Skip to content

Commit e614278

Browse files
committed
refactor: improve workflow with caching, linting and testing
1 parent e1fdfb6 commit e614278

1 file changed

Lines changed: 145 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 145 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,71 @@ on:
55
push:
66
paths-ignore:
77
- '**.md'
8-
- '**.yaml'
9-
- '**.yml'
8+
# - '**.yaml'
9+
# - '**.yml'
1010

1111
permissions:
1212
contents: write
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
1418
env:
1519
EXTENSION_NAME: fluent
1620

1721
jobs:
22+
lint:
23+
runs-on: ubuntu-22.04
24+
strategy:
25+
matrix:
26+
clang: [ "16" ]
27+
target: [ "x86_64-unknown-linux-gnu" ]
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: recursive
33+
34+
- name: Cache LLVM and Clang
35+
id: cache-llvm
36+
uses: actions/cache@v4
37+
with:
38+
path: ${{ runner.temp }}/llvm-${{ matrix.clang }}
39+
key: llvm-${{ matrix.clang }}-${{ runner.os }}
40+
41+
- name: Setup LLVM & Clang
42+
id: clang
43+
uses: KyleMayes/install-llvm-action@v2
44+
with:
45+
version: ${{ matrix.clang }}
46+
directory: ${{ runner.temp }}/llvm-${{ matrix.clang }}
47+
cached: ${{ steps.cache-llvm.outputs.cache-hit }}
48+
49+
- name: Configure Clang
50+
run: |
51+
echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/lib" >> $GITHUB_ENV
52+
echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV
53+
echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/bin/llvm-config" >> $GITHUB_ENV
54+
55+
- name: Install Rust toolchain
56+
uses: dtolnay/rust-toolchain@master
57+
with:
58+
toolchain: stable
59+
components: rustfmt, clippy
60+
targets: ${{ matrix.target }}
61+
62+
- name: Cache Rust
63+
uses: Swatinem/rust-cache@v2
64+
with:
65+
key: lint-${{ matrix.target }}
66+
67+
- name: Check formatting
68+
run: cargo fmt --all -- --check
69+
70+
- name: Clippy
71+
run: cargo clippy --target ${{ matrix.target }} --all-targets -- -D warnings
72+
1873
tests:
1974
runs-on: ubuntu-22.04
2075
strategy:
@@ -29,18 +84,12 @@ jobs:
2984
with:
3085
submodules: recursive
3186

32-
- name: Cache cargo and LLVM and Clang
87+
- name: Cache LLVM and Clang
3388
id: cache-llvm
3489
uses: actions/cache@v4
3590
with:
36-
path: |
37-
~/.cargo/bin/
38-
~/.cargo/registry/index/
39-
~/.cargo/registry/cache/
40-
~/.cargo/git/db/
41-
target/
42-
${{ runner.temp }}/llvm-${{ matrix.clang }}
43-
key: ${{ matrix.php-version }}-test
91+
path: ${{ runner.temp }}/llvm-${{ matrix.clang }}
92+
key: llvm-${{ matrix.clang }}-${{ runner.os }}
4493

4594
- name: Setup LLVM & Clang
4695
id: clang
@@ -62,24 +111,27 @@ jobs:
62111
php-version: ${{ matrix.php-version }}
63112
tools: php-config
64113

65-
- name: Install latest Rust toolchain
66-
run: |
67-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
68-
source $HOME/.cargo/env
69-
rustup default stable
70-
rustup target add ${{ matrix.target }}
114+
- name: Install Rust toolchain
115+
uses: dtolnay/rust-toolchain@master
116+
with:
117+
toolchain: stable
118+
targets: ${{ matrix.target }}
119+
120+
- name: Cache Rust
121+
uses: Swatinem/rust-cache@v2
122+
with:
123+
key: ${{ matrix.target }}-${{ matrix.php-version }}
71124

72125
- name: Build module
73126
run: |
74127
cargo build --target ${{ matrix.target }} --lib
75128
cargo test --target ${{ matrix.target }}
76129
77-
- name: Run PHP Test
78-
run: NO_INTERACTION=1 php run-tests.php -n -d extension=target/${{ matrix.target }}/debug/libfluent.so
79-
80130
build:
81131
runs-on: ${{ matrix.os }}
82-
needs: tests
132+
needs:
133+
- tests
134+
- lint
83135
strategy:
84136
matrix:
85137
clang: [ "16" ]
@@ -91,7 +143,7 @@ jobs:
91143
- { target: x86_64-pc-windows-msvc, rust_channel: nightly }
92144
- { target: x86_64-pc-windows-msvc, os: windows-latest }
93145
- { target: aarch64-apple-darwin, os: macos-latest }
94-
- { target: x86_64-apple-darwin, os: macos-latest }
146+
- { target: x86_64-apple-darwin, os: macos-13 }
95147
- { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
96148
- { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04 }
97149
exclude:
@@ -106,18 +158,12 @@ jobs:
106158
with:
107159
submodules: recursive
108160

109-
- name: Cache cargo and LLVM and Clang
161+
- name: Cache LLVM and Clang
110162
id: cache-llvm
111163
uses: actions/cache@v4
112164
with:
113-
path: |
114-
~/.cargo/bin/
115-
~/.cargo/registry/index/
116-
~/.cargo/registry/cache/
117-
~/.cargo/git/db/
118-
target/
119-
${{ runner.temp }}/llvm-${{ matrix.clang }}
120-
key: ${{ matrix.php-version }}-test
165+
path: ${{ runner.temp }}/llvm-${{ matrix.clang }}
166+
key: llvm-${{ matrix.clang }}-${{ runner.os }}
121167

122168
- name: Setup LLVM & Clang
123169
id: clang
@@ -135,13 +181,23 @@ jobs:
135181
echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV
136182
echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/bin/llvm-config" >> $GITHUB_ENV
137183
138-
- name: Install latest Rust toolchain
139-
run: |
140-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
141-
#source $HOME/.cargo/env
142-
rustup default ${{ matrix.rust_channel }}
143-
rustup target add ${{ matrix.target }}
184+
- name: Install Rust toolchain
185+
uses: dtolnay/rust-toolchain@master
186+
with:
187+
targets: ${{ matrix.target }}
188+
toolchain: ${{ matrix.rust_channel }}
189+
190+
- name: Cache Rust
191+
uses: Swatinem/rust-cache@v2
192+
with:
193+
key: ${{ matrix.target }}-${{ matrix.php-version }}
194+
195+
- name: Force rebuild of PHP-linked crate to prevent ts/nts conflict
196+
if: runner.os == 'Windows'
144197
shell: bash
198+
run: |
199+
cargo clean -p ext-php-rs
200+
rm -rf target/*/build/ext-php-rs-* 2>/dev/null || true
145201
146202
- name: Setup PHP with PECL extension
147203
uses: shivammathur/setup-php@v2
@@ -184,9 +240,60 @@ jobs:
184240
name: php${{ matrix.php-version }}-${{ matrix.phpts }}-${{ matrix.target }}
185241
path: target/php${{ matrix.php-version }}-${{ matrix.phpts }}-${{ matrix.target }}-${{ env.EXTENSION_NAME }}.${{ env.LIB_EXT }}
186242

243+
integration:
244+
runs-on: ${{ matrix.os }}
245+
needs: build
246+
strategy:
247+
fail-fast: false
248+
matrix:
249+
php-version: [ "8.2", "8.3", "8.4", "8.5" ]
250+
target: [ x86_64-pc-windows-msvc, aarch64-apple-darwin, x86_64-apple-darwin, x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu ]
251+
phpts: [ "nts", "ts" ]
252+
include:
253+
- { target: x86_64-pc-windows-msvc, os: windows-latest }
254+
- { target: aarch64-apple-darwin, os: macos-latest }
255+
- { target: x86_64-apple-darwin, os: macos-13 }
256+
- { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
257+
exclude:
258+
- { target: aarch64-apple-darwin, phpts: ts }
259+
- { target: x86_64-apple-darwin, phpts: ts }
260+
- { target: x86_64-unknown-linux-gnu, phpts: ts }
261+
- { target: aarch64-unknown-linux-gnu, phpts: ts }
262+
- { target: aarch64-unknown-linux-gnu } # build-only: no native arm64 Linux runner
263+
steps:
264+
- name: Checkout
265+
uses: actions/checkout@v4
266+
with:
267+
submodules: recursive
268+
269+
- name: Setup PHP
270+
uses: shivammathur/setup-php@v2
271+
with:
272+
php-version: ${{ matrix.php-version }}
273+
env:
274+
phpts: ${{ matrix.phpts }}
275+
276+
- name: Download built extension
277+
uses: actions/download-artifact@v4
278+
with:
279+
name: php${{ matrix.php-version }}-${{ matrix.phpts }}-${{ matrix.target }}
280+
path: ./dist
281+
282+
- name: Run PHP Test
283+
shell: bash
284+
run: |
285+
set -x
286+
EXT=$(find ./dist -maxdepth 1 -type f \( -name '*.so' -o -name '*.dll' \) | head -n1)
287+
if [ -z "$EXT" ]; then
288+
echo "::error::No built extension found in ./dist"
289+
exit 1
290+
fi
291+
php -d extension="$EXT" -m
292+
NO_INTERACTION=1 php run-tests.php -n -d extension="$EXT"
293+
187294
release:
188295
runs-on: ubuntu-22.04
189-
needs: build
296+
needs: integration
190297
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
191298

192299
steps:

0 commit comments

Comments
 (0)