From fcd3d12006ac70604dad3b906e54177a778a8f88 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Sat, 21 Sep 2024 16:27:19 +0800 Subject: [PATCH] ci: release workflow --- .github/workflows/config.toml | 13 +++ .github/workflows/release.yml | 153 ++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 .github/workflows/config.toml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/config.toml b/.github/workflows/config.toml new file mode 100644 index 00000000000..f965b210a1f --- /dev/null +++ b/.github/workflows/config.toml @@ -0,0 +1,13 @@ +[build] +target = ["riscv32im-succinct-zkvm-elf"] +extended = true +tools = ["cargo", "cargo-clippy", "clippy", "rustfmt"] +configure-args = [] +cargo-native-static = true + +[rust] +lld = true +llvm-tools = true + +[llvm] +download-ci-llvm = false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..f077a5ec275 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,153 @@ +on: + push: + tags: + - "v*.*.*" + +name: "Release" + +jobs: + version-info: + name: "Extract version info" + runs-on: "ubuntu-latest" + outputs: + version: ${{ steps.derive.outputs.version }} + + steps: + - id: "derive" + name: "Derive version info from Git tag" + run: | + FULL_REF="${{ github.ref }}" + REGEX="^refs\/tags\/v(.*)$" + [[ $FULL_REF =~ $REGEX ]]; + + echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT + + draft-release: + name: "Create draft release" + runs-on: "ubuntu-latest" + needs: + - "version-info" + outputs: + release-id: ${{ steps.create.outputs.id }} + + steps: + - id: "create" + name: "Create draft release" + run: | + ID=$(curl -L --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -d '{"tag_name":"v${{ needs.version-info.outputs.version }}","name":"v${{ needs.version-info.outputs.version }}","draft":true,"generate_release_notes":true}' | + jq ".id") + echo "id=$ID" >> $GITHUB_OUTPUT + + release-unix: + name: "Build for ${{ matrix.triple }}" + runs-on: "${{ matrix.runner }}" + needs: + - "version-info" + - "draft-release" + + strategy: + matrix: + include: + # WARN: DO NOT upgrade Ubuntu runner to 22.04 or higher, as that would cause glibc 3.2+ to + # be linked, and therefore errors when running on Ubuntu 20.04. + - runner: "buildjet-32vcpu-ubuntu-2004" + triple: "x86_64-unknown-linux-gnu" + # Using Ubuntu 22 for now as none of these support Ubuntu 20 on ARM64: + # + # - GitHub Actions large runners + # - BuildJet + # - runs-on + # + # FIXME: use `ec2-github-runner` to build on Ubuntu 20.04 instead. + - runner: + [ + "runs-on", + "runner=64cpu-linux-arm64", + "image=ubuntu22-full-arm64", + "run-id=${{ github.run_id }}", + ] + triple: "aarch64-unknown-linux-gnu" + - runner: "macos-13" + triple: "x86_64-apple-darwin" + - runner: "macos-14" + triple: "aarch64-apple-darwin" + + steps: + - name: "Checkout source code" + uses: "actions/checkout@v3" + with: + submodules: "recursive" + fetch-depth: 0 + + - name: "Setup ninja-build" + if: matrix.triple != 'aarch64-unknown-linux-gnu' + uses: "seanmiddleditch/gha-setup-ninja@v5" + + - name: "Setup ninja-build" + if: matrix.triple == 'aarch64-unknown-linux-gnu' + run: | + sudo apt-get update + sudo apt-get install -y ninja-build + + - name: "Setup build config" + run: | + cp ./.github/workflows/config.toml ./config.toml + + - name: "Setup build env vars" + run: | + echo "CARGO_TARGET_RISCV32IM_SUCCINCT_ZKVM_ELF_RUSTFLAGS=-Cpasses=loweratomic" >> $GITHUB_ENV + + - name: "Work around missing target issue" + run: | + mkdir /tmp/rustc-targets + touch /tmp/rustc-targets/riscv32im-succinct-zkvm-elf.json + echo "RUST_TARGET_PATH=/tmp/rustc-targets" >> $GITHUB_ENV + + - name: "Build Rust" + run: | + ./x.py build --stage 2 + + - name: "Archive toolchain" + run: | + # Use `rsync` instead of `cp` due to hardlinks + rsync --recursive ./build/${{ matrix.triple }}/stage2-tools-bin/ ./build/${{ matrix.triple }}/stage2/bin/ + + tar \ + --exclude lib/rustlib/src \ + --exclude lib/rustlib/rustc-src \ + -hczvf \ + ./rust-toolchain-${{ matrix.triple }}.tar.gz \ + -C ./build/${{ matrix.triple }}/stage2/ \ + . + + - name: "Upload workflow artifact" + uses: "actions/upload-artifact@v3" + with: + name: "rust-toolchain-${{ matrix.triple }}.tar.gz" + path: "./rust-toolchain-${{ matrix.triple }}.tar.gz" + + - name: "Upload release artifact" + run: | + ARTIFACT_NAME="rust-toolchain-${{ matrix.triple }}.tar.gz" + + curl -L --fail "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}/assets?name=${ARTIFACT_NAME}" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@${ARTIFACT_NAME}" + + publish-release: + name: "Publish release" + runs-on: "ubuntu-latest" + needs: + - "draft-release" + - "release-unix" + + steps: + - name: "Publish release" + run: | + curl -L --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}" \ + -X PATCH \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -d '{"draft":false}'