-
Notifications
You must be signed in to change notification settings - Fork 3
206 lines (186 loc) · 6.85 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
on:
release:
types:
- published
workflow_dispatch:
name: Release new version
jobs:
validate-version:
name: Validate `Cargo.toml` version matches tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.validate.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Validate version
id: validate
continue-on-error: ${{ github.event_name == 'workflow_dispatch' }}
run: |
# Extract the version from the Cargo.toml
VERSION=$(cat "Cargo.toml" | grep '^version =' | awk '{ split($0,version,"=") ; gsub(/[\ \"]/, "", version[2]) ; print version[2] }')
echo version=$VERSION >> "$GITHUB_OUTPUT"
echo "Cargo.toml version: \`$VERSION\`" >> $GITHUB_STEP_SUMMARY
if [ "v${VERSION}" != "${{ github.event.release.tag_name }}" ]; then
echo "::error file=Cargo.toml::Version set in Cargo.toml (v${VERSION}) does not match release version (${{ github.event.release.tag_name }})"
exit 1
fi
build-artifacts:
name: Build (${{ matrix.platform.name }})
needs: validate-version
runs-on: ${{ matrix.platform.os }}
strategy:
matrix:
platform:
- name: linux_aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
bin: am
file-name: am-linux-aarch64
- name: linux_x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
bin: am
file-name: am-linux-x86_64
- name: macos_aarch64
os: macOS-latest
target: aarch64-apple-darwin
bin: am
file-name: am-macos-aarch64
- name: macos_x86_64
os: macOS-latest
target: x86_64-apple-darwin
bin: am
file-name: am-macos-x86_64
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
uses: houseabsolute/actions-rust-cross@v0
with:
target: ${{ matrix.platform.target }}
args: "--locked --release"
strip: true
- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.platform.file-name }}
path: "target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}"
publish-artifacts-docker:
name: Build and publish multi-arch Docker image
runs-on: ubuntu-latest
needs: [build-artifacts, validate-version]
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Download am artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Prepare files
run: |
mkdir -p build/linux/{amd64,arm64}/
mv artifacts/am-linux-x86_64/am build/linux/amd64/am
mv artifacts/am-linux-aarch64/am build/linux/arm64/am
chmod u+x build/linux/{amd64,arm64}/am
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push to Docker Hub
uses: docker/build-push-action@v4
with:
file: Dockerfile.release
context: build
platforms: linux/amd64,linux/arm64
push: true
tags: |
autometrics/am:v${{ needs.validate-version.outputs.version }}
autometrics/am:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push to Docker Hub
uses: docker/build-push-action@v4
with:
file: Dockerfile.proxy
context: build
platforms: linux/amd64,linux/arm64
push: true
tags: |
autometrics/am-proxy:v${{ needs.validate-version.outputs.version }}
autometrics/am-proxy:latest
cache-from: type=gha
cache-to: type=gha,mode=max
finalize-release:
name: Upload artifacts, trigger homebrew workflow
needs: [build-artifacts, validate-version]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download am artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Prepare files
run: |
mv artifacts/am-linux-aarch64/am am-linux-aarch64
mv artifacts/am-linux-x86_64/am am-linux-x86_64
mv artifacts/am-macos-aarch64/am am-macos-aarch64
mv artifacts/am-macos-x86_64/am am-macos-x86_64
- name: Calculate sha256sum
run: |
sha256sum am-linux-aarch64 >> am-linux-aarch64.sha256
sha256sum am-linux-x86_64 >> am-linux-x86_64.sha256
sha256sum am-macos-aarch64 >> am-macos-aarch64.sha256
sha256sum am-macos-x86_64 >> am-macos-x86_64.sha256
echo "### Checksums"
echo "\`$(cat am-linux-aarch64.sha256)\`" >> $GITHUB_STEP_SUMMARY
echo "\`$(cat am-linux-x86_64.sha256)\`" >> $GITHUB_STEP_SUMMARY
echo "\`$(cat am-macos-aarch64.sha256)\`" >> $GITHUB_STEP_SUMMARY
echo "\`$(cat am-macos-x86_64.sha256)\`" >> $GITHUB_STEP_SUMMARY
- name: Upload checksums
uses: actions/upload-artifact@v3
with:
name: checksums
path: "*.sha256"
- name: Attach artifacts to release
uses: softprops/action-gh-release@v1
if: ${{ github.event_name == 'release' }}
with:
files: |
am-linux-aarch64
am-linux-aarch64.sha256
am-linux-x86_64
am-linux-x86_64.sha256
am-macos-aarch64
am-macos-aarch64.sha256
am-macos-x86_64
am-macos-x86_64.sha256
- name: Trigger homebrew workflow
if: ${{ github.event_name == 'release' }}
env:
AM_VERSION: ${{ needs.validate-version.outputs.version }}
GH_TOKEN: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
run: |
gh workflow run update_formula.yml \
-R autometrics-dev/homebrew-tap \
-f AM_VERSION=$AM_VERSION \
-f SHA256_AARCH64_APPLE_DARWIN=$(cat am-macos-aarch64.sha256 | awk '{print $1}') \
-f SHA256_AARCH64_LINUX_GNU=$(cat am-linux-aarch64.sha256 | awk '{print $1}') \
-f SHA256_X86_64_APPLE_DARWIN=$(cat am-macos-x86_64.sha256 | awk '{print $1}') \
-f SHA256_X86_64_LINUX_GNU=$(cat am-linux-x86_64.sha256 | awk '{print $1}')
- name: Trigger the CLI reference docs update
env:
GH_TOKEN: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
run: |
gh workflow run update-cli-reference.yml \
-R autometrics-dev/docs