-
Notifications
You must be signed in to change notification settings - Fork 3
154 lines (132 loc) · 5.52 KB
/
publish-helm-charts.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
#
# Publish Magasin Helm charts in the gh-pages branch
# It creates a release.
#
# Reference documentation
#
# What needs to be setup in Github
# https://helm.sh/docs/topics/chart_repository/#github-pages-example
#
# Releaser action was not used because it did create one release per helm chart
#
name: Publish helm charts
on:
# On tag creation
push:
tags:
# Only run on tags that have the vX.Y.Z; Example v0.1.1.
- v[0-9]+.[0-9]+.[0-9]+
# Manual run of the
workflow_dispatch:
inputs:
tag:
description: "Release tag. Use format: vX.Y.Z. '-charts' is appened"
default: 'v0.0.1'
required: true
type: string
jobs:
release:
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v3
with:
token: ${{ secrets.GITHUB_TOKEN }} # only needed if version is 'latest'
- name: Install hub
run: |
sudo apt install -y hub
- name: Display the Input options
run: |
echo "tag: ${{ inputs.tag }}"
- name: Make helm packages (.tgz)
id: helm_packages
run: |
helm_packages_dir=`pwd`'/helm_packages'
# Create destination folder
mkdir $helm_packages_dir
# Get the list of all folders in helm.
# each folder has a chart
cd helm
# ls -d displays a / at the end of each folder. We remove it using sed
helm_charts=`ls -d helm/ */ | sed 's/\/$//'`
echo Charts to be created: $helm_charts
cd ..
# Create the packages that will be assets of the release
for chart in $helm_charts; do
# Creates a .tgz file for each folder in helm
helm package helm/$chart -d $helm_packages_dir
done
# Set env variable
echo "HELM_PACKAGES_DIR=$helm_packages_dir" >> "$GITHUB_ENV"
# And output steps.helm_packages.outputs.dir
echo "dir=$helm_packages_dir" >> $GITHUB_OUTPUT
- name: Create/Edit a GitHub release using hub (adds assets)
run: |
set -x
echo HELM_PACKAGES_DIR=$HELM_PACKAGES_DIR
echo steps.helm_pacakges.dir: ${{ steps.helm_packages.outputs.dir }}
assets=()
echo Packages to add process
ls -la $HELM_PACKAGES_DIR
for asset in `ls $HELM_PACKAGES_DIR`; do
echo Adding asset $asset...
assets+=("-a" "$HELM_PACKAGES_DIR/$asset")
done
echo Resulting assets to be added: ${assets[@]}
# Create the template of the body
echo "To install an specific chart: " > release-body.txt
echo " ```shell" >> release-body.txt
echo "helm repo add magasin https://unicef.github.io/magasin" >> release-body.txt
echo "
echo "# helm install <chart> magasin/<chart> --namespace magasin --create-namespace " >> release-body.txt
echo "helm install drill magasin/drill --namespace magasin --create-namespace" >> release-body.txt
echo "helm install dagster magasin/dagster --namespace magasin" >> release-body.txt
echo "helm install superset magasin/superset --namespace magasin" >> release-body.txt
echo "helm install daskhub magasin/daskhub --namespace magasin " >> release-body.txt
echo "```" >> release-body.txt
# Release using hub.
# Documentation: https://hub.github.com/hub-release.1.html
hub release create "${assets[@]}" --file release-body.txt --message "magasin charts ${{inputs.tag}}" "${{ inputs.tag }}-charts"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
# Now proceed to update the index.yaml in github pages
# First checkout gh-pages
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: 'gh-pages'
path: 'gh-pages'
# Then update the index usin helm repo index
- name: Update index.yaml
run: |
# Go to helm release folder folder
cd $HELM_PACKAGES_DIR
# Merge existing index with the new files. The url is given by the release
helm repo index . --merge ../gh-pages/index.yaml --url "https://github.com/$GITHUB_REPOSITORY/releases/download/${{ inputs.tag }}-charts"
cp index.yaml ../gh-pages/index.yaml
# Check changes
cd ../gh-pages
git diff index.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Commit the new index
# https://github.com/marketplace/actions/add-commit
- name: "Push the new index"
uses: EndBug/add-and-commit@v9
with:
cwd: './gh-pages/'
message: "update index.yaml for ${{ inputs.tag }}"
committer_name: GitHub Actions
committer_email: [email protected]