-
Notifications
You must be signed in to change notification settings - Fork 149
171 lines (164 loc) · 5.68 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
name: Release
on:
push:
tags:
- v*.*.*
jobs:
release:
name: Build release artifacts
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: aarch64-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Rust
run: rustup target add ${{ matrix.target }}
- name: Install additional toolchains
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
set -x
case "${{ matrix.target }}" in
x86_64-unknown-linux-gnu)
;;
x86_64-unknown-linux-musl)
sudo apt-get update
sudo apt-get install -y musl-tools
;;
aarch64-unknown-linux-gnu)
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config
echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config
;;
aarch64-unknown-linux-musl)
mkdir -p $HOME/.local
curl -o /tmp/musl.tgz https://musl.cc/aarch64-linux-musl-cross.tgz
tar -xzf /tmp/musl.tgz -C $HOME/.local
echo "$HOME/.local/aarch64-linux-musl-cross/bin" >> $GITHUB_PATH
echo '[target.aarch64-unknown-linux-musl]' >> .cargo/config
echo 'linker = "aarch64-linux-musl-gcc"' >> .cargo/config
;;
esac
- name: Configure cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: release-${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Strip binary
if: ${{ matrix.os != 'windows-latest' }}
run: |
set -x
strip="strip"
case "${{ matrix.target }}" in
x86_64-unknown-linux-gnu)
;;
x86_64-unknown-linux-musl)
;;
aarch64-unknown-linux-gnu)
strip=aarch64-linux-gnu-strip
;;
aarch64-unknown-linux-musl)
strip=aarch64-linux-musl-strip
;;
esac
${strip} target/${{ matrix.target }}/release/grcov
- name: Package (unix)
if: ${{ matrix.os != 'windows-latest' }}
run: |
set -x
rm -rf target/dist
mkdir target/dist
cd target/${{ matrix.target }}/release
tar cjf ../../dist/grcov-${{ matrix.target }}.tar.bz2 grcov
- name: Package (windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
if (Test-Path target/dist) { rm -Recurse -Force target/dist }
mkdir target/dist
cd target/${{ matrix.target }}/release
7z a ../../dist/grcov-${{ matrix.target }}.zip grcov.exe
- name: Upload archive
uses: actions/upload-artifact@v3
with:
name: artifact-${{ matrix.target }}
path: target/dist/*
publish:
name: Publish release
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Create checksums
run: |
set -x
for dir in $(pwd)/artifact-*; do
cd $dir
sha256sum -b * >> ~/checksums.sha256
done
- name: Create release
id: release
run: |
set -x
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/releases \
--header "Accept: application/vnd.github.v3+json" \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--header "Content-Type: application/json" \
--data '{
"tag_name": "${{ github.ref_name }}",
"name": "Release ${{ github.ref_name }}",
"body": "Release ${{ github.ref_name }}",
"draft": true
}' \
--fail > release.json
id=$(jq .id release.json)
echo "id=$id" >> $GITHUB_OUTPUT
- name: Upload artifacts
run: |
set -x
for file in $(ls artifact-*/*.{tar.bz2,zip}) ~/checksums.sha256; do
filename=$(basename -- "$file")
extension="${filename#*.}"
type="text/plain"
case $extension in
zip)
type="application/zip"
;;
tar.bz2)
type="application/x-bzip2"
;;
esac
curl --request POST \
--url https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.release.outputs.id }}/assets?name=${filename} \
--header "Accept: application/vnd.github.v3+json" \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--header "Content-Type: ${type}" \
--data-binary "@${file}" \
--fail
done