|
5 | 5 | workflow_dispatch:
|
6 | 6 |
|
7 | 7 | jobs:
|
8 |
| - upload-to-registry: |
9 |
| - name: Upload plugin to the registry |
| 8 | + check-version: |
| 9 | + name: Check snforge_scarb_plugin Version |
10 | 10 | runs-on: ubuntu-latest
|
11 |
| - env: |
12 |
| - SCARB_REGISTRY_AUTH_TOKEN: ${{ secrets.SCARB_REGISTRY_AUTH_TOKEN }} |
| 11 | + outputs: |
| 12 | + plugin_uploaded: ${{ steps.check-version.outputs.plugin_uploaded }} |
13 | 13 | steps:
|
14 | 14 | - uses: actions/checkout@v4
|
15 |
| - |
16 | 15 | - name: Check version
|
17 | 16 | id: check-version
|
18 |
| - if: ${{ github.event_name != 'workflow_dispatch' }} |
19 | 17 | run: |
|
20 | 18 | set -exo pipefail
|
21 | 19 |
|
22 | 20 | snforge_scarb_plugin_version=$(grep version crates/snforge-scarb-plugin/Scarb.toml | cut -d '"' -f 2)
|
23 |
| - snforge_scarb_plugin_uploaded=$(curl -s https://scarbs.xyz/api/v1/index/sn/fo/snforge_scarb_plugin.json | jq --arg version "$snforge_scarb_plugin_version" '[.[] | select(.v == $version)] | length > 0') |
24 |
| - echo "snforge_scarb_plugin_uploaded=$snforge_scarb_plugin_uploaded" >> $GITHUB_OUTPUT |
| 21 | + plugin_uploaded=$(curl -s https://scarbs.xyz/api/v1/index/sn/fo/snforge_scarb_plugin.json | jq --arg version "$snforge_scarb_plugin_version" '[.[] | select(.v == $version)] | length > 0') |
| 22 | + echo "plugin_uploaded=$plugin_uploaded" >> $GITHUB_OUTPUT |
| 23 | +
|
| 24 | + build-binaries: |
| 25 | + name: Build ${{ matrix.target }} |
| 26 | + needs: check-version |
| 27 | + if: needs.check-version.outputs.plugin_uploaded == 'false' || github.event_name == 'workflow_dispatch' |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + |
| 30 | + env: |
| 31 | + # Cross-compiled targets will override this to `cross`. |
| 32 | + CARGO: cargo |
| 33 | + |
| 34 | + strategy: |
| 35 | + matrix: |
| 36 | + include: |
| 37 | + - target: x86_64-unknown-linux-gnu |
| 38 | + os: ubuntu-latest |
| 39 | + # Use cross to link oldest GLIBC possible. |
| 40 | + cross: true |
| 41 | + lib-name: "libsnforge_scarb_plugin" |
| 42 | + ext: "so" |
| 43 | + |
| 44 | + - target: aarch64-unknown-linux-gnu |
| 45 | + os: ubuntu-latest |
| 46 | + cross: true |
| 47 | + lib-name: "libsnforge_scarb_plugin" |
| 48 | + ext: "so" |
| 49 | + |
| 50 | + - target: x86_64-apple-darwin |
| 51 | + os: macos-latest |
| 52 | + lib-name: "libsnforge_scarb_plugin" |
| 53 | + ext: "dylib" |
| 54 | + |
| 55 | + - target: aarch64-apple-darwin |
| 56 | + os: macos-latest |
| 57 | + lib-name: "libsnforge_scarb_plugin" |
| 58 | + ext: "dylib" |
25 | 59 |
|
26 |
| - - uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a |
| 60 | + - target: x86_64-pc-windows-msvc |
| 61 | + os: windows-latest |
| 62 | + lib-name: "snforge_scarb_plugin" |
| 63 | + ext: "dll" |
| 64 | + |
| 65 | + # The scarb builds for following platforms are experimental and not officially supported by starknet-foundry. |
| 66 | + # https://docs.swmansion.com/scarb/download.html#platform-support |
| 67 | + # Reference issue: TODO(#2886) |
| 68 | + |
| 69 | + # - target: aarch64-unknown-linux-musl |
| 70 | + # os: ubuntu-latest |
| 71 | + # cross: true |
| 72 | + # ext: "so" |
| 73 | + |
| 74 | + # - target: x86_64-unknown-linux-musl |
| 75 | + # os: ubuntu-latest |
| 76 | + # cross: true |
| 77 | + # ext: "so" |
| 78 | + |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - uses: dtolnay/rust-toolchain@stable |
27 | 83 | with:
|
28 |
| - toolchain: stable |
| 84 | + target: ${{ matrix.target }} |
| 85 | + |
| 86 | + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 |
| 87 | + |
| 88 | + - name: Install cross |
| 89 | + if: matrix.cross |
| 90 | + uses: taiki-e/install-action@cross |
| 91 | + |
| 92 | + - name: Enable cross-compilation |
| 93 | + if: matrix.cross |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + echo "CARGO=cross" >> $GITHUB_ENV |
29 | 97 |
|
| 98 | + - name: Build |
| 99 | + working-directory: crates/snforge-scarb-plugin |
| 100 | + run: ${{ env.CARGO }} build --release --locked --target ${{ matrix.target }} |
| 101 | + |
| 102 | + - name: Rename Binary |
| 103 | + shell: bash |
| 104 | + run: | |
| 105 | + set -euxo pipefail |
| 106 | +
|
| 107 | + PACKAGE_NAME="snforge_scarb_plugin" |
| 108 | + PACKAGE_VERSION=$(grep version crates/snforge-scarb-plugin/Scarb.toml | cut -d '"' -f 2) |
| 109 | +
|
| 110 | + TARGET="${{ matrix.target }}" |
| 111 | + EXT="${{ matrix.ext }}" |
| 112 | + LIB_NAME="${{ matrix.lib-name }}" |
| 113 | +
|
| 114 | + OUTPUT_BINARY="${PACKAGE_NAME}_v${PACKAGE_VERSION}_${TARGET}.${EXT}" |
| 115 | +
|
| 116 | + mv ./target/${TARGET}/release/${LIB_NAME}.${EXT} ./target/${TARGET}/release/${OUTPUT_BINARY} |
| 117 | +
|
| 118 | + echo "OUTPUT_BINARY_PATH=./target/${TARGET}/release/${OUTPUT_BINARY}" >> $GITHUB_ENV |
| 119 | +
|
| 120 | + - name: Upload Artifact |
| 121 | + uses: actions/upload-artifact@v4 |
| 122 | + with: |
| 123 | + name: build-${{ matrix.target }} |
| 124 | + path: ${{ env.OUTPUT_BINARY_PATH }} |
| 125 | + compression-level: 0 |
| 126 | + |
| 127 | + upload-to-registry: |
| 128 | + name: Upload snforge_scarb_plugin to the registry |
| 129 | + runs-on: ubuntu-latest |
| 130 | + needs: [check-version, build-binaries] |
| 131 | + env: |
| 132 | + SCARB_REGISTRY_AUTH_TOKEN: ${{ secrets.SCARB_REGISTRY_AUTH_TOKEN }} |
| 133 | + steps: |
| 134 | + - uses: actions/checkout@v4 |
| 135 | + - uses: dtolnay/rust-toolchain@stable |
30 | 136 | - uses: software-mansion/setup-scarb@v1
|
31 | 137 | with:
|
32 |
| - scarb-version: "2.8.5" |
| 138 | + scarb-version: "2.10.0-rc.1" |
| 139 | + |
| 140 | + - name: Download artifacts |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + path: artifacts-dl |
| 144 | + |
| 145 | + - name: Unpack artifacts to target directory |
| 146 | + shell: bash |
| 147 | + run: | |
| 148 | + set -euxo pipefail |
| 149 | + mkdir -p crates/snforge-scarb-plugin/target/scarb/cairo-plugin |
| 150 | + |
| 151 | + mv artifacts-dl/build-*/snforge_scarb_plugin_* crates/snforge-scarb-plugin/target/scarb/cairo-plugin/ |
33 | 152 |
|
34 | 153 | - name: Publish snforge_scarb_plugin
|
35 |
| - if: ${{ steps.check-version.outputs.snforge_scarb_plugin_uploaded == 'false' || github.event_name == 'workflow_dispatch' }} |
| 154 | + if: needs.check-version.outputs.plugin_uploaded == 'false' || github.event_name == 'workflow_dispatch' |
36 | 155 | working-directory: crates/snforge-scarb-plugin
|
37 | 156 | run: scarb publish
|
0 commit comments