Skip to content

Check and Update Argo CD Version #5583

Check and Update Argo CD Version

Check and Update Argo CD Version #5583

name: Check and Update Argo CD Version
on:
schedule:
- cron: '0 * * * *' # Runs every hour
workflow_dispatch: # Manual trigger
jobs:
check_and_update:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Determine version to update to
id: determine_version_to_update
run: |
current_version=$(awk -F 'ref=v|"' '/ref=v/{print $2}' argocd/kustomization.yaml)
echo "Current version in kustomization.yaml: $current_version"
echo "::set-output name=current_version::$current_version"
releases=$(curl -s https://api.github.com/repos/argoproj/argo-cd/releases)
echo "Retrieved releases from GitHub API"
is_rc="false"
if [[ "$current_version" == *"-rc"* ]]; then
is_rc="true"
echo "Current version is a release candidate: $current_version"
else
echo "Current version is not a release candidate: $current_version"
fi
highest_version=""
for release in $(echo "$releases" | jq -r '.[].tag_name'); do
if [[ "$release" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)(-.+)?$ ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
prerelease="${BASH_REMATCH[4]}"
echo "Processing release: $release"
if [[ -z $highest_version ]] || (( major > $(echo $highest_version | cut -d '.' -f 1) || ( major == $(echo $highest_version | cut -d '.' -f 1) && minor > $(echo $highest_version | cut -d '.' -f 2) ) || ( major == $(echo $highest_version | cut -d '.' -f 1) && minor == $(echo $highest_version | cut -d '.' -f 2) && patch > $(echo $highest_version | cut -d '.' -f 3) ) )); then
if [[ "$prerelease" != "rc"* ]] || [[ "$is_rc" == "true" && "$release" == "${current_version%.*}-"* ]]; then
highest_version="$major.$minor.$patch$prerelease"
echo "New highest version found: $highest_version"
fi
fi
fi
done
echo "Highest version determined: $highest_version"
echo "::set-output name=version::$highest_version"
- name: Compare versions and update kustomization.yaml if needed
if: steps.determine_version_to_update.outputs.version != steps.determine_version_to_update.outputs.current_version && steps.determine_version_to_update.outputs.version != null && steps.determine_version_to_update.outputs.current_version != null
run: |
sed -i "s/ref=v${{ steps.determine_version_to_update.outputs.current_version }}/ref=v${{ steps.determine_version_to_update.outputs.version }}/" argocd/kustomization.yaml
echo "Updated Argo CD version in kustomization.yaml from ${{ steps.determine_version_to_update.outputs.current_version }} to ${{ steps.determine_version_to_update.outputs.version }}"
working-directory: ${{ github.workspace }}
- name: Commit and push if kustomization.yaml was updated
if: steps.determine_version_to_update.outputs.version != steps.determine_version_to_update.outputs.current_version && steps.determine_version_to_update.outputs.version != null && steps.determine_version_to_update.outputs.current_version != null
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add argocd/kustomization.yaml
git commit -m "Update Argo CD version to ${{ steps.determine_version_to_update.outputs.version }}"
git push