|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + paths-ignore: |
| 7 | + - "*.md" |
| 8 | + - "LICENSE*" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + # For npm publish provenance |
| 13 | + id-token: write |
| 14 | + |
| 15 | +env: |
| 16 | + BUILD_PROFILE: release-lto |
| 17 | + CARGO_INCREMENTAL: 0 |
| 18 | + |
| 19 | +jobs: |
| 20 | + check: |
| 21 | + name: Check |
| 22 | + runs-on: ubuntu-latest |
| 23 | + env: |
| 24 | + RUSTFLAGS: -D warnings |
| 25 | + steps: |
| 26 | + - name: Install dependencies |
| 27 | + run: | |
| 28 | + sudo apt-get update |
| 29 | + sudo apt-get -y install libgtk-3-dev |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v6 |
| 32 | + - name: Setup Rust toolchain |
| 33 | + uses: dtolnay/rust-toolchain@stable |
| 34 | + with: |
| 35 | + components: clippy |
| 36 | + - name: Cache Rust workspace |
| 37 | + uses: Swatinem/rust-cache@v2 |
| 38 | + - name: Cargo check |
| 39 | + run: cargo check --all-targets --all-features --workspace |
| 40 | + - name: Cargo clippy |
| 41 | + run: cargo clippy --all-targets --all-features --workspace |
| 42 | + |
| 43 | + fmt: |
| 44 | + name: Format |
| 45 | + runs-on: ubuntu-latest |
| 46 | + env: |
| 47 | + RUSTFLAGS: -D warnings |
| 48 | + steps: |
| 49 | + - name: Checkout |
| 50 | + uses: actions/checkout@v6 |
| 51 | + - name: Setup Rust toolchain |
| 52 | + # We use nightly options in rustfmt.toml |
| 53 | + uses: dtolnay/rust-toolchain@nightly |
| 54 | + with: |
| 55 | + components: rustfmt |
| 56 | + - name: Cargo fmt |
| 57 | + run: cargo fmt --all --check |
| 58 | + |
| 59 | + deny: |
| 60 | + name: Deny |
| 61 | + runs-on: ubuntu-latest |
| 62 | + strategy: |
| 63 | + matrix: |
| 64 | + checks: |
| 65 | + # - advisories |
| 66 | + - bans licenses sources |
| 67 | + # Prevent new advisories from failing CI |
| 68 | + continue-on-error: ${{ matrix.checks == 'advisories' }} |
| 69 | + steps: |
| 70 | + - uses: actions/checkout@v6 |
| 71 | + - uses: EmbarkStudios/cargo-deny-action@v2 |
| 72 | + with: |
| 73 | + command: check ${{ matrix.checks }} |
| 74 | + |
| 75 | + test: |
| 76 | + name: Test |
| 77 | + strategy: |
| 78 | + matrix: |
| 79 | + platform: [ ubuntu-latest, windows-latest, macos-latest ] |
| 80 | + fail-fast: false |
| 81 | + runs-on: ${{ matrix.platform }} |
| 82 | + steps: |
| 83 | + - name: Install dependencies |
| 84 | + if: matrix.platform == 'ubuntu-latest' |
| 85 | + run: | |
| 86 | + sudo apt-get update |
| 87 | + sudo apt-get -y install libgtk-3-dev |
| 88 | + - name: Checkout |
| 89 | + uses: actions/checkout@v6 |
| 90 | + - name: Setup Rust toolchain |
| 91 | + uses: dtolnay/rust-toolchain@stable |
| 92 | + - name: Cache Rust workspace |
| 93 | + uses: Swatinem/rust-cache@v2 |
| 94 | + - name: Cargo test |
| 95 | + run: cargo test --release --all-features --workspace |
| 96 | + |
| 97 | + build: |
| 98 | + name: Build delink |
| 99 | + env: |
| 100 | + CARGO_BIN_NAME: delink |
| 101 | + strategy: |
| 102 | + matrix: |
| 103 | + include: |
| 104 | + - platform: ubuntu-latest |
| 105 | + target: x86_64-unknown-linux-gnu.2.31 |
| 106 | + target_base: x86_64-unknown-linux-gnu |
| 107 | + name: linux-x86_64 |
| 108 | + packages: libgtk-3-dev |
| 109 | + build: zigbuild |
| 110 | + - platform: windows-latest |
| 111 | + target: x86_64-pc-windows-msvc |
| 112 | + name: windows-x86_64 |
| 113 | + build: build |
| 114 | + - platform: macos-latest |
| 115 | + target: x86_64-apple-darwin |
| 116 | + name: macos-x86_64 |
| 117 | + build: build |
| 118 | + - platform: macos-latest |
| 119 | + target: aarch64-apple-darwin |
| 120 | + name: macos-arm64 |
| 121 | + build: build |
| 122 | + fail-fast: false |
| 123 | + runs-on: ${{ matrix.platform }} |
| 124 | + steps: |
| 125 | + - name: Install dependencies |
| 126 | + if: matrix.packages != '' |
| 127 | + run: | |
| 128 | + sudo apt-get update |
| 129 | + sudo apt-get -y install ${{ matrix.packages }} |
| 130 | + - name: Checkout |
| 131 | + uses: actions/checkout@v6 |
| 132 | + - name: Install uv |
| 133 | + if: matrix.build == 'zigbuild' |
| 134 | + uses: astral-sh/setup-uv@v7 |
| 135 | + - name: Install cargo-zigbuild |
| 136 | + if: matrix.build == 'zigbuild' |
| 137 | + run: | |
| 138 | + uv tool install cargo-zigbuild==0.20.1 --with-executables-from ziglang==0.15.1 |
| 139 | + echo "CARGO_ZIGBUILD_ZIG_PATH=$(uv tool dir)/cargo-zigbuild/bin/python-zig" >> $GITHUB_ENV |
| 140 | + - name: Setup Rust toolchain |
| 141 | + uses: dtolnay/rust-toolchain@stable |
| 142 | + with: |
| 143 | + targets: ${{ matrix.target_base || matrix.target }} |
| 144 | + - name: Cache Rust workspace |
| 145 | + uses: Swatinem/rust-cache@v2 |
| 146 | + with: |
| 147 | + key: ${{ matrix.target }} |
| 148 | + - name: Cargo build |
| 149 | + run: > |
| 150 | + cargo ${{ matrix.build }} --profile ${{ env.BUILD_PROFILE }} --target ${{ matrix.target }} --bin ${{ env.CARGO_BIN_NAME }} |
| 151 | + - name: Upload artifacts |
| 152 | + uses: actions/upload-artifact@v7 |
| 153 | + with: |
| 154 | + name: ${{ env.CARGO_BIN_NAME }}-${{ matrix.name }} |
| 155 | + path: | |
| 156 | + target/${{ matrix.target_base || matrix.target }}/${{ env.BUILD_PROFILE }}/${{ env.CARGO_BIN_NAME }} |
| 157 | + target/${{ matrix.target_base || matrix.target }}/${{ env.BUILD_PROFILE }}/${{ env.CARGO_BIN_NAME }}.exe |
| 158 | + if-no-files-found: error |
| 159 | + |
| 160 | + check-version: |
| 161 | + name: Check package versions |
| 162 | + if: startsWith(github.ref, 'refs/tags/') |
| 163 | + runs-on: ubuntu-latest |
| 164 | + needs: [ build ] |
| 165 | + steps: |
| 166 | + - name: Checkout |
| 167 | + uses: actions/checkout@v6 |
| 168 | + - name: Check git tag against package versions |
| 169 | + shell: bash |
| 170 | + run: | |
| 171 | + set -eou pipefail |
| 172 | + tag='${{github.ref}}' |
| 173 | + tag="${tag#refs/tags/}" |
| 174 | + version=$(grep '^version' Cargo.toml | head -1 | awk -F' = ' '{print $2}' | tr -d '"') |
| 175 | + version="v$version" |
| 176 | + if [ "$tag" != "$version" ]; then |
| 177 | + echo "::error::Git tag doesn't match the Cargo version! ($tag != $version)" |
| 178 | + exit 1 |
| 179 | + fi |
| 180 | +
|
| 181 | + release-github: |
| 182 | + name: Release (GitHub) |
| 183 | + if: startsWith(github.ref, 'refs/tags/') |
| 184 | + runs-on: ubuntu-latest |
| 185 | + needs: [ check-version ] |
| 186 | + permissions: |
| 187 | + contents: write |
| 188 | + steps: |
| 189 | + - name: Download artifacts |
| 190 | + uses: actions/download-artifact@v4 |
| 191 | + with: |
| 192 | + pattern: delink-* |
| 193 | + path: artifacts |
| 194 | + - name: Rename artifacts |
| 195 | + working-directory: artifacts |
| 196 | + run: | |
| 197 | + set -euo pipefail |
| 198 | + mkdir ../out |
| 199 | + for dir in */; do |
| 200 | + for file in "$dir"*; do |
| 201 | + base=$(basename "$file") |
| 202 | + name="${base%.*}" |
| 203 | + ext="${base##*.}" |
| 204 | + if [ "$ext" = "$base" ]; then |
| 205 | + ext="" |
| 206 | + else |
| 207 | + ext=".$ext" |
| 208 | + fi |
| 209 | + arch="${dir%/}" # remove trailing slash |
| 210 | + arch="${arch##"$name-"}" # remove bin name |
| 211 | + dst="../out/${name}-${arch}${ext}" |
| 212 | + mv "$file" "$dst" |
| 213 | + done |
| 214 | + done |
| 215 | + ls -R ../out |
| 216 | + - name: Release |
| 217 | + uses: softprops/action-gh-release@v2 |
| 218 | + with: |
| 219 | + files: out/* |
| 220 | + draft: true |
| 221 | + generate_release_notes: true |
0 commit comments