From 7caaa92ee766bc8d6ea92720ba50a9616d982be4 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Wed, 13 Sep 2023 18:54:27 +0200 Subject: [PATCH] WIP: better release workflow --- .github/workflows/build.yaml | 252 ++++++++++------------------------- 1 file changed, 72 insertions(+), 180 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 05438d397..fcdf4e4e1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,9 +17,12 @@ env: CARGO_NET_GIT_FETCH_WITH_CLI: "true" jobs: - build-assets: - name: Build assets - runs-on: ubuntu-latest + build: + name: Build binaries + runs-on: ubuntu-22.04 + + env: + SDKROOT: /opt/MacOSX11.3.sdk permissions: contents: read @@ -38,6 +41,17 @@ jobs: with: node-version: 18 + - name: Setup Rust build cache + uses: Swatinem/rust-cache@v2.7.0 + with: + save-if: "${{ github.event_name != 'pull_request' }}" + + - name: Install zig and cargo-zigbuild + run: pip3 install ziglang==0.11.0 cargo-zigbuild==0.17.1 + + - name: Download the macOS SDK + run: curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz" | tar -J -x -C /opt + - name: Install Node dependencies working-directory: ./frontend run: npm ci @@ -50,188 +64,66 @@ jobs: working-directory: ./policies run: make - - name: Collect the artifacts + - name: Force Cargo to create the target directory + # Run `cargo clean` with an empty package name to force it to create the target directory + # This fails because there is no package with an empty name, but the target directory is created + # See https://github.com/rust-lang/cargo/issues/12441 + # This is needed because `cargo-zigbuild` sometimes (wrongly) creates the target directory + # See https://github.com/rust-cross/cargo-zigbuild/issues/165 run: | - mkdir share/ - mv policies/policy.wasm share/policy.wasm - mv frontend/dist/manifest.json share/manifest.json - mv frontend/dist/ share/assets - mv templates/ share/templates + cargo clean -p '' \ + --target x86_64-unknown-linux-musl \ + --target aarch64-unknown-linux-musl \ + --target x86_64-apple-darwin \ + --target aarch64-apple-darwin \ + || true + + - name: Build the binary + run: | + cargo zigbuild \ + --release \ + --target x86_64-unknown-linux-musl \ + --target aarch64-unknown-linux-musl \ + --target x86_64-apple-darwin \ + --target aarch64-apple-darwin \ + --no-default-features \ + --features dist \ + -p mas-cli - name: Upload the artifacts uses: actions/upload-artifact@v3.1.3 with: - name: artifacts - path: share/ + path: | + target/x86_64-unknown-linux-musl/release/mas-cli + target/aarch64-unknown-linux-musl/release/mas-cli + target/x86_64-apple-darwin/release/mas-cli + target/aarch64-apple-darwin/release/mas-cli + frontend/dist/ + policies/policy.wasm + #release: + # name: Release + # if: startsWith(github.ref, 'refs/tags/') + # runs-on: ubuntu-latest + # needs: + # - build + # steps: + # - name: Download the artifacts from the previous job + # uses: actions/download-artifact@v3 + # with: + # path: artifacts - build-linux: - name: Build for Linux ${{ matrix.arch }} - runs-on: ubuntu-22.04 + # - name: Create the various archives + # run: | + # mkdir -p dist + # mv artifacts/ - needs: - - build-assets - - strategy: - fail-fast: false - matrix: - arch: [x86_64, aarch64] - - steps: - - name: Checkout the code - uses: actions/checkout@v4.0.0 - - - name: Install Rust toolchain - run: | - rustup toolchain install stable - rustup default stable - rustup target add ${{ matrix.arch }}-unknown-linux-musl - - - name: Setup Rust build cache - uses: Swatinem/rust-cache@v2.7.0 - with: - shared-key: ${{ matrix.arch }}-linux - save-if: "${{ github.event_name != 'pull_request' }}" - - - name: Install zig and cargo-zigbuild - run: pip3 install ziglang==0.11.0 cargo-zigbuild==0.17.1 - - - name: Force Cargo to create the target directory - # Run `cargo clean` with an empty package name to force it to create the target directory - # This fails because there is no package with an empty name, but the target directory is created - # See https://github.com/rust-lang/cargo/issues/12441 - # This is needed because `cargo-zigbuild` sometimes (wrongly) creates the target directory - # See https://github.com/rust-cross/cargo-zigbuild/issues/165 - run: cargo clean -p '' --target ${{ matrix.arch }}-unknown-linux-gnu || true - - - name: Build the binary - run: | - cargo zigbuild \ - --release \ - --target=${{ matrix.arch }}-unknown-linux-musl \ - --no-default-features \ - --features dist \ - -p mas-cli - - - name: Download the artifacts - uses: actions/download-artifact@v3.0.2 - with: - name: artifacts - path: share/ - - - name: Create the archive - run: | - mkdir dist/ - mv share/ dist/ - mv target/${{ matrix.arch }}-unknown-linux-musl/release/mas-cli dist/ - mv LICENSE dist/ - chmod -R u=rwX,go=rX dist/ - tar -czvf mas-cli-${{ matrix.arch }}-linux.tar.gz --owner=0 --group=0 -C dist/ . - - - name: Upload the binary as artifact - uses: actions/upload-artifact@v3.1.3 - with: - name: ${{ matrix.arch }}-linux - path: mas-cli-${{ matrix.arch }}-linux.tar.gz - - - build-macos: - name: Build for macOS ${{ matrix.arch }} - runs-on: ubuntu-22.04 - env: - SDKROOT: /opt/MacOSX11.3.sdk - - needs: - - build-assets - - strategy: - fail-fast: false - matrix: - arch: [x86_64, aarch64] - - steps: - - name: Checkout the code - uses: actions/checkout@v4.0.0 - - - name: Install Rust toolchain - run: | - rustup toolchain install stable - rustup default stable - rustup target add ${{ matrix.arch }}-apple-darwin - - - name: Setup Rust build cache - uses: Swatinem/rust-cache@v2.7.0 - with: - shared-key: ${{ matrix.arch }}-macos - save-if: "${{ github.event_name != 'pull_request' }}" - - - name: Install zig and cargo-zigbuild - run: pip3 install ziglang==0.11.0 cargo-zigbuild==0.17.1 - - - name: Download the macOS SDK - run: curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz" | tar -J -x -C /opt - - - name: Force Cargo to create the target directory - # Run `cargo clean` with an empty package name to force it to create the target directory - # This fails because there is no package with an empty name, but the target directory is created - # See https://github.com/rust-lang/cargo/issues/12441 - # This is needed because `cargo-zigbuild` sometimes (wrongly) creates the target directory - # See https://github.com/rust-cross/cargo-zigbuild/issues/165 - run: cargo clean -p '' --target ${{ matrix.arch }}-apple-darwin || true - - - name: Build the binary - run: | - cargo zigbuild \ - --release \ - --target=${{ matrix.arch }}-apple-darwin \ - --no-default-features \ - --features dist \ - -p mas-cli - - - name: Download the artifacts - uses: actions/download-artifact@v3.0.2 - with: - name: artifacts - path: share/ - - - name: Create the archive - run: | - mkdir dist/ - mv share/ dist/ - mv target/${{ matrix.arch }}-apple-darwin/release/mas-cli dist/ - mv LICENSE dist/ - chmod -R u=rwX,go=rX dist/ - tar -czvf mas-cli-${{ matrix.arch }}-macos.tar.gz --owner=0 --group=0 -C dist/ . - - - name: Upload the binary as artifact - uses: actions/upload-artifact@v3.1.3 - with: - name: ${{ matrix.arch }}-macos - path: mas-cli-${{ matrix.arch }}-macos.tar.gz - - release: - name: Release - if: startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - needs: - - build-linux - - build-macos - steps: - - name: Download the artifacts from the previous job - uses: actions/download-artifact@v3 - with: - path: artifacts - - - name: Move the release assets - run: | - mv ./artifacts/{x86_64,aarch64}-{linux,macos}/* ./ - - - name: Prepare a release - uses: softprops/action-gh-release@v1 - with: - files: | - mas-cli-aarch64-linux.tar.gz - mas-cli-aarch64-macos.tar.gz - mas-cli-x86_64-linux.tar.gz - mas-cli-x86_64-macos.tar.gz - draft: true \ No newline at end of file + # - name: Prepare a release + # uses: softprops/action-gh-release@v1 + # with: + # files: | + # mas-cli-aarch64-linux.tar.gz + # mas-cli-aarch64-macos.tar.gz + # mas-cli-x86_64-linux.tar.gz + # mas-cli-x86_64-macos.tar.gz + # draft: true \ No newline at end of file