|
1 | 1 | name: Build |
2 | 2 |
|
3 | | -on: [push] |
| 3 | +on: [push, pull_request] |
4 | 4 |
|
5 | 5 | jobs: |
6 | 6 | build: |
7 | | - runs-on: ubuntu-latest |
| 7 | + name: Build - ${{ matrix.os }} (${{ matrix.arch }}) |
| 8 | + runs-on: ${{ matrix.runner }} |
| 9 | + strategy: |
| 10 | + matrix: |
| 11 | + include: |
| 12 | + - os: linux |
| 13 | + arch: x86_64 |
| 14 | + runner: ubuntu-latest |
| 15 | + target: x86_64-unknown-linux-gnu |
| 16 | + - os: linux |
| 17 | + arch: aarch64 |
| 18 | + runner: ubuntu-latest |
| 19 | + target: aarch64-unknown-linux-gnu |
| 20 | + - os: windows |
| 21 | + arch: x86_64 |
| 22 | + runner: windows-latest |
| 23 | + target: x86_64-pc-windows-msvc |
| 24 | + - os: windows |
| 25 | + arch: aarch64 |
| 26 | + runner: windows-latest |
| 27 | + target: aarch64-pc-windows-msvc |
| 28 | + - os: macos |
| 29 | + arch: x86_64 |
| 30 | + runner: macos-latest |
| 31 | + target: x86_64-apple-darwin |
| 32 | + - os: macos |
| 33 | + arch: aarch64 |
| 34 | + runner: macos-latest |
| 35 | + target: aarch64-apple-darwin |
8 | 36 |
|
9 | 37 | steps: |
10 | 38 | - name: Checkout Source |
11 | | - id: checkout-source |
12 | | - uses: actions/checkout@v2 |
13 | | - - name: Set variables |
14 | | - id: vars |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Install Rust toolchain |
| 42 | + uses: dtolnay/rust-toolchain@stable |
| 43 | + with: |
| 44 | + targets: ${{ matrix.target }} |
| 45 | + |
| 46 | + - name: Install cross-compilation tools (Linux ARM64) |
| 47 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 48 | + run: | |
| 49 | + sudo apt-get update |
| 50 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 51 | +
|
| 52 | + - name: Configure cross-compilation (Linux ARM64) |
| 53 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
15 | 54 | run: | |
16 | | - echo "::set-output name=package_name::$(sed -En 's/name[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1)" |
17 | | - echo "::set-output name=package_version::$(sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1)" |
18 | | - - run: | |
19 | | - echo "${{steps.vars.outputs.package_name}}" |
20 | | - echo "${{steps.vars.outputs.package_version}}" |
21 | | - - uses: actions/cache@v4.2.0 |
| 55 | + echo "[target.aarch64-unknown-linux-gnu]" >> ~/.cargo/config.toml |
| 56 | + echo "linker = \"aarch64-linux-gnu-gcc\"" >> ~/.cargo/config.toml |
| 57 | +
|
| 58 | + - name: Cache cargo registry and build |
| 59 | + uses: actions/cache@v4 |
22 | 60 | with: |
23 | 61 | path: | |
24 | 62 | ~/.cargo/registry |
25 | 63 | ~/.cargo/git |
26 | 64 | target |
27 | | - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 65 | + key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-${{ matrix.target }}-cargo- |
28 | 68 |
|
29 | 69 | - name: Build |
30 | | - id: build-release |
31 | | - run: cargo build --release |
32 | | - |
33 | | - - name: Zip release |
34 | | - id: zip-release |
35 | | - run: zip -j build.zip target/release/ci |
36 | | - |
37 | | - - name: Artifact Production |
38 | | - id: create-artifact |
39 | | - uses: actions/upload-artifact@v4 |
40 | | - with: |
41 | | - name: build |
42 | | - path: build.zip |
43 | | - |
44 | | - - name: Remove Same Release |
45 | | - uses: omarabid-forks/action-rollback@stable |
46 | | - continue-on-error: true |
47 | | - with: |
48 | | - tag: ${{ steps.vars.outputs.package_version }} |
49 | | - env: |
50 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
51 | | - |
52 | | - - name: Create Release |
53 | | - id: create-release |
54 | | - uses: actions/create-release@latest |
55 | | - env: |
56 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
57 | | - with: |
58 | | - tag_name: ${{steps.vars.outputs.package_version}} |
59 | | - release_name: Version ${{steps.vars.outputs.package_version}} |
60 | | - body: ${{steps.vars.outputs.package_name}} - ${{steps.vars.outputs.package_version}} |
61 | | - draft: false |
62 | | - prerelease: false |
63 | | - |
64 | | - - name: Upload Artifact |
65 | | - id: upload-release-asset |
66 | | - uses: actions/upload-release-asset@v1 |
67 | | - env: |
68 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
69 | | - with: |
70 | | - upload_url: ${{ steps.create-release.outputs.upload_url }} |
71 | | - asset_path: build.zip |
72 | | - asset_name: build.zip |
73 | | - asset_content_type: application/zip |
74 | | - |
75 | | - - uses: omarabid-forks/purge-artifacts@v1 |
76 | | - with: |
77 | | - token: ${{ secrets.GITHUB_TOKEN }} |
78 | | - expire-in: 0 |
| 70 | + run: cargo build --release --target ${{ matrix.target }} |
0 commit comments