|
| 1 | +name: Build and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + release: |
| 9 | + types: |
| 10 | + - published |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + tag_name: |
| 14 | + description: "Tag name" |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + should_publish: |
| 18 | + description: "Whether to publish the release" |
| 19 | + required: true |
| 20 | + type: boolean |
| 21 | + |
| 22 | +jobs: |
| 23 | + check: |
| 24 | + name: Check |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b |
| 29 | + with: |
| 30 | + toolchain: stable |
| 31 | + - run: cargo check |
| 32 | + |
| 33 | + test: |
| 34 | + name: Test |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b |
| 39 | + with: |
| 40 | + toolchain: stable |
| 41 | + - run: cargo test |
| 42 | + |
| 43 | + fmt: |
| 44 | + name: Format |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b |
| 49 | + with: |
| 50 | + toolchain: stable |
| 51 | + components: rustfmt |
| 52 | + - run: cargo fmt --all -- --check |
| 53 | + |
| 54 | + clippy: |
| 55 | + name: Clippy |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b |
| 60 | + with: |
| 61 | + toolchain: stable |
| 62 | + components: clippy |
| 63 | + - run: cargo clippy -- -D warnings |
| 64 | + |
| 65 | + build-and-publish: |
| 66 | + name: Build and Publish |
| 67 | + runs-on: ${{ matrix.os }} |
| 68 | + strategy: |
| 69 | + matrix: |
| 70 | + include: |
| 71 | + - name: linux |
| 72 | + os: ubuntu-22.04 # Use oldest supported non-deprecated version so we link against older glibc version which allows running binary on a wider set of Linux systems |
| 73 | + path: target/x86_64-unknown-linux-gnu/release/function-runner |
| 74 | + asset_name: function-runner-x86_64-linux-${{ inputs.tag_name || github.event.release.tag_name }} |
| 75 | + shasum_cmd: sha256sum |
| 76 | + target: x86_64-unknown-linux-gnu |
| 77 | + - name: linux-arm64 |
| 78 | + os: ubuntu-22.04 # Use oldest supported non-deprecated version so we link against older glibc version which allows running binary on a wider set of Linux systems |
| 79 | + path: target/aarch64-unknown-linux-gnu/release/function-runner |
| 80 | + asset_name: function-runner-arm-linux-${{ inputs.tag_name || github.event.release.tag_name }} |
| 81 | + shasum_cmd: sha256sum |
| 82 | + target: aarch64-unknown-linux-gnu |
| 83 | + - name: macos |
| 84 | + os: macos-latest |
| 85 | + path: target/x86_64-apple-darwin/release/function-runner |
| 86 | + asset_name: function-runner-x86_64-macos-${{ inputs.tag_name || github.event.release.tag_name }} |
| 87 | + shasum_cmd: shasum -a 256 |
| 88 | + target: x86_64-apple-darwin |
| 89 | + - name: arm64-macos |
| 90 | + os: macos-latest |
| 91 | + path: target/aarch64-apple-darwin/release/function-runner |
| 92 | + asset_name: function-runner-arm-macos-${{ inputs.tag_name || github.event.release.tag_name }} |
| 93 | + shasum_cmd: shasum -a 256 |
| 94 | + target: aarch64-apple-darwin |
| 95 | + - name: windows |
| 96 | + os: windows-latest |
| 97 | + path: target\x86_64-pc-windows-msvc\release\function-runner.exe |
| 98 | + asset_name: function-runner-x86_64-windows-${{ inputs.tag_name || github.event.release.tag_name }} |
| 99 | + shasum_cmd: sha256sum |
| 100 | + target: x86_64-pc-windows-msvc |
| 101 | + |
| 102 | + steps: |
| 103 | + - uses: actions/checkout@v4 |
| 104 | + |
| 105 | + - name: Install cross compiler |
| 106 | + if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }} |
| 107 | + run: | |
| 108 | + sudo apt-get update |
| 109 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 110 | +
|
| 111 | + - name: Set up cross compiler env variables |
| 112 | + if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }} |
| 113 | + run: | |
| 114 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
| 115 | + echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
| 116 | + echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV |
| 117 | +
|
| 118 | + # Should no-op except for macos-arm case where that target won't be installed |
| 119 | + - name: Install target |
| 120 | + run: rustup target add ${{ matrix.target }} |
| 121 | + |
| 122 | + - name: Build ${{ matrix.target }} |
| 123 | + run: cargo build --release --target ${{ matrix.target }} --package function-runner |
| 124 | + |
| 125 | + - name: Archive assets |
| 126 | + if: ${{ inputs.should_publish }} |
| 127 | + run: gzip -k -f ${{ matrix.path }} && mv ${{ matrix.path }}.gz ${{ matrix.asset_name }}.gz |
| 128 | + |
| 129 | + - name: Upload assets to artifacts |
| 130 | + if: ${{ inputs.should_publish }} |
| 131 | + uses: actions/upload-artifact@v4 |
| 132 | + with: |
| 133 | + name: ${{ matrix.asset_name }}.gz |
| 134 | + path: ${{ matrix.asset_name }}.gz |
| 135 | + |
| 136 | + - name: Upload assets to release |
| 137 | + if: ${{ inputs.should_publish }} |
| 138 | + env: |
| 139 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + run: gh release upload ${{ inputs.tag_name || github.event.release.tag_name }} ${{ matrix.asset_name }}.gz |
| 141 | + |
| 142 | + - name: Generate asset hash |
| 143 | + if: ${{ inputs.should_publish }} |
| 144 | + run: ${{ matrix.shasum_cmd }} ${{ matrix.asset_name }}.gz | awk '{ print $1 }' > ${{ matrix.asset_name }}.gz.sha256 |
| 145 | + |
| 146 | + - name: Upload asset hash to artifacts |
| 147 | + if: ${{ inputs.should_publish }} |
| 148 | + uses: actions/upload-artifact@v4 |
| 149 | + with: |
| 150 | + name: ${{ matrix.asset_name }}.gz.sha256 |
| 151 | + path: ${{ matrix.asset_name }}.gz.sha256 |
| 152 | + |
| 153 | + - name: Upload asset hash to release |
| 154 | + if: ${{ inputs.should_publish }} |
| 155 | + env: |
| 156 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 157 | + run: gh release upload ${{ inputs.tag_name || github.event.release.tag_name }} ${{ matrix.asset_name }}.gz.sha256 |
0 commit comments