|
| 1 | +name: Update GitOps Promoter Version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + pull-requests: write |
| 9 | + |
| 10 | +env: |
| 11 | + KUBEBUILDER_VERSION: v4.11.1 |
| 12 | + |
| 13 | +jobs: |
| 14 | + update-version: |
| 15 | + name: Update GitOps Promoter to Latest Version |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 15 |
| 18 | + steps: |
| 19 | + - name: Checkout Repository |
| 20 | + uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6.0.1 |
| 21 | + with: |
| 22 | + path: current-repo |
| 23 | + - name: Set up Go |
| 24 | + uses: actions/setup-go@4aaadf42668403795cdfdb15b1c4250e9fed12b9 # pin@v5 |
| 25 | + with: |
| 26 | + go-version: "1.25" |
| 27 | + |
| 28 | + - name: Get latest GitOps Promoter release |
| 29 | + id: get-latest-release |
| 30 | + run: | |
| 31 | + LATEST_VERSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 32 | + https://api.github.com/repos/argoproj-labs/gitops-promoter/releases/latest | jq -r .tag_name) |
| 33 | + if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then |
| 34 | + echo "Failed to fetch latest release" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT |
| 38 | + echo "Latest GitOps Promoter version: $LATEST_VERSION" |
| 39 | +
|
| 40 | + - name: Get current GitOps Promoter version |
| 41 | + id: get-current-version |
| 42 | + run: | |
| 43 | + CURRENT_VERSION=$(grep 'GITOPS_PROMOTER_VERSION:' current-repo/.github/workflows/chart-diff.yaml | awk '{print $2}') |
| 44 | + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 45 | + echo "Current GitOps Promoter version: $CURRENT_VERSION" |
| 46 | +
|
| 47 | + - name: Check if update is needed |
| 48 | + id: check-update |
| 49 | + run: | |
| 50 | + if [ "${{ steps.get-latest-release.outputs.latest_version }}" = "${{ steps.get-current-version.outputs.current_version }}" ]; then |
| 51 | + echo "No update needed. Current version is already the latest." |
| 52 | + echo "update_needed=false" >> $GITHUB_OUTPUT |
| 53 | + else |
| 54 | + echo "Update needed: ${{ steps.get-current-version.outputs.current_version }} -> ${{ steps.get-latest-release.outputs.latest_version }}" |
| 55 | + echo "update_needed=true" >> $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Checkout gitops-promoter at latest release |
| 59 | + if: steps.check-update.outputs.update_needed == 'true' |
| 60 | + uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 |
| 61 | + with: |
| 62 | + repository: argoproj-labs/gitops-promoter |
| 63 | + ref: ${{ steps.get-latest-release.outputs.latest_version }} |
| 64 | + path: gitops-promoter |
| 65 | + |
| 66 | + - name: Install kubebuilder |
| 67 | + if: steps.check-update.outputs.update_needed == 'true' |
| 68 | + run: | |
| 69 | + go env GOOS |
| 70 | + curl -L -o kubebuilder "https://github.com/kubernetes-sigs/kubebuilder/releases/download/${{ env.KUBEBUILDER_VERSION }}/kubebuilder_$(go env GOOS)_$(go env GOARCH)" |
| 71 | + chmod +x kubebuilder && sudo mv kubebuilder /usr/local/bin/ |
| 72 | + kubebuilder version |
| 73 | +
|
| 74 | + - name: Run KubeBuilder to generate manifests |
| 75 | + if: steps.check-update.outputs.update_needed == 'true' |
| 76 | + working-directory: gitops-promoter |
| 77 | + run: | |
| 78 | + kubebuilder edit --plugins=helm/v2-alpha --output-dir=../current-repo --manifests=./dist/install.yaml |
| 79 | +
|
| 80 | + - name: Remove example blocks from generated CRDs |
| 81 | + if: steps.check-update.outputs.update_needed == 'true' |
| 82 | + run: | |
| 83 | + sed -i 's/{{- if eq \(.Environment\)/{{ `{{- if eq .Environment` }}/g; s/{{- else if eq \(.Environment\)/{{ `{{- else if eq .Environment` }}/g; s/{{- end -}}/{{ `{{- end -}}` }}/g; s/{{- range \$key, \$value := \.ArgoCDCommitStatus/{{ `{{- range $key, $value := .ArgoCDCommitStatus` }}/g' current-repo/chart/templates/crd/argocdcommitstatuses.promoter.argoproj.io.yaml |
| 84 | +
|
| 85 | + - name: Update appVersion in gitops_promoter_version |
| 86 | + if: steps.check-update.outputs.update_needed == 'true' |
| 87 | + run: | |
| 88 | + # Remove the 'v' prefix from version for appVersion |
| 89 | + VERSION_WITHOUT_V="${{ steps.get-latest-release.outputs.latest_version }}" |
| 90 | + VERSION_WITHOUT_V="${VERSION_WITHOUT_V#v}" |
| 91 | + echo "$VERSION_WITHOUT_V" > current-repo/gitops_promoter_version |
| 92 | +
|
| 93 | + - name: Update Chart.yaml version |
| 94 | + if: steps.check-update.outputs.update_needed == 'true' |
| 95 | + working-directory: current-repo |
| 96 | + run: | |
| 97 | + OLD_APP=$(grep '^appVersion:' chart/Chart.yaml | tr -d '"' | awk '{print $2}') |
| 98 | + echo "Old app version: $OLD_APP" |
| 99 | + NEW_APP="${{ steps.get-latest-release.outputs.latest_version }}" |
| 100 | + echo "New app version: $NEW_APP" |
| 101 | + NEW_APP="${NEW_APP#v}" |
| 102 | + echo "New app version number: $NEW_APP" |
| 103 | + |
| 104 | + OLD_MAJOR=$(echo "$OLD_APP" | cut -d. -f1) |
| 105 | + OLD_MINOR=$(echo "$OLD_APP" | cut -d. -f2) |
| 106 | + NEW_MAJOR=$(echo "$NEW_APP" | cut -d. -f1) |
| 107 | + NEW_MINOR=$(echo "$NEW_APP" | cut -d. -f2) |
| 108 | + |
| 109 | + CURRENT_CHART_VERSION=$(grep '^version:' chart/Chart.yaml | awk '{print $2}') |
| 110 | + CHART_MAJOR=$(echo "$CURRENT_CHART_VERSION" | cut -d. -f1) |
| 111 | + CHART_MINOR=$(echo "$CURRENT_CHART_VERSION" | cut -d. -f2) |
| 112 | + CHART_PATCH=$(echo "$CURRENT_CHART_VERSION" | cut -d. -f3) |
| 113 | + |
| 114 | + if [ "$NEW_MAJOR" -gt "$OLD_MAJOR" ]; then |
| 115 | + NEW_CHART_VERSION="$((CHART_MAJOR + 1)).0.0" |
| 116 | + elif [ "$NEW_MINOR" -gt "$OLD_MINOR" ]; then |
| 117 | + NEW_CHART_VERSION="$CHART_MAJOR.$((CHART_MINOR + 1)).0" |
| 118 | + else |
| 119 | + NEW_CHART_VERSION="$CHART_MAJOR.$CHART_MINOR.$((CHART_PATCH + 1))" |
| 120 | + fi |
| 121 | +
|
| 122 | + sed -i "s/^version: .*/version: $NEW_CHART_VERSION/" chart/Chart.yaml |
| 123 | + echo "Chart version bumped to $NEW_CHART_VERSION" |
| 124 | +
|
| 125 | + - name: Create Pull Request |
| 126 | + if: steps.check-update.outputs.update_needed == 'true' |
| 127 | + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 |
| 128 | + with: |
| 129 | + path: current-repo |
| 130 | + commit-message: "chore: update GitOps Promoter to ${{ steps.get-latest-release.outputs.latest_version }}" |
| 131 | + title: "chore: update GitOps Promoter to ${{ steps.get-latest-release.outputs.latest_version }}" |
| 132 | + body: | |
| 133 | + This PR updates GitOps Promoter from ${{ steps.get-current-version.outputs.current_version }} to ${{ steps.get-latest-release.outputs.latest_version }}. |
| 134 | +
|
| 135 | + **Changes:** |
| 136 | + - Updated manifests using kubebuilder |
| 137 | + - Updated appVersion in Chart.yaml |
| 138 | + - Updated GITOPS_PROMOTER_VERSION in chart-diff.yaml |
| 139 | +
|
| 140 | + **Release Notes:** https://github.com/argoproj-labs/gitops-promoter/releases/tag/${{ steps.get-latest-release.outputs.latest_version }} |
| 141 | + branch: update-gitops-promoter-${{ steps.get-latest-release.outputs.latest_version }} |
| 142 | + delete-branch: true |
0 commit comments