-
Notifications
You must be signed in to change notification settings - Fork 14
78 lines (69 loc) · 2.67 KB
/
publish.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
name: "Upload Chart"
on:
push:
branches:
- master
paths:
- 'heartex/**'
- '.github/workflows/publish.yml'
env:
HELM_CHARTS_BUCKET: "heartex-charts"
HELM_CHARTS_REPO: "https://charts.heartex.com"
SYNC_DIR: sync
INDEX_DIR: index
AWS_REGION: us-east-1
jobs:
upload_chart:
name: "Upload Chart"
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v3.0.0
- name: Checkout
uses: actions/checkout@v4.2.2
with:
fetch-depth: '2'
- name: Helm package
id: helm_package
run: |
set -eu
# gather only changed charts
CHANGED_CHARTS=$(git diff --dirstat=files,0 HEAD~1 -- heartex/ | sed -E 's/^[ 0-9.]+% //g' | cut -d'/' -f2- | cut -d'/' -f1 | sort -u)
echo "Changed charts:"
echo "$CHANGED_CHARTS"
CHANGED_CHARTS_MAP=""
for chart in $CHANGED_CHARTS; do
chart_version=$(cat heartex/$chart/Chart.yaml | yq eval '.version' -)
helm package ./heartex/$chart -d ${{ env.SYNC_DIR }} -u
CHANGED_CHARTS_MAP="${CHANGED_CHARTS_MAP}$chart => $chart_version\n"
done
echo "CHANGED_CHARTS_MAP<<EOF" >> $GITHUB_ENV
echo "${CHANGED_CHARTS_MAP}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.CHARTS_UPLOAD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CHARTS_UPLOAD_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Build helm index
id: helm_index
run: |
set -eux
aws s3 cp s3://${{ env.HELM_CHARTS_BUCKET }}/index.yaml "${{ env.INDEX_DIR }}/index.yaml" || true
helm repo index ${{ env.SYNC_DIR }} --url "${{ env.HELM_CHARTS_REPO }}" --merge "${{ env.INDEX_DIR }}/index.yaml"
echo "==> Merged index:"
cat "${{ env.SYNC_DIR }}/index.yaml"
- name: Publish to S3
run: |
set -eux
aws s3 cp ${{ env.SYNC_DIR }} s3://${{ env.HELM_CHARTS_BUCKET }}/ --recursive
# Make sure index.yaml is synced last
aws s3 cp "${{ env.SYNC_DIR }}/index.yaml" s3://${{ env.HELM_CHARTS_BUCKET }}/
- name: Post to a Slack channel
id: slack
uses: slackapi/slack-github-action@v2.0
with:
channel-id: 'C02LMULF4NA'
slack-message: "New versions of helm charts released:\n${{ env.CHANGED_CHARTS_MAP }}<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|[Workflow run]>"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}