generated from Cloudzero/template-cloudzero-open-source
-
Notifications
You must be signed in to change notification settings - Fork 9
155 lines (128 loc) · 4.86 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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:
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 "[email protected]"
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 Dependencies
run: helm dependency update charts/cloudzero-agent/
# Step 4: Determine Version
- name: Get Github Tag Version
id: version
uses: flatherskevin/semver-action@v1
with:
incrementLevel: patch
source: tags
- name: Determine Chart Version
run: |
NEW_VERSION=${{ github.event.inputs.version || steps.version.outputs.nextVersion }}
echo "NEW_VERSION=$NEW_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
# Step 5: Package and Commit Chart
- name: Package Chart
run: helm package charts/cloudzero-agent/ --destination .deploy
- name: Get Main Changelog Beginning Hash
run: |
MAIN_PREV_COMMIT_HASH=$(git rev-parse HEAD)
echo "MAIN_PREV_COMMIT_HASH=${MAIN_PREV_COMMIT_HASH}" >> $GITHUB_ENV
- 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 6: Generate Change Log
- name: Generate Change Log
id: get_changes
run: |
FROM=${{ env.MAIN_PREV_COMMIT_HASH }}
TO=$(git rev-parse --short HEAD)
CHANGES=$(git log ${FROM}..${TO} --oneline)
echo "::set-output name=changes::${CHANGES}"
# 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: |
## Installation Instructions
[Please follow the Installation Instructions provided in this releases README](https://github.com/Cloudzero/cloudzero-charts/blob/${{ env.NEW_VERSION }}/charts/cloudzero-agent/README.md).
## Release ${{ env.NEW_VERSION }} Changes
${{ steps.get_changes.outputs.changes }}