Skip to content

Commit 726c1b6

Browse files
committed
ci: add build.yml and release.yml
Signed-off-by: Xin Liu <sam@secondstate.io>
1 parent eff7489 commit 726c1b6

File tree

2 files changed

+307
-0
lines changed

2 files changed

+307
-0
lines changed

.github/workflows/build.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
- main
8+
- release-*
9+
- feat-*
10+
- ci-*
11+
- refactor-*
12+
- fix-*
13+
- test-*
14+
paths:
15+
- '.github/workflows/build.yml'
16+
- '**/Cargo.toml'
17+
- '**/*.rs'
18+
- '**/*.sh'
19+
pull_request:
20+
branches:
21+
- dev
22+
- main
23+
types: [opened, synchronize, reopened]
24+
paths:
25+
- '.github/workflows/**'
26+
- '**/Cargo.toml'
27+
- '**/*.rs'
28+
- '**/*.sh'
29+
30+
jobs:
31+
check:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Clone project
35+
uses: actions/checkout@v5
36+
37+
- name: Install Rust-nightly
38+
uses: actions-rust-lang/setup-rust-toolchain@v1
39+
with:
40+
toolchain: nightly
41+
components: rustfmt, clippy
42+
43+
- name: Run clippy
44+
run: |
45+
cargo +nightly clippy --all-features -- -D warnings
46+
47+
- name: Run fmt
48+
run: |
49+
cargo +nightly fmt --all -- --check
50+
51+
build_macos:
52+
runs-on: ${{ matrix.os }}
53+
strategy:
54+
matrix:
55+
os: [macos-13, macos-14, macos-15]
56+
steps:
57+
- name: Clone project
58+
id: checkout
59+
uses: actions/checkout@v5
60+
61+
- name: Install Rust-stable
62+
uses: actions-rust-lang/setup-rust-toolchain@v1
63+
64+
- name: Build
65+
run: |
66+
cargo build --release
67+
68+
build_linux:
69+
runs-on: ${{ matrix.os }}
70+
container:
71+
image: ${{ matrix.image }}
72+
strategy:
73+
matrix:
74+
build: [linux-x86_64, linux-aarch64]
75+
include:
76+
- build: linux-x86_64
77+
os: ubuntu-22.04
78+
image: ubuntu:20.04
79+
target: x86_64-unknown-linux-gnu
80+
- build: linux-aarch64
81+
os: ubuntu-22.04-arm
82+
image: arm64v8/ubuntu:20.04
83+
target: aarch64-unknown-linux-gnu
84+
fail-fast: false
85+
86+
steps:
87+
- name: Clone project
88+
id: checkout
89+
uses: actions/checkout@v5
90+
91+
- name: Install dependencies silently
92+
run: |
93+
export DEBIAN_FRONTEND=noninteractive
94+
apt update && apt install -y curl build-essential pkg-config cmake clang nasm ninja-build git
95+
96+
- name: Install Rust-stable
97+
uses: actions-rust-lang/setup-rust-toolchain@v1
98+
99+
- name: List targets
100+
run: |
101+
rustup target list --installed
102+
103+
- name: Build
104+
run: |
105+
cargo build --release

.github/workflows/release.yml

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch: # manual trigger release
5+
inputs:
6+
create_release:
7+
description: 'Create new release'
8+
required: true
9+
type: boolean
10+
release_version:
11+
description: "Version (e.g. 1.0.0)"
12+
required: true
13+
type: string
14+
15+
jobs:
16+
build_macos:
17+
name: build_macos
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
build: [macos-x86_64, macos-arm64]
22+
include:
23+
- build: macos-x86_64
24+
os: macos-latest
25+
rust: stable
26+
target: x86_64-apple-darwin
27+
archive-name: cardea-weather-apple-darwin-x86_64.tar.gz
28+
bin-path: macos-x86_64-binary
29+
- build: macos-arm64
30+
os: macos-latest
31+
rust: stable
32+
target: aarch64-apple-darwin
33+
archive-name: cardea-weather-apple-darwin-aarch64.tar.gz
34+
bin-path: macos-arm64-binary
35+
fail-fast: false
36+
steps:
37+
- name: Checkout repository
38+
id: checkout
39+
uses: actions/checkout@v5
40+
41+
- name: Install Rust
42+
uses: actions-rust-lang/setup-rust-toolchain@v1
43+
with:
44+
toolchain: ${{ matrix.rust }}
45+
target: ${{ matrix.target }}
46+
47+
- name: List targets
48+
run: |
49+
rustup target list --installed
50+
51+
- name: Build binary
52+
run: cargo build --release --target ${{ matrix.target }}
53+
env:
54+
RUST_BACKTRACE: 1
55+
56+
- name: Strip binary
57+
run: |
58+
strip "target/${{ matrix.target }}/release/cardea-weather"
59+
60+
ls -al "target/${{ matrix.target }}/release"
61+
62+
- name: Build archive
63+
shell: bash
64+
run: |
65+
mkdir archive
66+
cd archive
67+
68+
cp "../target/${{ matrix.target }}/release/cardea-weather" ./
69+
70+
tar -czf "${{ matrix.archive-name }}" *
71+
ls -al
72+
73+
- name: Upload archive
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: ${{ matrix.bin-path }}
77+
path: archive/${{ matrix.archive-name }}
78+
79+
build_linux:
80+
name: build_linux
81+
runs-on: ${{ matrix.os }}
82+
container:
83+
image: ${{ matrix.image }}
84+
strategy:
85+
matrix:
86+
build: [linux-x86_64, linux-aarch64]
87+
include:
88+
- build: linux-x86_64
89+
os: ubuntu-22.04
90+
image: ubuntu:20.04
91+
rust: nightly
92+
target: x86_64-unknown-linux-gnu
93+
archive-name: cardea-weather-unknown-linux-gnu-x86_64.tar.gz
94+
bin-path: linux-x86_64-binary
95+
- build: linux-aarch64
96+
os: ubuntu-22.04-arm
97+
image: arm64v8/ubuntu:20.04
98+
rust: nightly
99+
target: aarch64-unknown-linux-gnu
100+
archive-name: cardea-weather-unknown-linux-gnu-aarch64.tar.gz
101+
bin-path: linux-aarch64-binary
102+
fail-fast: false
103+
steps:
104+
- name: Checkout repository
105+
id: checkout
106+
uses: actions/checkout@v5
107+
108+
- name: Install dependencies silently
109+
run: |
110+
export DEBIAN_FRONTEND=noninteractive
111+
apt update && apt install -y curl build-essential pkg-config
112+
113+
- name: Install Rust-stable
114+
uses: actions-rust-lang/setup-rust-toolchain@v1
115+
116+
- name: Build binary
117+
run: cargo build --release --target ${{ matrix.target }}
118+
env:
119+
RUST_BACKTRACE: 1
120+
121+
- name: Strip binary
122+
run: |
123+
strip "target/${{ matrix.target }}/release/cardea-weather"
124+
125+
ls -al "target/${{ matrix.target }}/release"
126+
127+
- name: Build archive
128+
shell: bash
129+
run: |
130+
mkdir archive
131+
cd archive
132+
133+
cp "../target/${{ matrix.target }}/release/cardea-weather" ./
134+
135+
tar -czf "${{ matrix.archive-name }}" *
136+
ls -al
137+
138+
- name: Upload archive
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: ${{ matrix.bin-path }}
142+
path: archive/${{ matrix.archive-name }}
143+
144+
release:
145+
name: release
146+
runs-on: ubuntu-latest
147+
permissions:
148+
contents: write
149+
needs: [build_macos, build_linux]
150+
steps:
151+
- name: Download artifacts (linux-x86_64-binary)
152+
uses: actions/download-artifact@v4
153+
with:
154+
name: linux-x86_64-binary
155+
path: linux-x86_64-binary
156+
157+
- name: Download artifacts (linux-aarch64-binary)
158+
uses: actions/download-artifact@v4
159+
with:
160+
name: linux-aarch64-binary
161+
path: linux-aarch64-binary
162+
163+
- name: Download artifacts (macos-x86_64-binary)
164+
uses: actions/download-artifact@v4
165+
with:
166+
name: macos-x86_64-binary
167+
path: macos-x86_64-binary
168+
169+
- name: Download artifacts (macos-arm64-binary)
170+
uses: actions/download-artifact@v4
171+
with:
172+
name: macos-arm64-binary
173+
path: macos-arm64-binary
174+
175+
- name: Display structure of downloaded files
176+
run: |
177+
ls -al
178+
ls -al linux-x86_64-binary
179+
ls -al linux-aarch64-binary
180+
ls -al macos-x86_64-binary
181+
ls -al macos-arm64-binary
182+
183+
- name: Tag and release names
184+
id: tag_and_release_names
185+
run: |
186+
echo "tag_name=${{ github.event.inputs.release_version }}" >> $GITHUB_OUTPUT
187+
echo "release_name=Cardea-Weather ${{ github.event.inputs.release_version }}" >> $GITHUB_OUTPUT
188+
189+
- name: Create Release and Upload Release Asset
190+
if: ${{ github.event.inputs.create_release == 'true' && github.ref == 'refs/heads/main'}}
191+
uses: softprops/action-gh-release@v2.2.2
192+
with:
193+
name: ${{ steps.tag_and_release_names.outputs.release_name }}
194+
tag_name: ${{ steps.tag_and_release_names.outputs.tag_name }}
195+
body: TODO New Release.
196+
draft: true
197+
prerelease: true
198+
files: |
199+
linux-x86_64-binary/*
200+
linux-aarch64-binary/*
201+
macos-x86_64-binary/*
202+
macos-arm64-binary/*

0 commit comments

Comments
 (0)