Skip to content

Commit 2fb22be

Browse files
committed
chore: add simple release pipeline
1 parent aeb442d commit 2fb22be

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

.github/workflows/release.yml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Publish
2+
3+
# We have to use gtar on macOS because apple's tar is literally broken.
4+
# Yes, I know how stupid that sounds. But it's true:
5+
# https://github.com/actions/virtual-environments/issues/2619
6+
7+
on:
8+
push:
9+
tags:
10+
- 'release-[0-9]+.[0-9]+.[0-9]+'
11+
- 'release-[0-9]+.[0-9]+.[0-9]+-[A-Za-z]+.[0-9]+'
12+
pull_request:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
env:
19+
# When getting Rust dependencies, retry on network error:
20+
CARGO_NET_RETRY: 10
21+
22+
jobs:
23+
build_icp:
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
target: [ x86_64-apple-darwin, aarch64-apple-darwin, x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu ]
29+
include:
30+
- os: macos-14-large
31+
target: x86_64-apple-darwin
32+
binary_path: target/x86_64-apple-darwin/release
33+
name: x86_64-darwin
34+
tar: gtar
35+
- os: macos-14
36+
target: aarch64-apple-darwin
37+
binary_path: target/aarch64-apple-darwin/release
38+
name: aarch64-darwin
39+
tar: gtar
40+
- os: ubuntu-22.04
41+
target: x86_64-unknown-linux-gnu
42+
binary_path: target/x86_64-unknown-linux-gnu/release
43+
name: x86_64-linux
44+
tar: tar
45+
- os: ubuntu-22.04-arm
46+
target: aarch64-unknown-linux-gnu
47+
binary_path: target/aarch64-unknown-linux-gnu/release
48+
name: aarch64-linux
49+
tar: tar
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Setup environment variables
54+
run: |
55+
echo "RUSTFLAGS=--remap-path-prefix=${GITHUB_WORKSPACE}=/builds/dfinity" >> $GITHUB_ENV
56+
57+
- name: Set names (tag only)
58+
if: github.ref_type == 'tag'
59+
run: |
60+
echo "TARBALL_1_FILENAME=icp-cli-$GITHUB_REF_NAME-${{ matrix.name }}.tar.gz" >> $GITHUB_ENV
61+
echo "SHA256_1_FILENAME=icp-cli-$GITHUB_REF_NAME-${{ matrix.name }}.tar.gz.sha256" >> $GITHUB_ENV
62+
echo "TARBALL_2_FILENAME=icp-cli-${{ matrix.target }}.tar.gz" >> $GITHUB_ENV
63+
echo "SHA256_2_FILENAME=icp-cli-${{ matrix.target }}.tar.gz.sha256" >> $GITHUB_ENV
64+
65+
- name: Cache Cargo
66+
uses: actions/cache@v4
67+
with:
68+
path: |
69+
~/.cargo/bin/
70+
~/.cargo/registry/index/
71+
~/.cargo/registry/cache/
72+
~/.cargo/git/db/
73+
~/.rustup/
74+
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('rust-toolchain.toml') }}-publish-1
75+
76+
- name: Build
77+
run: |
78+
cargo clean --target ${{ matrix.target }} --release
79+
cargo build --target ${{ matrix.target }} --locked --release
80+
81+
- name: Strip binaries
82+
run: |
83+
cd ${{ matrix.binary_path }}
84+
sudo chown -R $(whoami) .
85+
strip icp
86+
if: contains(matrix.os, 'ubuntu')
87+
88+
- name: Create tarball of binaries and sha256 of tarball
89+
if: github.ref_type == 'tag'
90+
run: |
91+
mkdir icp-${{ matrix.target }}
92+
cp ${{ matrix.binary_path }}/icp icp-${{ matrix.target }}
93+
cp LICENSE icp-${{ matrix.target }}
94+
${{ matrix.tar }} -zc -f ${{ env.TARBALL_2_FILENAME }} icp-${{ matrix.target }}
95+
shasum -a 256 ${{ env.TARBALL_2_FILENAME }} > ${{ env.SHA256_2_FILENAME }}
96+
shasum -c ${{ env.SHA256_2_FILENAME }}
97+
98+
${{ matrix.tar }} -zcC ${{ matrix.binary_path }} -f ${{ env.TARBALL_1_FILENAME }} icp
99+
shasum -a 256 ${{ env.TARBALL_1_FILENAME }} > ${{ env.SHA256_1_FILENAME }}
100+
shasum -c ${{ env.SHA256_1_FILENAME }}
101+
102+
- name: Upload Artifacts
103+
if: github.ref_type == 'tag'
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: icp-artifacts-${{ hashFiles('rust-toolchain.toml') }}-${{ matrix.name }}
107+
path: |
108+
${{ env.TARBALL_1_FILENAME }}
109+
${{ env.SHA256_1_FILENAME }}
110+
${{ env.TARBALL_2_FILENAME }}
111+
${{ env.SHA256_2_FILENAME }}
112+
113+
aggregate:
114+
name: publishable:required
115+
if: ${{ always() }}
116+
needs: [build_icp]
117+
runs-on: ubuntu-latest
118+
steps:
119+
- name: check build result
120+
if: ${{ needs.build_icp.result != 'success' }}
121+
run: exit 1
122+
123+
publish:
124+
runs-on: ubuntu-latest
125+
if: github.ref_type == 'tag'
126+
needs: build_icp
127+
strategy:
128+
fail-fast: false
129+
matrix:
130+
name: [ 'x86_64-darwin', 'aarch64-darwin', 'x86_64-linux', 'aarch64-linux' ]
131+
steps:
132+
- uses: actions/checkout@v4
133+
134+
- name: Setup environment variables
135+
run: echo "VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
136+
137+
- name: Download Artifacts
138+
uses: actions/download-artifact@v4
139+
with:
140+
name: icp-artifacts-${{ hashFiles('rust-toolchain.toml') }}-${{ matrix.name }}
141+
142+
- name: Upload tarball and sha256
143+
uses: svenstaro/upload-release-action@v2
144+
with:
145+
repo_token: ${{ secrets.GITHUB_TOKEN }}
146+
file: icp-*.tar.*
147+
file_glob: true
148+
tag: ${{ env.VERSION }}
149+
prerelease: true
150+
make_latest: false

0 commit comments

Comments
 (0)