Skip to content

Commit 808506a

Browse files
authored
chore: add simple release pipeline (#163)
1 parent 41dde6b commit 808506a

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

.github/workflows/release.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
- 'v[0-9]+.[0-9]+.[0-9]+'
11+
- 'v[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 ]
29+
# target: [ x86_64-apple-darwin, aarch64-apple-darwin, x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu ] Waiting for repo to be public
30+
include:
31+
- os: macos-14-large
32+
target: x86_64-apple-darwin
33+
binary_path: target/x86_64-apple-darwin/release
34+
name: x86_64-darwin
35+
tar: gtar
36+
- os: macos-14
37+
target: aarch64-apple-darwin
38+
binary_path: target/aarch64-apple-darwin/release
39+
name: aarch64-darwin
40+
tar: gtar
41+
- os: ubuntu-22.04
42+
target: x86_64-unknown-linux-gnu
43+
binary_path: target/x86_64-unknown-linux-gnu/release
44+
name: x86_64-linux
45+
tar: tar
46+
# - os: ubuntu-22.04-arm
47+
# target: aarch64-unknown-linux-gnu
48+
# binary_path: target/aarch64-unknown-linux-gnu/release
49+
# name: aarch64-linux
50+
# tar: tar
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Setup environment variables
55+
run: |
56+
echo "RUSTFLAGS=--remap-path-prefix=${GITHUB_WORKSPACE}=/builds/dfinity" >> $GITHUB_ENV
57+
58+
- name: Set names (tag only)
59+
if: github.ref_type == 'tag'
60+
run: |
61+
REF_NAME_SANITIZED=$(echo "$GITHUB_REF_NAME" | tr '/' '-')
62+
echo "TARBALL_FILENAME=icp-cli-$REF_NAME_SANITIZED-${{ matrix.name }}.tar.gz" >> $GITHUB_ENV
63+
echo "SHA256_FILENAME=icp-cli-$REF_NAME_SANITIZED-${{ matrix.name }}.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+
target/
75+
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('rust-toolchain.toml') }}-publish-1
76+
77+
- name: Build
78+
run: |
79+
cargo clean --target ${{ matrix.target }} --release
80+
cargo build --target ${{ matrix.target }} --locked --release
81+
82+
- name: Strip binaries
83+
run: |
84+
cd ${{ matrix.binary_path }}
85+
sudo chown -R $(whoami) .
86+
strip icp
87+
if: contains(matrix.os, 'ubuntu')
88+
89+
- name: Create tarball of binaries and sha256 of tarball
90+
if: github.ref_type == 'tag'
91+
run: |
92+
${{ matrix.tar }} -zcC ${{ matrix.binary_path }} -f ${{ env.TARBALL_FILENAME }} icp
93+
shasum -a 256 ${{ env.TARBALL_FILENAME }} > ${{ env.SHA256_FILENAME }}
94+
shasum -c ${{ env.SHA256_FILENAME }}
95+
96+
- name: Upload Artifacts
97+
if: github.ref_type == 'tag'
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: icp-artifacts-${{ hashFiles('rust-toolchain.toml') }}-${{ matrix.name }}
101+
path: |
102+
${{ env.TARBALL_FILENAME }}
103+
${{ env.SHA256_FILENAME }}
104+
105+
aggregate:
106+
name: publishable:required
107+
if: ${{ always() }}
108+
needs: [build_icp]
109+
runs-on: ubuntu-latest
110+
steps:
111+
- name: check build result
112+
if: ${{ needs.build_icp.result != 'success' }}
113+
run: exit 1
114+
115+
publish:
116+
runs-on: ubuntu-latest
117+
if: github.ref_type == 'tag'
118+
needs: build_icp
119+
permissions:
120+
contents: write
121+
strategy:
122+
fail-fast: false
123+
matrix:
124+
name: [ 'x86_64-darwin', 'aarch64-darwin', 'x86_64-linux']
125+
# name: [ 'x86_64-darwin', 'aarch64-darwin', 'x86_64-linux', 'aarch64-linux' ]
126+
steps:
127+
- uses: actions/checkout@v4
128+
129+
- name: Setup environment variables
130+
run: echo "VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
131+
132+
- name: Download Artifacts
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: icp-artifacts-${{ hashFiles('rust-toolchain.toml') }}-${{ matrix.name }}
136+
137+
- name: Upload tarball and sha256
138+
uses: svenstaro/upload-release-action@v2
139+
with:
140+
repo_token: ${{ secrets.GITHUB_TOKEN }}
141+
file: icp-*.tar.*
142+
file_glob: true
143+
tag: ${{ env.VERSION }}
144+
prerelease: true
145+
make_latest: false

0 commit comments

Comments
 (0)