generated from Cloudzero/template-cloudzero-open-source
-
Notifications
You must be signed in to change notification settings - Fork 9
139 lines (118 loc) · 4.53 KB
/
build-and-publish-chart.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Manual Release Chart
# Manual trigger only
on:
workflow_dispatch:
inputs:
version:
description: 'Version to use for the release'
required: false
default: ''
jobs:
build-and-publish-chart:
environment: release
permissions:
contents: 'write'
packages: 'write'
id-token: write
actions: 'read'
runs-on: ubuntu-latest
steps:
# Step 1: Checkout and Setup
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Set up Git
run: |
git config --local user.email "ops@cloudzero.com"
git config --local user.name "Automated CZ Release"
- name: Fetch All Branches
run: git fetch --all
# Step 2: Prepare Branches
- name: Prepare Branches
run: |
git checkout develop
git pull --rebase origin develop
git checkout main
git pull --rebase origin main
git merge develop
# Step 3: Helm Setup
- name: Install Helm
uses: azure/setup-helm@v3
- name: Build Cloudzero Agent Dependencies
run: helm dependency update charts/cloudzero-agent/
- name: Package Cloudzero Agent Chart
run: helm package charts/cloudzero-agent/ --destination .deploy
# Step 4: Validate and Set Version
- name: Validate Input Version
run: |
if [[ -z "${{ github.event.inputs.version }}" ]]; then
echo "Version input is required."
exit 1
fi
echo "NEW_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
- name: Update Chart Version
run: |
VERSION_LINE=$(awk '/version:/ && !done {print NR; done=1}' charts/cloudzero-agent/Chart.yaml)
sed -i ''$VERSION_LINE's/.*/version: ${{ env.NEW_VERSION }}/' charts/cloudzero-agent/Chart.yaml
- name: Validate Release Notes are Present
run: |
if [ ! -f "charts/cloudzero-agent/docs/releases/${{ env.NEW_VERSION }}.md" ]; then
echo "Release notes for ${{ env.NEW_VERSION }} are missing. Please create a release notes file at charts/cloudzero-agent/docs/releases/${{ env.NEW_VERSION }}.md"
exit 1
fi
# Step 5: Package and Commit Chart
- name: Package Chart
run: helm package charts/cloudzero-agent/ --destination .deploy
- name: Commit updated Chart.yaml
run: |
git add .
git commit -m "Update Chart.yaml to version ${{ env.NEW_VERSION }}"
git push origin main
COMMIT_HASH=$(git rev-parse HEAD)
echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV
continue-on-error: true
# Step 7: Handle Artifacts and Update Pages
- name: Upload Chart as Artifact
uses: actions/upload-artifact@v4
with:
name: agent-chart
path: .deploy/cloudzero-agent-${{ env.NEW_VERSION }}.tgz
- name: Checkout GH Pages
run: |
git checkout -f gh-pages
- name: Move release Tarball
run: |
cp .deploy/cloudzero-agent-${{ env.NEW_VERSION }}.tgz ./
rm -fr .deploy
- name: Update Index
run: helm repo index --url https://cloudzero.github.io/cloudzero-charts .
- name: Save Index in GH Pages
run: |
# copy the new chart and index.yaml
git add cloudzero-agent-${{ env.NEW_VERSION }}.tgz index.yaml
git commit -m "Updating ${{ env.NEW_VERSION }} Index"
git push origin gh-pages
continue-on-error: true
- name: Update Docs for GH Pages
run: |
# cleanup garbage files
rm -fr .deploy charts/cloudzero-agent/charts
git reset --hard
# now checkout docs from main
git checkout main -- charts/cloudzero-agent/docs charts/cloudzero-agent/README.md README.md
git add README.md charts/cloudzero-agent/docs charts/cloudzero-agent/README.md
git commit -m "Update docs for ${{ env.NEW_VERSION }}"
git push origin gh-pages
continue-on-error: true
# Step 8: Create GitHub Release
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.NEW_VERSION }}
tag_name: ${{ env.NEW_VERSION }}
files: cloudzero-agent-${{ env.NEW_VERSION }}.tgz
make_latest: true
target_commitish: ${{ env.COMMIT_HASH }}
body_path: ${{ github.workspace }}/charts/cloudzero-agent/docs/releases/${{ env.NEW_VERSION }}.md