Skip to content

Commit 1d184ad

Browse files
authored
Add workflow to update GitOps Promoter version
1 parent d2d6442 commit 1d184ad

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
24+
- name: Get latest GitOps Promoter release
25+
id: get-latest-release
26+
run: |
27+
LATEST_VERSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
28+
https://api.github.com/repos/argoproj-labs/gitops-promoter/releases/latest | jq -r .tag_name)
29+
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then
30+
echo "Failed to fetch latest release"
31+
exit 1
32+
fi
33+
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
34+
echo "Latest GitOps Promoter version: $LATEST_VERSION"
35+
36+
- name: Get current GitOps Promoter version
37+
id: get-current-version
38+
run: |
39+
CURRENT_VERSION=$(grep 'GITOPS_PROMOTER_VERSION:' current-repo/.github/workflows/chart-diff.yaml | awk '{print $2}')
40+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
41+
echo "Current GitOps Promoter version: $CURRENT_VERSION"
42+
43+
- name: Check if update is needed
44+
id: check-update
45+
run: |
46+
if [ "${{ steps.get-latest-release.outputs.latest_version }}" = "${{ steps.get-current-version.outputs.current_version }}" ]; then
47+
echo "No update needed. Current version is already the latest."
48+
echo "update_needed=false" >> $GITHUB_OUTPUT
49+
else
50+
echo "Update needed: ${{ steps.get-current-version.outputs.current_version }} -> ${{ steps.get-latest-release.outputs.latest_version }}"
51+
echo "update_needed=true" >> $GITHUB_OUTPUT
52+
fi
53+
54+
- name: Checkout gitops-promoter at latest release
55+
if: steps.check-update.outputs.update_needed == 'true'
56+
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
57+
with:
58+
repository: argoproj-labs/gitops-promoter
59+
ref: ${{ steps.get-latest-release.outputs.latest_version }}
60+
path: gitops-promoter
61+
62+
- name: Install kubebuilder
63+
if: steps.check-update.outputs.update_needed == 'true'
64+
run: |
65+
curl -L -o kubebuilder "https://github.com/kubernetes-sigs/kubebuilder/releases/download/${{ env.KUBEBUILDER_VERSION }}/kubebuilder_$(go env GOOS)_$(go env GOARCH)"
66+
chmod +x kubebuilder && sudo mv kubebuilder /usr/local/bin/
67+
kubebuilder version
68+
69+
- name: Run KubeBuilder to generate manifests
70+
if: steps.check-update.outputs.update_needed == 'true'
71+
working-directory: gitops-promoter
72+
run: |
73+
kubebuilder edit --plugins=helm/v2-alpha --output-dir=../current-repo --manifests=./dist/install.yaml
74+
75+
- name: Remove example blocks from generated CRDs
76+
if: steps.check-update.outputs.update_needed == 'true'
77+
run: |
78+
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
79+
80+
- name: Update appVersion in Chart.yaml
81+
if: steps.check-update.outputs.update_needed == 'true'
82+
run: |
83+
# Remove the 'v' prefix from version for appVersion
84+
VERSION_WITHOUT_V="${{ steps.get-latest-release.outputs.latest_version }}"
85+
VERSION_WITHOUT_V="${VERSION_WITHOUT_V#v}"
86+
sed -i "s/^appVersion: .*/appVersion: \"$VERSION_WITHOUT_V\"/" current-repo/chart/Chart.yaml
87+
88+
- name: Update GITOPS_PROMOTER_VERSION in chart-diff.yaml
89+
if: steps.check-update.outputs.update_needed == 'true'
90+
run: |
91+
sed -i "s/GITOPS_PROMOTER_VERSION: .*/GITOPS_PROMOTER_VERSION: ${{ steps.get-latest-release.outputs.latest_version }}/" current-repo/.github/workflows/chart-diff.yaml
92+
93+
- name: Create Pull Request
94+
if: steps.check-update.outputs.update_needed == 'true'
95+
uses: peter-evans/create-pull-request@c7fcb2c1d4c851a1d8d82dd61df0e0f8ef373e6f # v7.0.6
96+
with:
97+
path: current-repo
98+
commit-message: "chore: update GitOps Promoter to ${{ steps.get-latest-release.outputs.latest_version }}"
99+
title: "chore: update GitOps Promoter to ${{ steps.get-latest-release.outputs.latest_version }}"
100+
body: |
101+
This PR updates GitOps Promoter from ${{ steps.get-current-version.outputs.current_version }} to ${{ steps.get-latest-release.outputs.latest_version }}.
102+
103+
**Changes:**
104+
- Updated manifests using kubebuilder
105+
- Updated appVersion in Chart.yaml
106+
- Updated GITOPS_PROMOTER_VERSION in chart-diff.yaml
107+
108+
**Release Notes:** https://github.com/argoproj-labs/gitops-promoter/releases/tag/${{ steps.get-latest-release.outputs.latest_version }}
109+
branch: update-gitops-promoter-${{ steps.get-latest-release.outputs.latest_version }}
110+
delete-branch: true

0 commit comments

Comments
 (0)