-
Notifications
You must be signed in to change notification settings - Fork 1
195 lines (184 loc) · 7.86 KB
/
main.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Build
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
IMAGE: party
REGISTRY_HOSTNAME: eu.gcr.io
HOST: ${{ secrets.GOOGLE_PROJECT_ID }}
RELEASE_HOST: ${{ secrets.RELEASE_PROJECT_ID }}
CHART_DIRECTORY: _infra/helm/party
SPINNAKER_TOPIC: ${{ secrets.SPINNAKER_TOPIC }}
ARTIFACT_BUCKET: ${{ secrets.ARTIFACT_BUCKET }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build & package"
build:
name: Build & Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
token: ${{ secrets.BOT_TOKEN }}
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Get Dependencies
run: |
docker compose --verbose build
docker compose up -d
pip install pipenv
pipenv install --dev
- name: Run tests
run: make test
- name: Authenticate with Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCR_KEY }}
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- run: |
gcloud auth configure-docker
- name: pr docker tag
if: github.ref != 'refs/heads/main'
id: tag
run: |
PR=$(echo "$GITHUB_REF" | awk -F / '{print $3}')
echo "$PR"
echo "pr_number=pr-$PR" >> $GITHUB_ENV
# Build the Docker image
- name: Build Docker Image
if: github.ref != 'refs/heads/main'
run: |
docker build -t "$REGISTRY_HOSTNAME"/"$HOST"/"$IMAGE":${{ env.pr_number }} -f _infra/docker/Dockerfile .
- name: Push dev image
if: github.ref != 'refs/heads/main'
run: |
docker push "$REGISTRY_HOSTNAME"/"$HOST"/"$IMAGE":${{ env.pr_number }}
- name: template helm
run: |
helm template $CHART_DIRECTORY
- name: Set current tag
if: github.ref != 'refs/heads/main'
id: vars
run: |
git fetch --tags
echo "tag=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
- name: Import BOT GPG key
run: echo $BOT_GPG_KEY | base64 --decode | gpg --batch --import
env:
BOT_GPG_KEY: ${{ secrets.BOT_GPG_KEY }}
- name: Prepare gpg CLI signing step
run: |
rm -rf /tmp/gpg.sh
echo '#!/bin/bash' >> /tmp/gpg.sh
echo 'gpg --batch --pinentry-mode=loopback --passphrase $BOT_GPG_KEY_PASSPHRASE $@' >> /tmp/gpg.sh
chmod +x /tmp/gpg.sh
- name: Setup git
run: |
git config commit.gpgsign true
git config user.signingkey "${{ secrets.BOT_GPG_KEY_ID }}"
git config gpg.program /tmp/gpg.sh
git config user.name "${{ secrets.BOT_USERNAME }}"
git config user.email "${{ secrets.BOT_EMAIL }}"
- name: update versions
if: github.ref != 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
BOT_GPG_KEY_PASSPHRASE: ${{ secrets.BOT_GPG_KEY_PASSPHRASE }}
COMMIT_MSG: |
auto patch increment
shell: bash
run: |
echo "Current git version: ${{ env.tag }}"
export APP_VERSION=$(grep -E "appVersion:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g')
export CHART_VERSION=$(grep -E "version:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g')
echo "appVersion: $APP_VERSION"
echo "chartVersion: $CHART_VERSION"
if [ ${{ env.tag }} = $APP_VERSION ]; then
echo "versions match, incrementing patch"
OLD_PATCH=$(echo ${{ env.tag }} | cut -d '.' -f3)
echo "OLD patch: $OLD_PATCH"
NEW_PATCH=$(($OLD_PATCH + 1))
echo "New patch version: $NEW_PATCH"
NEW_APP_VERSION="appVersion: $(echo ${{ env.tag }} | sed -e "s/[0-9]\{1,3\}/$NEW_PATCH/3")"
NEW_CHART_VERSION="version: $(echo ${{ env.tag }} | sed -e "s/[0-9]\{1,3\}/$NEW_PATCH/3")"
sed -i -e "s/appVersion: .*/$NEW_APP_VERSION/g" $CHART_DIRECTORY/Chart.yaml
sed -i -e "s/version: .*/$NEW_CHART_VERSION/g" $CHART_DIRECTORY/Chart.yaml
git config user.name "ras-rm-pr-bot"
git config user.email "${{ secrets.BOT_EMAIL }}"
git remote set-url origin https://ras-rm-pr-bot:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git remote update
git fetch
git checkout ${{ github.head_ref }}
git add $CHART_DIRECTORY/Chart.yaml
git commit -m "$COMMIT_MSG"
git push
else
if [ $APP_VERSION != $CHART_VERSION ]; then
echo "app version manually updated without updating chart version"
NEW_CHART_VERSION="version: $APP_VERSION"
echo "replacing version with $NEW_CHART_VERSION"
sed -i -e "s/version: .*/$NEW_CHART_VERSION/g" $CHART_DIRECTORY/Chart.yaml
git config user.name "ras-rm-pr-bot"
git config user.email "${{ secrets.BOT_EMAIL }}"
git remote set-url origin https://ras-rm-pr-bot:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git remote update
git fetch
git checkout ${{ github.head_ref }}
git add $CHART_DIRECTORY/Chart.yaml
git commit -m "$COMMIT_MSG"
git push
else
echo "git version different to chart/app versions and chart/app versions match"
echo "Using current version: $APP_VERSION"
fi
fi
- name: output new version
if: github.ref == 'refs/heads/main'
id: release
shell: bash
run: |
echo "version=$(grep -E "appVersion:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g')" >> $GITHUB_ENV
- name: package helm
run: |
echo HELM_VERSION=$(grep -E "version:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g') >> $GITHUB_ENV
helm dep up $CHART_DIRECTORY
helm package $CHART_DIRECTORY
- name: Publish dev Chart
if: github.ref != 'refs/heads/main'
run: |
mv $IMAGE-${{ env.HELM_VERSION }}.tgz $IMAGE-${{ env.pr_number }}.tgz
gsutil cp $IMAGE-*.tgz gs://$ARTIFACT_BUCKET/$IMAGE/
- name: Build Release Image
if: github.ref == 'refs/heads/main'
run: |
docker build -f _infra/docker/Dockerfile -t "$REGISTRY_HOSTNAME"/"$RELEASE_HOST"/"$IMAGE":latest -t "$REGISTRY_HOSTNAME"/"$RELEASE_HOST"/"$IMAGE":${{ env.version }} .
- name: Push Release image
if: github.ref == 'refs/heads/main'
run: |
docker push "$REGISTRY_HOSTNAME"/"$RELEASE_HOST"/"$IMAGE":${{ env.version }}
docker push "$REGISTRY_HOSTNAME"/"$RELEASE_HOST"/"$IMAGE":latest
- name: Publish Charts
if: github.ref == 'refs/heads/main'
run: |
cp $IMAGE-${{ env.HELM_VERSION }}.tgz $IMAGE-latest.tgz
gsutil cp $IMAGE-*.tgz gs://$ARTIFACT_BUCKET/$IMAGE/
- name: Publish Release
if: github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create ${{ env.version }} --title ${{ env.version }} --notes ${{ env.version }}
- name: CD hook
if: github.ref == 'refs/heads/main'
run: |
gcloud pubsub topics publish $SPINNAKER_TOPIC --project $HOST \
--message "{ \"kind\": \"storage#object\", \"name\": \"$IMAGE/$IMAGE-${{ env.HELM_VERSION }}.tgz\", \"bucket\": \"$ARTIFACT_BUCKET\" }" \
--attribute cd="actions"