|
| 1 | +name: release-binaries |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: "Existing git tag to release (for example: v0.1.0)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +env: |
| 18 | + BINARY_NAME: odoo-rapid-quant |
| 19 | + TARGET: x86_64-unknown-linux-musl |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-and-publish: |
| 23 | + name: build-and-publish-linux-musl |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v6 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Resolve release tag |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 36 | + echo "RELEASE_TAG=${{ github.event.inputs.tag }}" >> "$GITHUB_ENV" |
| 37 | + else |
| 38 | + echo "RELEASE_TAG=${GITHUB_REF_NAME}" >> "$GITHUB_ENV" |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: Checkout requested tag |
| 42 | + if: github.event_name == 'workflow_dispatch' |
| 43 | + shell: bash |
| 44 | + run: git checkout "${RELEASE_TAG}" |
| 45 | + |
| 46 | + - name: Validate tag matches Cargo.toml version |
| 47 | + shell: bash |
| 48 | + run: | |
| 49 | + tag_version="${RELEASE_TAG#v}" |
| 50 | + manifest_version="$(python -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')" |
| 51 | +
|
| 52 | + if [ "${tag_version}" != "${manifest_version}" ]; then |
| 53 | + echo "::error::Tag ${RELEASE_TAG} does not match Cargo.toml version ${manifest_version}" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Install Rust toolchain |
| 58 | + uses: dtolnay/rust-toolchain@stable |
| 59 | + with: |
| 60 | + targets: ${{ env.TARGET }} |
| 61 | + |
| 62 | + - name: Cache Rust dependencies |
| 63 | + uses: Swatinem/rust-cache@v2 |
| 64 | + with: |
| 65 | + key: ${{ env.TARGET }} |
| 66 | + |
| 67 | + - name: Install musl toolchain |
| 68 | + shell: bash |
| 69 | + run: | |
| 70 | + sudo apt-get update |
| 71 | + sudo apt-get install -y musl-tools |
| 72 | +
|
| 73 | + - name: Build static Linux binary |
| 74 | + shell: bash |
| 75 | + run: cargo build --locked --release --target "${TARGET}" |
| 76 | + |
| 77 | + - name: Verify static linking |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + binary_path="target/${TARGET}/release/${BINARY_NAME}" |
| 81 | + ldd_output="$(ldd "${binary_path}" 2>&1 || true)" |
| 82 | + echo "${ldd_output}" |
| 83 | + if ! grep -Eq "not a dynamic executable|statically linked" <<< "${ldd_output}"; then |
| 84 | + echo "Expected a static musl binary, but binary appears dynamically linked." |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Package release archive |
| 89 | + shell: bash |
| 90 | + run: | |
| 91 | + mkdir -p dist |
| 92 | + cp "target/${TARGET}/release/${BINARY_NAME}" "dist/${BINARY_NAME}" |
| 93 | + cp LICENSE "dist/LICENSE" |
| 94 | + archive="${BINARY_NAME}-${RELEASE_TAG}-${TARGET}.tar.gz" |
| 95 | + tar -C dist -czf "dist/${archive}" "${BINARY_NAME}" "LICENSE" |
| 96 | + rm "dist/${BINARY_NAME}" "dist/LICENSE" |
| 97 | +
|
| 98 | + - name: Generate checksums |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + cd dist |
| 102 | + sha256sum * > SHA256SUMS |
| 103 | +
|
| 104 | + - name: Create or update GitHub release |
| 105 | + uses: softprops/action-gh-release@v2 |
| 106 | + with: |
| 107 | + tag_name: ${{ env.RELEASE_TAG }} |
| 108 | + files: | |
| 109 | + dist/* |
| 110 | + generate_release_notes: true |
| 111 | + env: |
| 112 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments