-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (149 loc) · 6.91 KB
/
helm-package-and-publish.yaml
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Helm package and push to Github Pages
on:
push:
# run the Github Action on every tag versioned as v*.*.*
tags:
- "v*.*.*"
jobs:
helm-package-and-push-to-ghcr-io:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Helm + yq + jq
run: |
sudo snap install yq
sudo snap install helm --classic
sudo snap install jq
- name: Helm Package
id: helm_package
run: |
echo "Tag version: $GITHUB_REF"
RELEASE_TAG="${GITHUB_REF#refs/tags/}"
VERSION="${RELEASE_TAG:-v666.666.666}"
echo "VERSION Version: $VERSION"
CLEAN_VERSION="${VERSION#v}"
echo "CLEAN_VERSION Version: $CLEAN_VERSION"
# package the helm chart
PACKAGE_OUTPUT=$(helm package --version "$CLEAN_VERSION" helm-chart)
echo "PACKAGE_OUTPUT=$PACKAGE_OUTPUT"
PACKAGE_NAME=$(basename "$PACKAGE_OUTPUT")
echo "Generated helm package: $PACKAGE_NAME"
# save the generated package name to github_output to pass it to next step
echo "package-name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "package-version=$CLEAN_VERSION" >> $GITHUB_OUTPUT
- name: Patch argocd application yaml
id: argocd-application
run: |
VERSIONED_ARGOCD_APP_YAML="argocd-application-${{ steps.helm_package.outputs.package-version}}.yaml"
cp argocd-application.yaml "$VERSIONED_ARGOCD_APP_YAML"
echo "Current targetRevision: $(yq '.spec.source.targetRevision' $VERSIONED_ARGOCD_APP_YAML)"
yq e '.spec.source.targetRevision = "${{ steps.helm_package.outputs.package-version}}"' --inplace $VERSIONED_ARGOCD_APP_YAML
echo "Patched targetRevision: $(yq '.spec.source.targetRevision' $VERSIONED_ARGOCD_APP_YAML)"
# save to the github_output to pass it to next step
echo "argocd-application-filename=$VERSIONED_ARGOCD_APP_YAML" >> $GITHUB_OUTPUT
- name: Print helm_package step output
run: |
echo "package-name=$MESSAGE"
env:
MESSAGE: ${{ steps.helm_package.outputs.package-name}}
- name: Create new Release and upload helm artifact
id: create_release_and_upload_artifacts
uses: softprops/[email protected]
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
${{ steps.helm_package.outputs.package-name}}
${{ steps.argocd-application.outputs.argocd-application-filename}}
token: ${{ secrets.GHCR_TOKEN }}
generate_release_notes: true
fail_on_unmatched_files: true
body: |
Github Repo: <https://github.com/oguzhan-yilmaz/steampipe-powerpipe-kubernetes>
Github Releases: <https://github.com/oguzhan-yilmaz/steampipe-powerpipe-kubernetes/releases>
Github Pages: <https://oguzhan-yilmaz.github.io/steampipe-powerpipe-kubernetes/>
Github Pages (Helm index): <https://oguzhan-yilmaz.github.io/steampipe-powerpipe-kubernetes/index.yaml>
**Helm Repo**
```bash
helm repo add oguzhan-yilmaz https://oguzhan-yilmaz.github.io/steampipe-powerpipe-kubernetes
```
```bash
helm repo update oguzhan-yilmaz
```
**Helm Install (latest version)**
```bash
helm repo update oguzhan-yilmaz
helm show values oguzhan-yilmaz/steampipe-powerpipe-kubernetes > values.yaml
# update the values.yaml on your own accord
helm upgrade --install steampipe-powerpipe \
-n turbot \
-f values.yaml \
--create-namespace \
oguzhan-yilmaz/steampipe-powerpipe-kubernetes
```
**Helm Install (current version)**
```bash
helm show values oguzhan-yilmaz/steampipe-powerpipe-kubernetes --version ${{ steps.helm_package.outputs.package-version}} > values.yaml
# update the values.yaml on your own accord
helm upgrade --install steampipe-powerpipe \
-n turbot \
-f values.yaml \
--create-namespace \
--version ${{ steps.helm_package.outputs.package-version}} \
oguzhan-yilmaz/steampipe-powerpipe-kubernetes
```
**ArgoCD Application (current version)**
First, download the `argocd-application-X.Y.Z.yaml` from assets.
```bash
kubectl apply -f argocd-application-X.Y.Z.yaml
```
- name: print release upload output
run: |
echo "assets=${{ steps.create_release_and_upload_artifacts.outputs.assets}}"
- name: Save artifact download url
id: helm_package_download_url
run: |
DOWNLOAD_URL=$(echo '${{ steps.create_release_and_upload_artifacts.outputs.assets}}' | jq '.[0].browser_download_url')
echo "DOWNLOAD_URL=$DOWNLOAD_URL"
echo "download_url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT
- name: Print uploaded helm_package download url
run: |
echo 'package-name=${{ steps.helm_package_download_url.outputs.download_url}}'
- name: Clone gh-pages branch and update helm index.yaml on github pages
env:
GITHUB_TOKEN: ${{ secrets.GHCR_TOKEN }}
GIT_AUTHOR_EMAIL: "Oguzhan Yilmaz"
GIT_AUTHOR_NAME: "[email protected]"
run: |
git config --global user.email "[email protected]"
git config --global user.name "Oguzhan Yilmaz"
# clone gh-pages branch
git clone -b gh-pages https://github.com/oguzhan-yilmaz/steampipe-powerpipe-kubernetes.git gh-pages-clone
ls -al
ls -al gh-pages-clone
# merge the helm index.yaml
ACTUAL_RELEASE_URL="${{ steps.helm_package_download_url.outputs.download_url}}"
RELEASE_BASE_URL="${ACTUAL_RELEASE_URL%/*}"
echo "RELEASE_BASE_URL=$RELEASE_BASE_URL"
helm repo index . --url "$RELEASE_BASE_URL" --merge gh-pages-clone/index.yaml
ls -al
# replace the index.yaml with the new one
echo "Old index.yaml"
cat gh-pages-clone/index.yaml
rm gh-pages-clone/index.yaml
cp index.yaml gh-pages-clone/index.yaml
# check out the new index.yaml
cd gh-pages-clone
pwd
echo "New index.yaml"
cat index.yaml
git status
# commit and push the new index.yaml
git add index.yaml
git commit -m "update index.yaml in Github Action"
git remote set-url origin https://x-access-token:${{ secrets.GHCR_TOKEN }}@github.com/oguzhan-yilmaz/steampipe-powerpipe-kubernetes.git
git push
git status