forked from loic-sharma/BaGet
-
Notifications
You must be signed in to change notification settings - Fork 62
219 lines (203 loc) · 8.53 KB
/
release.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Release
on:
push:
tags:
- 'v*.*.*'
jobs:
version:
runs-on: ubuntu-latest
steps:
- id: get-version-tag
run: |
export GITHUB_REF_NAME="${{ github.ref_name }}"
export RELEASE_VERSION="${GITHUB_REF_NAME#v}"
export RELEASE_MAJOR_VERSION="${RELEASE_VERSION%%.*}"
export remaining_version="${RELEASE_VERSION#*.}"
export RELEASE_MINOR_VERSION="${RELEASE_MAJOR_VERSION}.${remaining_version%%.*}"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "RELEASE_MINOR_VERSION=$RELEASE_MINOR_VERSION" >> $GITHUB_OUTPUT
echo "RELEASE_MAJOR_VERSION=$RELEASE_MAJOR_VERSION" >> $GITHUB_OUTPUT
outputs:
RELEASE_VERSION: ${{ steps.get-version-tag.outputs.RELEASE_VERSION }}
RELEASE_MINOR_VERSION: ${{ steps.get-version-tag.outputs.RELEASE_MINOR_VERSION }}
RELEASE_MAJOR_VERSION: ${{ steps.get-version-tag.outputs.RELEASE_MAJOR_VERSION }}
verify:
name: Run tests
runs-on: ubuntu-latest
needs: version
steps:
- uses: actions/[email protected]
- name: Setup .NET
uses: actions/[email protected]
with:
global-json-file: global.json
- name: Test
run: dotnet test --verbosity normal
release_zip:
if: ${{ github.ref_type == 'tag' }}
needs: [version, verify]
name: Release BaGetter.zip to GitHub
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/[email protected]
with:
global-json-file: global.json
- name: Publish
run: |
dotnet publish src/BaGetter --configuration Release --output artifacts --property:Version=${{ needs.version.outputs.RELEASE_VERSION }}
echo ${{ github.sha }} > artifacts/ReleaseSha.txt
7z a -tzip bagetter-${{ needs.version.outputs.RELEASE_VERSION }}.zip ./artifacts/*
- name: Generate changelog with git-cliff
uses: tj-actions/[email protected]
with:
args: --latest --strip all
output: "CHANGELOG.md"
- name: Create release with ncipollo/release-action
uses: ncipollo/[email protected]
with:
bodyFile: "CHANGELOG.md"
artifacts: "bagetter-${{ needs.version.outputs.RELEASE_VERSION }}.zip"
name: ${{ needs.version.outputs.RELEASE_VERSION }}
prerelease: ${{ contains(github.ref_name, '-') }}
release_packages:
if: ${{ github.ref_type == 'tag' }}
needs: [version, verify]
name: Release packages to nuget.org
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Setup .NET
uses: actions/[email protected]
with:
global-json-file: global.json
- name: Pack
run: |
export PackageVersion=${{ needs.version.outputs.RELEASE_VERSION }}
export PackageSource=${PackageSource:="https://api.nuget.org/v3/index.json"}
echo "PackageSource=${PackageSource}" >> $GITHUB_ENV
dotnet pack --configuration Release --output artifacts --property:Version=${{ needs.version.outputs.RELEASE_VERSION }}
- name: Push
run: dotnet nuget push "*" -s ${PackageSource} -k ${{secrets.NUGET_API_KEY}}
working-directory: artifacts
release_docker_image:
if: ${{ github.ref_type == 'tag' }}
needs: [version, verify]
name: Release Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set release version
run: echo "PackageVersion=${{ needs.version.outputs.RELEASE_VERSION }}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
bagetter/bagetter:latest
bagetter/bagetter:${{ needs.version.outputs.RELEASE_VERSION }}
bagetter/bagetter:${{ needs.version.outputs.RELEASE_MINOR_VERSION }}
bagetter/bagetter:${{ needs.version.outputs.RELEASE_MAJOR_VERSION }}
build-args: |
Version=${{ needs.version.outputs.RELEASE_VERSION }}
release_helm_chart:
if: ${{ github.ref_type == 'tag' }}
needs: [version, verify]
name: Release Helm chart to GitHub
runs-on: ubuntu-latest
env:
CHART_DIR: deployment templates/chart
CHART_REPO: bagetter/helm-chart-repo
CHART_REPO_BRANCH: gh-pages
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
steps:
- uses: actions/[email protected]
- name: Update version in helm chart
run: |
sed -i "s/version: \".*\"/version: \"${{ needs.version.outputs.RELEASE_VERSION }}\"/" "deployment templates/chart/bagetter/Chart.yaml"
sed -i "s/appVersion: \".*\"/appVersion: \"${{ needs.version.outputs.RELEASE_VERSION }}\"/" "deployment templates/chart/bagetter/Chart.yaml"
- name: Generate helm docs
uses: losisin/helm-docs-github-action@v1
with:
chart-search-root: "deployment templates"
- name: Install yq - portable yaml processor
uses: mikefarah/[email protected]
- name: Collect charts
id: charts
run: |
set -e
find -L '${{ env.CHART_DIR }}' -mindepth 2 -maxdepth 2 -type f \( -name 'Chart.yaml' -o -name 'Chart.yml' \) -exec dirname "{}" \; \
| sort -u \
| sed -E 's/^/- /' \
| yq --no-colors --indent 0 --output-format json '.' \
| sed -E 's/^/charts=/' >> $GITHUB_OUTPUT
- name: Install chart releaser
run: |
set -e
arch="$(dpkg --print-architecture)"
curl -s https://api.github.com/repos/helm/chart-releaser/releases/latest \
| yq --indent 0 --no-colors --input-format json --unwrapScalar \
".assets[] | select(.name | test("\""^chart-releaser_.+_linux_${arch}\.tar\.gz$"\"")) | .browser_download_url" \
| xargs curl -SsL \
| tar zxf - -C /usr/local/bin
- name: Install Helm
uses: azure/[email protected]
- name: Helm Deps
run: |
set -ex
echo '${{ steps.charts.outputs.charts }}' \
| yq --indent 0 --no-colors --input-format json --unwrapScalar '.[]' \
| while read -r dir; do
helm dependency update "$dir";
if [ -f "$dir/Chart.lock" ]; then
yq --indent 0 \
'.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' \
"$dir/Chart.lock" \
| sh --;
fi
done
- name: Package charts
id: package
run: |
set -ex
PACKAGES=.cr-release-packages
echo '${{ steps.charts.outputs.charts }}' \
| yq --indent 0 --no-colors --input-format json --unwrapScalar '.[]' \
| xargs -d$'\n' cr package --package-path "$PACKAGES"
echo "dir=${PACKAGES}" >> $GITHUB_OUTPUT
- name: Upload packages
run: |
set -ex
git config --list
owner=$(cut -d '/' -f 1 <<< '${{ env.CHART_REPO }}')
repo=$(cut -d '/' -f 2 <<< '${{ env.CHART_REPO }}')
cr upload --commit '${{ github.sha }}' --git-repo "$repo" --owner "$owner" --token '${{ github.token }}' \
--package-path '${{ steps.package.outputs.dir }}' --skip-existing
- name: Update charts index
working-directory: .helm-chart-repo
run: |
set -ex
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
mkdir -p .cr-index
owner=$(cut -d '/' -f 1 <<< '${{ env.CHART_REPO }}')
repo=$(cut -d '/' -f 2 <<< '${{ env.CHART_REPO }}')
cr index --git-repo "$repo" --owner "$owner" --pages-branch '${{ env.CHART_REPO_BRANCH }}' \
--package-path '../${{ steps.package.outputs.dir }}' \
--index-path .cr-index --push