Skip to content

Commit 3a3ce10

Browse files
committed
ci: add release workflow for tagged versions
1 parent add4266 commit 3a3ce10

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
build:
13+
name: Build ${{ matrix.target }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
include:
18+
- os: ubuntu-latest
19+
target: x86_64-unknown-linux-gnu
20+
artifact_name: emon
21+
asset_name: emon-tui-${{ github.ref_name }}-x86_64-unknown-linux-gnu
22+
- os: ubuntu-latest
23+
target: aarch64-unknown-linux-gnu
24+
artifact_name: emon
25+
asset_name: emon-tui-${{ github.ref_name }}-aarch64-unknown-linux-gnu
26+
- os: macos-latest
27+
target: x86_64-apple-darwin
28+
artifact_name: emon
29+
asset_name: emon-tui-${{ github.ref_name }}-x86_64-apple-darwin
30+
- os: macos-latest
31+
target: aarch64-apple-darwin
32+
artifact_name: emon
33+
asset_name: emon-tui-${{ github.ref_name }}-aarch64-apple-darwin
34+
- os: windows-latest
35+
target: x86_64-pc-windows-msvc
36+
artifact_name: emon.exe
37+
asset_name: emon-tui-${{ github.ref_name }}-x86_64-pc-windows-msvc
38+
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
43+
- name: Install Rust toolchain
44+
uses: dtolnay/rust-toolchain@stable
45+
with:
46+
targets: ${{ matrix.target }}
47+
48+
- name: Install cross-compilation tools (Linux ARM64)
49+
if: matrix.target == 'aarch64-unknown-linux-gnu'
50+
run: |
51+
sudo apt-get update
52+
sudo apt-get install -y gcc-aarch64-linux-gnu
53+
54+
- name: Build
55+
run: |
56+
cargo build --release --target ${{ matrix.target }}
57+
58+
- name: Strip binary (Linux/macOS)
59+
if: runner.os != 'Windows'
60+
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
61+
62+
- name: Prepare archive
63+
shell: bash
64+
run: |
65+
cd target/${{ matrix.target }}/release
66+
if [ "${{ runner.os }}" = "Windows" ]; then
67+
7z a ../../../${{ matrix.asset_name }}.zip ${{ matrix.artifact_name }}
68+
else
69+
tar czf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
70+
fi
71+
cd ../../..
72+
73+
- name: Upload artifact
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: ${{ matrix.asset_name }}
77+
path: |
78+
${{ matrix.asset_name }}.tar.gz
79+
${{ matrix.asset_name }}.zip
80+
81+
release:
82+
name: Create Release
83+
needs: build
84+
runs-on: ubuntu-latest
85+
permissions:
86+
contents: write
87+
88+
steps:
89+
- name: Checkout
90+
uses: actions/checkout@v4
91+
92+
- name: Download all artifacts
93+
uses: actions/download-artifact@v4
94+
with:
95+
path: artifacts
96+
97+
- name: Display structure of downloaded files
98+
run: ls -R artifacts
99+
100+
- name: Create checksums
101+
run: |
102+
cd artifacts
103+
for dir in */; do
104+
cd "$dir"
105+
for file in *; do
106+
if [ -f "$file" ]; then
107+
sha256sum "$file" >> ../checksums.txt
108+
fi
109+
done
110+
cd ..
111+
done
112+
cat checksums.txt
113+
114+
- name: Create Release
115+
uses: softprops/action-gh-release@v2
116+
with:
117+
files: |
118+
artifacts/*/*.tar.gz
119+
artifacts/*/*.zip
120+
artifacts/checksums.txt
121+
generate_release_notes: true
122+
draft: false
123+
prerelease: ${{ contains(github.ref_name, 'beta') || contains(github.ref_name, 'b') || contains(github.ref_name, 'alpha') }}
124+
env:
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)