|
| 1 | +name: Release |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: write |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + commit_sha: |
| 10 | + description: Git commit sha, on which, to run this workflow |
| 11 | + |
| 12 | +defaults: |
| 13 | + run: |
| 14 | + shell: bash |
| 15 | + |
| 16 | +jobs: |
| 17 | + build_and_test: |
| 18 | + name: Build and Test Binaries |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - target: aarch64-apple-darwin |
| 23 | + host_operating_system: macos-14 |
| 24 | + use_cross: false |
| 25 | + test_method: native |
| 26 | + |
| 27 | + - target: x86_64-apple-darwin |
| 28 | + host_operating_system: macos-14 |
| 29 | + use_cross: false |
| 30 | + test_method: native |
| 31 | + |
| 32 | + - target: x86_64-unknown-linux-gnu |
| 33 | + host_operating_system: ubuntu-22.04 |
| 34 | + use_cross: false |
| 35 | + test_method: native |
| 36 | + |
| 37 | + - target: x86_64-unknown-linux-musl |
| 38 | + host_operating_system: ubuntu-22.04 |
| 39 | + use_cross: true |
| 40 | + test_method: native |
| 41 | + |
| 42 | + - target: aarch64-unknown-linux-gnu |
| 43 | + host_operating_system: ubuntu-22.04 |
| 44 | + use_cross: true |
| 45 | + test_method: qemu |
| 46 | + qemu_architecture: aarch64 |
| 47 | + |
| 48 | + - target: aarch64-unknown-linux-musl |
| 49 | + host_operating_system: ubuntu-22.04 |
| 50 | + use_cross: true |
| 51 | + test_method: qemu |
| 52 | + qemu_architecture: aarch64 |
| 53 | + |
| 54 | + - target: armv7-unknown-linux-musleabihf |
| 55 | + host_operating_system: ubuntu-22.04 |
| 56 | + use_cross: true |
| 57 | + test_method: qemu |
| 58 | + qemu_architecture: arm |
| 59 | + |
| 60 | + runs-on: ${{ matrix.host_operating_system }} |
| 61 | + steps: |
| 62 | + - name: Checkout |
| 63 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 64 | + with: |
| 65 | + ref: ${{ github.event.inputs.commit_sha }} |
| 66 | + |
| 67 | + - name: Setup rust toolchain |
| 68 | + run: | |
| 69 | + rustup show |
| 70 | + rustup target add ${{ matrix.target }} |
| 71 | +
|
| 72 | + - name: Install build dependencies |
| 73 | + if: matrix.host_operating_system == 'ubuntu-22.04' |
| 74 | + run: | |
| 75 | + set -x |
| 76 | +
|
| 77 | + if [ "${{ matrix.use_cross }}" == "true" ]; then |
| 78 | + cargo install cross --git https://github.com/cross-rs/cross |
| 79 | + else |
| 80 | + sudo apt-get update |
| 81 | + sudo apt-get install -y --no-install-recommends \ |
| 82 | + gcc g++ libclang-dev xz-utils liblz4-tool musl-tools |
| 83 | + fi |
| 84 | +
|
| 85 | + if [ "${{ matrix.test_method }}" == "qemu" ]; then |
| 86 | + sudo apt-get update |
| 87 | + sudo apt-get install -y qemu-user-static |
| 88 | +
|
| 89 | + # Install libraries needed for QEMU to properly execute dynamically |
| 90 | + # linked binaries for the target architectures. |
| 91 | + if [ "${{ matrix.qemu_architecture }}" == "aarch64" ]; then |
| 92 | + sudo apt-get install -y libc6-dev-arm64-cross |
| 93 | + elif [ "${{ matrix.qemu_architecture }}" == "arm" ]; then |
| 94 | + sudo apt-get install -y libc6-dev-armhf-cross |
| 95 | + fi |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Build binary |
| 99 | + run: | |
| 100 | + set -ex |
| 101 | + cd source/rust/autonomy_command |
| 102 | +
|
| 103 | + # Build the compile tool first (natively for the host) |
| 104 | + # This must be done before setting RUSTFLAGS=+crt-static to avoid |
| 105 | + # the Rust compiler bug where proc-macros cannot be built with static |
| 106 | + # linking https://github.com/rust-lang/rust/issues/78210 |
| 107 | + cargo build --bin compile |
| 108 | +
|
| 109 | + # Set RUSTFLAGS for musl targets only when building the target binary |
| 110 | + # The compile tool will use these flags when building the final autonomy binary |
| 111 | + if [[ "${{ matrix.target }}" =~ .+-musl(.+)? ]]; then |
| 112 | + export RUSTFLAGS='-C target-feature=+crt-static' |
| 113 | + fi |
| 114 | +
|
| 115 | + # Use the compile tool to build the target binary |
| 116 | + if [ "${{ matrix.use_cross }}" == "true" ]; then |
| 117 | + ./target/debug/compile --configuration compile.yaml \ |
| 118 | + --target ${{ matrix.target }} --use-cross --release |
| 119 | + else |
| 120 | + ./target/debug/compile --configuration compile.yaml \ |
| 121 | + --target ${{ matrix.target }} --release |
| 122 | + fi |
| 123 | +
|
| 124 | + BINARY_PATH="./target/${{ matrix.target }}/release/autonomy" |
| 125 | + chmod +x "$BINARY_PATH" |
| 126 | +
|
| 127 | + if [ "${{ matrix.test_method }}" == "qemu" ]; then |
| 128 | + qemu-${{ matrix.qemu_architecture }}-static "$BINARY_PATH" --version |
| 129 | + else |
| 130 | + "$BINARY_PATH" --version |
| 131 | + fi |
| 132 | +
|
| 133 | + - name: Upload binary artifact |
| 134 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 |
| 135 | + with: |
| 136 | + name: autonomy.${{ matrix.target }} |
| 137 | + path: source/rust/autonomy_command/target/${{ matrix.target }}/release/autonomy |
| 138 | + if-no-files-found: error |
| 139 | + compression-level: 0 |
| 140 | + |
| 141 | + create_release: |
| 142 | + name: Create Release |
| 143 | + needs: build_and_test |
| 144 | + runs-on: ubuntu-22.04 |
| 145 | + if: github.event_name == 'workflow_dispatch' |
| 146 | + steps: |
| 147 | + - name: Checkout |
| 148 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 149 | + with: |
| 150 | + ref: ${{ github.event.inputs.commit_sha }} |
| 151 | + |
| 152 | + - name: Download all artifacts |
| 153 | + uses: actions/download-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 |
| 154 | + with: |
| 155 | + path: artifacts |
| 156 | + |
| 157 | + - name: Create Release |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 160 | + run: | |
| 161 | + RELEASE_TAG="v0.158.0" |
| 162 | + RELEASE_NAME="Release v0.158.0" |
| 163 | + COMMIT_SHA="${{ github.event.inputs.commit_sha || github.sha }}" |
| 164 | + RELEASE_BODY="Release v0.158.0" |
| 165 | +
|
| 166 | + gh release create "$RELEASE_TAG" \ |
| 167 | + --title "$RELEASE_NAME" \ |
| 168 | + --notes "$RELEASE_BODY" \ |
| 169 | + --target "$COMMIT_SHA" \ |
| 170 | + --draft |
| 171 | +
|
| 172 | + for artifact_dir in artifacts/autonomy.*; do |
| 173 | + if [ -d "$artifact_dir" ]; then |
| 174 | + target=$(basename "$artifact_dir" | sed 's/autonomy\.//') |
| 175 | + for binary_file in "$artifact_dir"/*; do |
| 176 | + if [ -f "$binary_file" ]; then |
| 177 | + asset_name="autonomy-${target}" |
| 178 | + echo "Uploading $binary_file as $asset_name" |
| 179 | + gh release upload "$RELEASE_TAG" "$binary_file#$asset_name" |
| 180 | + fi |
| 181 | + done |
| 182 | + fi |
| 183 | + done |
0 commit comments