Skip to content

Commit 0d46781

Browse files
committed
refactor: split CI into separate build, checks, and deploy workflows
1 parent 35b9312 commit 0d46781

7 files changed

Lines changed: 203 additions & 183 deletions

File tree

.github/workflows/build.yaml

Lines changed: 69 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,62 @@
1-
name: Build
1+
name: Builds
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
411

512
permissions:
6-
contents: write
13+
contents: read
714

815
jobs:
9-
wasm:
10-
runs-on: ubuntu-latest
16+
build:
17+
name: Build (${{ matrix.target }})
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- os: ubuntu-latest
23+
target: x86_64-unknown-linux-gnu
24+
artifact_name: spiritus
25+
sdl2_install: sudo apt-get install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libsdl2-gfx-dev
26+
- os: macos-15
27+
target: aarch64-apple-darwin
28+
artifact_name: spiritus
29+
sdl2_install: brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf sdl2_gfx
30+
- os: windows-latest
31+
target: x86_64-pc-windows-gnu
32+
artifact_name: spiritus.exe
33+
sdl2_install: ""
34+
runs-on: ${{ matrix.os }}
1135

12-
permissions:
13-
pages: write
14-
id-token: write
15-
16-
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v4
19-
20-
- name: Setup Emscripten SDK
21-
uses: mymindstorm/setup-emsdk@v14
22-
with:
23-
version: 3.1.43
24-
25-
- name: Setup Rust (WASM32 Emscripten)
26-
uses: dtolnay/rust-toolchain@stable
27-
with:
28-
target: wasm32-unknown-emscripten
29-
30-
- name: Rust Cache
31-
uses: Swatinem/rust-cache@v2
32-
33-
- name: Install pnpm
34-
uses: pnpm/action-setup@v3
35-
with:
36-
version: 8
37-
run_install: true
38-
39-
- name: Build
40-
run: ./scripts/build.sh -er # release mode, skip emsdk
41-
42-
- name: Upload Artifact
43-
uses: actions/upload-pages-artifact@v3
44-
with:
45-
path: './dist/'
46-
retention-days: 7
47-
48-
- name: Deploy
49-
uses: actions/deploy-pages@v4
50-
51-
linux:
52-
runs-on: ubuntu-latest
53-
env:
54-
TARGET: x86_64-unknown-linux-gnu
55-
56-
steps:
57-
- name: Checkout
58-
uses: actions/checkout@v4
59-
60-
- name: Install SDL2 Packages
61-
run: sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libsdl2-gfx-dev
62-
63-
- name: Setup Rust Toolchain (Linux)
64-
uses: dtolnay/rust-toolchain@stable
65-
with:
66-
target: ${{ env.TARGET }}
67-
68-
- name: Rust Cache
69-
uses: Swatinem/rust-cache@v2
70-
71-
- name: Build
72-
run: cargo build --release
73-
74-
- name: Assemble Archive
75-
run: |
76-
mkdir /tmp/example/
77-
cp ./target/release/spiritus /tmp/example/
78-
chmod a+x /tmp/example/spiritus
79-
mkdir /tmp/example/assets
80-
cp ./assets/TerminalVector.ttf ./assets/fruit.png /tmp/example/assets
81-
82-
- name: Install Cargo Binstall
83-
uses: cargo-bins/cargo-binstall@main
84-
85-
- name: Acquire Package Version
86-
run: |
87-
cargo binstall toml-cli -y
88-
echo "PACKAGE_VERSION=$(toml get ./Cargo.toml package.version --raw)" >> $GITHUB_ENV
89-
90-
- name: Upload Artifact
91-
uses: actions/upload-artifact@v4
92-
with:
93-
name: "spiritus-${{ env.PACKAGE_VERSION }}-${{ env.TARGET }}"
94-
path: /tmp/example/
95-
retention-days: 7
96-
if-no-files-found: error
97-
98-
macos:
99-
runs-on: macos-13
10036
env:
101-
TARGET: x86_64-apple-darwin
102-
103-
steps:
104-
- name: Checkout
105-
uses: actions/checkout@v4
106-
107-
- name: Install SDL2 Packages
108-
run: brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf sdl2_gfx
109-
110-
- name: Setup Rust Toolchain (MacOS)
111-
uses: dtolnay/rust-toolchain@stable
112-
with:
113-
target: ${{ env.TARGET }}
114-
115-
- name: Rust Cache
116-
uses: Swatinem/rust-cache@v2
117-
118-
- name: Build
119-
run: cargo build --release
120-
121-
- name: Assemble Archive
122-
run: |
123-
mkdir /tmp/example/
124-
cp ./target/release/spiritus /tmp/example/
125-
mkdir /tmp/example/assets
126-
cp ./assets/TerminalVector.ttf ./assets/fruit.png /tmp/example/assets
127-
128-
- name: Install Cargo Binstall
129-
uses: cargo-bins/cargo-binstall@main
130-
131-
- name: Acquire Package Version
132-
run: |
133-
cargo binstall toml-cli -y
134-
echo "PACKAGE_VERSION=$(toml get ./Cargo.toml package.version --raw)" >> $GITHUB_ENV
135-
136-
- name: Upload Artifact
137-
uses: actions/upload-artifact@v4
138-
with:
139-
name: "spiritus-${{ env.PACKAGE_VERSION }}-${{ env.TARGET }}"
140-
path: /tmp/example/
141-
retention-days: 7
142-
if-no-files-found: error
143-
144-
windows:
145-
env:
146-
TARGET: x86_64-pc-windows-gnu
14737
SDL2: 2.30.2
14838
SDL2_TTF: 2.22.0
14939
SDL2_MIXER: 2.8.0
15040
SDL2_IMAGE: 2.8.2
151-
# SDL2_GFX: 1.0.4
152-
runs-on: windows-latest
15341

15442
steps:
155-
- name: Checkout
43+
- name: Checkout
15644
uses: actions/checkout@v4
15745

158-
- name: Download SDL2 Libraries
46+
- name: Install SDL2 packages (apt/brew)
47+
if: matrix.sdl2_install != ''
48+
run: ${{ matrix.sdl2_install }}
49+
50+
- name: Download SDL2 libraries (Windows)
51+
if: runner.os == 'Windows'
15952
run: |
16053
curl -L "https://github.com/libsdl-org/SDL/releases/download/release-${{ env.SDL2 }}/SDL2-devel-${{ env.SDL2 }}-VC.zip" -o "sdl2_devel.zip"
16154
curl -L "https://github.com/libsdl-org/SDL_mixer/releases/download/release-${{ env.SDL2_MIXER }}/SDL2_mixer-devel-${{ env.SDL2_MIXER }}-VC.zip" -o "sdl2_mixer_devel.zip"
16255
curl -L "https://github.com/libsdl-org/SDL_ttf/releases/download/release-${{ env.SDL2_TTF }}/SDL2_ttf-devel-${{ env.SDL2_TTF }}-VC.zip" -o "sdl2_ttf_devel.zip"
16356
curl -L "https://github.com/libsdl-org/SDL_image/releases/download/release-${{ env.SDL2_IMAGE }}/SDL2_image-devel-${{ env.SDL2_IMAGE }}-VC.zip" -o "sdl2_image_devel.zip"
164-
165-
- name: Extract SDL2 DLLs
57+
58+
- name: Extract SDL2 DLLs (Windows)
59+
if: runner.os == 'Windows'
16660
run: |
16761
7z x ./sdl2_devel.zip -o"./tmp/"
16862
mv ./tmp/SDL2-${{ env.SDL2 }}/lib/x64/SDL2.dll ./
@@ -179,45 +73,53 @@ jobs:
17973
7z x ./sdl2_image_devel.zip -o"./tmp/"
18074
mv ./tmp/SDL2_image-${{ env.SDL2_IMAGE }}/lib/x64/SDL2_image.dll ./
18175
mv ./tmp/SDL2_image-${{ env.SDL2_IMAGE }}/lib/x64/SDL2_image.lib ./
182-
183-
- name: Install SDL2_gfx
76+
77+
- name: Install SDL2_gfx (Windows)
78+
if: runner.os == 'Windows'
18479
run: |
18580
C:\vcpkg\vcpkg.exe install sdl2-gfx:x64-windows-release
18681
cp C:\vcpkg\packages\sdl2-gfx_x64-windows-release\bin\SDL2_gfx.dll ./
18782
cp C:\vcpkg\packages\sdl2-gfx_x64-windows-release\lib\SDL2_gfx.lib ./
188-
189-
- name: Setup Rust (Windows)
190-
uses: dtolnay/rust-toolchain@stable
191-
with:
192-
targets: ${{ env.TARGET }}
83+
84+
- name: Install Rust toolchain
85+
uses: mkroening/rust-toolchain-toml@main
86+
87+
- name: Add target
88+
run: rustup target add ${{ matrix.target }}
19389

19490
- name: Rust Cache
19591
uses: Swatinem/rust-cache@v2
19692

19793
- name: Build
19894
run: cargo build --release
19995

200-
- name: Prepare Archive
96+
- name: Acquire Package Version
97+
id: get_version
98+
shell: bash
20199
run: |
202-
New-Item -Type Directory ./release/
203-
Move-Item -Path ./target/release/spiritus.exe -Destination ./release/
204-
Move-Item -Path ./SDL2.dll, ./SDL2_image.dll, ./SDL2_ttf.dll, ./SDL2_mixer.dll, ./SDL2_gfx.dll -Destination ./release/
205-
New-Item -Type Directory ./release/assets/
206-
Move-Item -Path ./assets/TerminalVector.ttf, ./assets/fruit.png -Destination ./release/assets/
100+
set -euo pipefail
101+
echo "version=$(cargo metadata --format-version 1 --no-deps | jq '.packages[0].version' -r)" >> $GITHUB_OUTPUT
207102
208-
- name: Install Cargo Binstall
209-
uses: cargo-bins/cargo-binstall@main
210-
211-
- name: Acquire Package Version
103+
- name: Assemble archive (Unix)
104+
if: runner.os != 'Windows'
212105
run: |
213-
cargo binstall toml-cli -y
214-
echo "PACKAGE_VERSION=$(toml get ./Cargo.toml package.version --raw)" >> $env:GITHUB_ENV
106+
mkdir -p /tmp/spiritus/assets
107+
cp ./target/release/${{ matrix.artifact_name }} /tmp/spiritus/
108+
chmod a+x /tmp/spiritus/${{ matrix.artifact_name }}
109+
cp ./assets/TerminalVector.ttf ./assets/fruit.png /tmp/spiritus/assets
215110
111+
- name: Assemble archive (Windows)
112+
if: runner.os == 'Windows'
113+
run: |
114+
New-Item -Type Directory ./release/assets/
115+
Move-Item -Path ./target/release/${{ matrix.artifact_name }} -Destination ./release/
116+
Move-Item -Path ./SDL2.dll, ./SDL2_image.dll, ./SDL2_ttf.dll, ./SDL2_mixer.dll, ./SDL2_gfx.dll -Destination ./release/
117+
Move-Item -Path ./assets/TerminalVector.ttf, ./assets/fruit.png -Destination ./release/assets/
216118
217119
- name: Upload Artifact
218120
uses: actions/upload-artifact@v4
219121
with:
220-
name: "spiritus-${{ env.PACKAGE_VERSION }}-${{ env.TARGET }}"
221-
path: ./release/
122+
name: "spiritus-${{ steps.get_version.outputs.version }}-${{ matrix.target }}"
123+
path: ${{ runner.os == 'Windows' && './release/' || '/tmp/spiritus/' }}
222124
retention-days: 7
223-
if-no-files-found: error
125+
if-no-files-found: error

.github/workflows/checks.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Checks
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
15+
jobs:
16+
checks:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Install Rust toolchain
24+
uses: mkroening/rust-toolchain-toml@main
25+
26+
- name: Rust Cache
27+
uses: Swatinem/rust-cache@v2
28+
29+
- name: Install SDL2 packages
30+
run: sudo apt-get install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libsdl2-gfx-dev
31+
32+
- name: Run clippy
33+
run: cargo clippy --all-targets -- -D warnings
34+
35+
- name: Check formatting
36+
run: cargo fmt --all -- --check
37+
38+
- uses: taiki-e/install-action@cargo-audit
39+
40+
- name: Run security audit
41+
run: cargo audit

.github/workflows/deploy.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
permissions:
10+
pages: write
11+
id-token: write
12+
13+
jobs:
14+
wasm:
15+
name: Build WASM
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Emscripten SDK
23+
uses: mymindstorm/setup-emsdk@v14
24+
with:
25+
version: 3.1.74
26+
27+
- name: Pre-warm Emscripten port cache
28+
run: embuilder build sdl2 sdl2_ttf sdl2_image sdl2_mixer
29+
30+
- name: Install Rust toolchain
31+
uses: mkroening/rust-toolchain-toml@main
32+
33+
- name: Add wasm target
34+
run: rustup target add wasm32-unknown-emscripten
35+
36+
- name: Rust Cache
37+
uses: Swatinem/rust-cache@v2
38+
39+
- name: Install pnpm
40+
uses: pnpm/action-setup@v4
41+
with:
42+
run_install: true
43+
44+
- name: Build
45+
run: ./scripts/build.sh -er
46+
47+
- name: Upload Pages Artifact
48+
uses: actions/upload-pages-artifact@v3
49+
with:
50+
path: ./dist/
51+
retention-days: 7
52+
53+
deploy:
54+
name: Deploy to GitHub Pages
55+
runs-on: ubuntu-latest
56+
needs: wasm
57+
environment:
58+
name: github-pages
59+
url: ${{ steps.deployment.outputs.page_url }}
60+
61+
steps:
62+
- name: Deploy
63+
id: deployment
64+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)