-
Notifications
You must be signed in to change notification settings - Fork 0
261 lines (228 loc) · 8.52 KB
/
build_and_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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: Build and Release
on:
push:
branches:
- main
release:
types:
- created
permissions:
contents: write
env:
NAME: lumni
jobs:
prebuild:
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.generate_timestamp.outputs.release_tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Generate timestamp
id: generate_timestamp
run: |
TAG=$(bash ./ci/base36timestamp.sh)
echo "release_tag=$TAG" >> $GITHUB_OUTPUT
build:
needs: prebuild
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
#- target: aarch64-unknown-linux-gnu
# os: ubuntu-latest
#- target: x86_64-unknown-linux-musl
# os: ubuntu-latest
#- target: aarch64-unknown-linux-musl
# os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
env:
TARGET: ${{ matrix.target }}
OS: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Prepare build directories and set env vars (Ubuntu only)
if: runner.os == 'Linux'
run: |
sudo mkdir -p /mnt/cargo-build /mnt/cargo-home /mnt/rustup-home
sudo chmod 777 /mnt/cargo-build /mnt/cargo-home /mnt/rustup-home
echo "CARGO_TARGET_DIR=/mnt/cargo-build" >> $GITHUB_ENV
echo "CARGO_HOME=/mnt/cargo-home" >> $GITHUB_ENV
- name: Install and configure dependencies
run: |
# dependencies are only needed on ubuntu as that's the only place where
# we make cross-compilation
if [[ $OS =~ ^ubuntu.*$ ]]; then
sudo apt-get install -qq crossbuild-essential-arm64
fi
# some additional configuration for cross-compilation on linux
cat >>~/.cargo/config <<EOF
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
EOF
- name: Install target
run: rustup target add $TARGET
- name: Check disk usage
run: df -h
- name: Update version in Cargo.toml
id: update_version
run: |
CURRENT_VERSION=$(grep '^version' ./$NAME/Cargo.toml | sed 's/^version = \"\(.*\)\"/\1/')
if [[ $GITHUB_REF_TYPE == "tag" ]]; then
if [[ $GITHUB_REF_NAME =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
TAG=$GITHUB_REF_NAME
fi
else
TAG=${{ needs.prebuild.outputs.release_tag }}
VERSION="${CURRENT_VERSION%-pre}-$TAG"
fi
CARGO_TOML=$NAME/Cargo.toml
if [[ $OS == "macos-latest" ]]; then
sed -i '' "s/^version = \"[^\"]*\"/version = \"$VERSION\"/" ./$CARGO_TOML
else
sed -i "s/^version = \"[^\"]*\"/version = \"$VERSION\"/" ./$CARGO_TOML
fi
echo "Updated Cargo.toml to version $VERSION"
- name: Build project
run: cargo build -p $NAME --release --target $TARGET
- name: Check disk usage
run: df -h
- name: List target directory
run: |
if [[ $OS =~ ^ubuntu.*$ ]]; then
ls /mnt/cargo-build/$TARGET/release
else
ls target/$TARGET/release
fi
- name: Compress
run: |
[ -e ./build ] && rm -rf ./build
[ -e ./artifacts ] && rm -rf ./artifacts
mkdir -p ./artifacts ./build/bin
TAG=${{ needs.prebuild.outputs.release_tag }}
if [[ $OS =~ ^ubuntu.*$ ]]; then
mv /mnt/cargo-build/$TARGET/release/$NAME ./build/bin/$NAME
else
mv ./target/$TARGET/release/$NAME ./build/bin/$NAME
fi
OUTFILE=./artifacts/$NAME-$TARGET-$TAG.tar.gz
tar -czf $OUTFILE -C ./build .
shasum -a 256 $OUTFILE > $OUTFILE.sha256
- name: Archive artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.NAME }}-artifact
path: |
./artifacts
deploy:
runs-on: ubuntu-latest
needs: [prebuild, build]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.NAME }}-artifact
path: ./artifacts
- name: List artifacts
run: find ./artifacts
- name: Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
./artifacts/*.tar.gz*
tag_name: ${{ needs.prebuild.outputs.release_tag }}
name: ${{ needs.prebuild.outputs.release_tag }}
body: Automated release for ${{ github.sha }}
update-formula:
runs-on: ubuntu-latest
needs: [prebuild, deploy]
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Get release tag from previous step
id: vars
run: |
echo "RELEASE_TAG=${{ needs.prebuild.outputs.release_tag }}" >> $GITHUB_ENV
- name: Get release information
id: release
uses: actions/github-script@v7
with:
script: |
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: process.env.RELEASE_TAG
});
core.setOutput('release_tag', release.data.tag_name);
core.setOutput('assets', release.data.assets.map(asset => asset.browser_download_url).join('\n'));
- name: Download assets
run: |
mkdir -p assets
cd assets
echo "${{ steps.release.outputs.assets }}" | while IFS= read -r url; do
if [[ "$url" == *.tar.gz.sha256 ]]; then
echo "Downloading $url"
curl -LO "$url"
fi
done
- name: Extract SHA256 checksums
id: checksums
run: |
cd assets
# The following are examples for different platforms, uncomment as needed
SHA256_MAC_INTEL=$(awk '{print $1}' "${NAME}-x86_64-apple-darwin-${RELEASE_TAG}.tar.gz.sha256")
SHA256_MAC_ARM=$(awk '{print $1}' "${NAME}-aarch64-apple-darwin-${RELEASE_TAG}.tar.gz.sha256")
SHA256_LINUX_INTEL=$(awk '{print $1}' "${NAME}-x86_64-unknown-linux-gnu-${RELEASE_TAG}.tar.gz.sha256")
echo "SHA256_MAC_INTEL=${SHA256_MAC_INTEL}" >> "$GITHUB_OUTPUT"
echo "SHA256_MAC_ARM=${SHA256_MAC_ARM}" >> "$GITHUB_OUTPUT"
echo "SHA256_LINUX_INTEL=${SHA256_LINUX_INTEL}" >> "$GITHUB_OUTPUT"
- name: Checkout repository using Git and SSH
uses: actions/checkout@v3
with:
repository: serverlessnext/homebrew-lumni
ssh-key: ${{ secrets.DEPLOY_KEY_HOMEBREW_LUMNI }}
path: homebrew-lumni
- name: Create a new feature branch
run: |
cd homebrew-lumni
git checkout -b gh-update-formula-${RELEASE_TAG}
- name: Update formula
run: |
cd homebrew-lumni/Formula
cp ../templates/lumni.rb.template lumni.rb
SHA256_MAC_INTEL="${{ steps.checksums.outputs.SHA256_MAC_INTEL }}"
SHA256_MAC_ARM="${{ steps.checksums.outputs.SHA256_MAC_ARM }}"
SHA256_LINUX_INTEL="${{ steps.checksums.outputs.SHA256_LINUX_INTEL }}"
sed -i "s|{{ RELEASE_TAG }}|${RELEASE_TAG}|g" lumni.rb
sed -i "s|{{ SHA256_MAC_INTEL }}|${SHA256_MAC_INTEL}|g" lumni.rb
sed -i "s|{{ SHA256_MAC_ARM }}|${SHA256_MAC_ARM}|g" lumni.rb
sed -i "s|{{ SHA256_LINUX_INTEL }}|${SHA256_LINUX_INTEL}|g" lumni.rb
- name: Start SSH agent and deploy key
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY_HOMEBREW_LUMNI }}
run: |
eval "$(ssh-agent -s)"
echo "$DEPLOY_KEY" | ssh-add -
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Commit and push changes using custom SSH key
run: |
cd homebrew-lumni
git config user.email "[email protected]"
git config user.name "GitHub Action"
git add .
git commit -m "Update formula to release ${RELEASE_TAG}"
git push --set-upstream origin HEAD