Skip to content

Commit 6a38f13

Browse files
committed
fix: adjust workflows structure to .github directory at repo root
1 parent ff172bd commit 6a38f13

2 files changed

Lines changed: 305 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Reusable Release Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
cliff-config:
7+
description: 'Path to changelog configuration file'
8+
required: true
9+
type: string
10+
11+
on:
12+
workflow_call:
13+
inputs:
14+
cliff-config:
15+
description: 'Path to git-cliff config file'
16+
required: false
17+
type: string
18+
default: '.github/cliff.toml'
19+
20+
jobs:
21+
release:
22+
name: Release
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write
26+
steps:
27+
#--------------------------------------------------
28+
# Setup Steps
29+
#--------------------------------------------------
30+
- name: Checkout code
31+
uses: actions/checkout@v6
32+
with:
33+
fetch-depth: 0
34+
fetch-tags: true
35+
36+
- name: Download binary artifacts
37+
uses: actions/download-artifact@v7
38+
with:
39+
pattern: "*-binaries"
40+
path: ./packages
41+
merge-multiple: true
42+
43+
#--------------------------------------------------
44+
# Changelog Generation
45+
#--------------------------------------------------
46+
- name: Generate changelog
47+
uses: orhun/git-cliff-action@v4
48+
id: git-cliff
49+
with:
50+
config: ${{ inputs.cliff-config }}
51+
args: --latest --strip header
52+
env:
53+
GITHUB_REPO: ${{ github.repository }}
54+
55+
#--------------------------------------------------
56+
# Release Publishing
57+
#--------------------------------------------------
58+
- name: Create and publish release
59+
if: startsWith(github.ref, 'refs/tags/v')
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
TAG_NAME: ${{ github.ref_name }}
63+
run: |
64+
# Create draft release with changelog
65+
gh release create "$TAG_NAME" --draft --notes "${{ steps.git-cliff.outputs.content }}"
66+
67+
# Upload all package files
68+
find ./packages -type f -exec gh release upload "$TAG_NAME" {} \;
69+
70+
# Upload LICENSE file
71+
gh release upload "$TAG_NAME" LICENSE
72+
73+
# Publish the release (change from draft to published)
74+
gh release edit "$TAG_NAME" --draft=false

.github/workflows/rust-build.yml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
name: Reusable Build Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
rust-toolchain:
7+
description: 'Rust toolchain to use'
8+
required: false
9+
type: string
10+
default: 'stable'
11+
packages:
12+
description: 'Comma-separated list of package names'
13+
required: true
14+
type: string
15+
target-config-file:
16+
description: 'Path to the TOML file containing target configurations'
17+
required: false
18+
type: string
19+
default: '.github/target.toml'
20+
run-tests:
21+
description: 'Whether to run tests (can be overridden)'
22+
required: false
23+
type: boolean
24+
default: true
25+
26+
on:
27+
workflow_call:
28+
inputs:
29+
rust-toolchain:
30+
description: 'Rust toolchain to use'
31+
required: false
32+
type: string
33+
default: 'stable'
34+
packages:
35+
description: 'Comma-separated list of package names'
36+
required: true
37+
type: string
38+
target-config-file:
39+
description: 'Path to the TOML file containing target configurations'
40+
required: false
41+
type: string
42+
default: '.github/target.toml'
43+
run-tests:
44+
description: 'Whether to run tests (can be overridden by matrix config)'
45+
required: false
46+
type: boolean
47+
default: true
48+
cache-key-prefix:
49+
description: 'Prefix for cache key to avoid collisions'
50+
required: false
51+
type: string
52+
default: 'rust-build'
53+
rustflags:
54+
description: 'Additional RUSTFLAGS to pass to the compiler'
55+
required: false
56+
type: string
57+
default: ''
58+
59+
defaults:
60+
run:
61+
shell: bash
62+
63+
env:
64+
RUSTC_BOOTSTRAP: "1"
65+
66+
jobs:
67+
prepare:
68+
runs-on: ubuntu-latest
69+
outputs:
70+
target_config: ${{ steps.parse_config.outputs.targets }}
71+
steps:
72+
- name: Checkout code
73+
uses: actions/checkout@v6
74+
75+
- name: Install yj tool
76+
run: |
77+
# Install yj for TOML to JSON conversion
78+
curl -fsSL https://github.com/sclevine/yj/releases/latest/download/yj-linux-amd64 -o /usr/local/bin/yj
79+
chmod +x /usr/local/bin/yj
80+
81+
- name: Parse TOML configuration
82+
id: parse_config
83+
run: |
84+
if [ ! -f "${{ inputs.target-config-file }}" ]; then
85+
echo "Error: Target configuration file not found at ${{ inputs.target-config-file }}"
86+
exit 1
87+
fi
88+
TARGETS_JSON=$(cat ${{ inputs.target-config-file }} | yj -tj | jq -c '.target')
89+
echo "targets=$TARGETS_JSON" >> $GITHUB_OUTPUT
90+
91+
- name: Setup Rust toolchain
92+
uses: dtolnay/rust-toolchain@master
93+
with:
94+
toolchain: nightly
95+
components: rustfmt
96+
97+
- name: Check formatting
98+
run: |
99+
cargo +nightly fmt --all -- --check
100+
101+
- name: Spell Check Repo
102+
uses: crate-ci/typos@v1.43.4
103+
env:
104+
CLICOLOR: 1
105+
106+
compile:
107+
needs: prepare
108+
name: ${{ matrix.release-name || matrix.target || 'Unknown' }}
109+
permissions:
110+
contents: write
111+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
112+
strategy:
113+
fail-fast: false
114+
matrix:
115+
include: ${{ fromJSON(needs.prepare.outputs.target_config) }}
116+
117+
steps:
118+
#--------------------------------------------------
119+
# Setup Steps
120+
#--------------------------------------------------
121+
- name: Checkout code
122+
uses: actions/checkout@v6
123+
with:
124+
submodules: true
125+
fetch-depth: 1
126+
127+
- name: Run sccache-cache
128+
uses: mozilla-actions/sccache-action@v0.0.9
129+
130+
- name: Setup SCCache
131+
run: |
132+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
133+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
134+
135+
- name: Setup Rust cache
136+
uses: Swatinem/rust-cache@v2
137+
with:
138+
shared-key: ${{ inputs.cache-key-prefix }}-${{ matrix.release-name || matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
139+
cache-directories: |
140+
~/.cargo/registry/index/
141+
~/.cargo/registry/cache/
142+
~/.cargo/git/db/
143+
target/
144+
145+
- name: Setup Rust toolchain
146+
uses: dtolnay/rust-toolchain@master
147+
with:
148+
toolchain: ${{ matrix.toolchain || inputs.rust-toolchain }}
149+
targets: ${{ matrix.build-std && 'x86_64-unknown-linux-gnu' || matrix.target }}
150+
components: ${{ matrix.components || matrix.build-std && 'rustfmt,clippy,rust-src' || 'rustfmt, clippy' }}
151+
152+
- name: Install cross-compilation tools
153+
if: matrix.tool == 'cross'
154+
run: |
155+
if [ "${{ matrix.build-std }}" != "true" ]; then
156+
rustup target add ${TARGET}
157+
fi
158+
cargo install cross --git https://github.com/cross-rs/cross --force
159+
env:
160+
TARGET: ${{ matrix.target }}
161+
162+
- name: Install NASM
163+
if: matrix.nasm == true
164+
uses: ilammy/setup-nasm@v1
165+
166+
- name: Print build information
167+
run: |
168+
echo "Building for target: ${{ matrix.target }}"
169+
echo "Using toolchain: ${{ matrix.toolchain || inputs.rust-toolchain }}"
170+
echo "Building packages: ${{ inputs.packages }}"
171+
172+
#--------------------------------------------------
173+
# Code Quality Steps
174+
#--------------------------------------------------
175+
176+
- name: Run linter
177+
uses: clechasseur/rs-cargo@v4
178+
with:
179+
tool: ${{ matrix.tool }}
180+
command: clippy
181+
args: --all --target ${{ matrix.target }} ${{ matrix.build-std && '-Z build-std=std,panic_abort' || '' }} ${{ matrix.extra-args }} -- -D warnings
182+
env:
183+
RUSTFLAGS: ${{ matrix.rustflags }} ${{ inputs.rustflags }}
184+
185+
#--------------------------------------------------
186+
# Build & Test Steps
187+
#--------------------------------------------------
188+
- name: Run tests
189+
uses: clechasseur/rs-cargo@v4
190+
if: ${{ inputs.run-tests != false && !matrix.skip-test }}
191+
with:
192+
tool: ${{ matrix.tool }}
193+
command: test
194+
args: --all --target ${{ matrix.target }} ${{ matrix.build-std && '-Z build-std=std,panic_abort' || '' }} ${{ matrix.extra-args }} -- --nocapture
195+
env:
196+
CROSS_CONTAINER_OPTS: "--network host"
197+
RUSTFLAGS: ${{ matrix.rustflags }} ${{ inputs.rustflags }}
198+
199+
- name: Build release binaries
200+
id: build
201+
uses: clechasseur/rs-cargo@v4
202+
with:
203+
tool: ${{ matrix.tool }}
204+
command: build
205+
args: --workspace --release --target ${{ matrix.target }} ${{ matrix.build-std && '-Z build-std=std,panic_abort' || '' }} ${{ matrix.extra-args }}
206+
env:
207+
RUSTFLAGS: ${{ matrix.rustflags }} ${{ inputs.rustflags }}
208+
CROSS_BUILD_ZIG: ${{ matrix.zig }}
209+
210+
#--------------------------------------------------
211+
# Artifact Steps
212+
#--------------------------------------------------
213+
- name: Prepare binary artifacts
214+
shell: bash
215+
id: prepare-artifacts
216+
run: |
217+
mkdir -p artifacts
218+
IFS=',' read -ra PACKAGES <<< "${{ inputs.packages }}"
219+
for package in "${PACKAGES[@]}"; do
220+
source_file="target/${{ matrix.target }}/release/${package}${{ matrix.postfix }}"
221+
target_file="artifacts/${package}-${{ matrix.release-name || matrix.target }}${{ matrix.postfix }}"
222+
cp "$source_file" "$target_file"
223+
done
224+
225+
- name: Upload binary artifacts
226+
uses: actions/upload-artifact@v6
227+
with:
228+
name: ${{ matrix.release-name || matrix.target }}-binaries
229+
path: artifacts/
230+
if-no-files-found: error
231+
retention-days: ${{ matrix.retention-days || 3 }}

0 commit comments

Comments
 (0)