From 6aef1ebd700d66abe5e44eadd9dc7b6192a7793f Mon Sep 17 00:00:00 2001 From: Wu Wayne Date: Thu, 29 Feb 2024 15:59:34 +0900 Subject: [PATCH 1/5] Add release CI pipeline --- .github/workflows/release.yml | 217 ++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..723db0dfed2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,217 @@ +name: Rust + +on: + push: + branches: [main] + pull_request: + +env: + RUST_BACKTRACE: 1 + SHELL: /bin/bash + CARGO_INCREMENTAL: 0 + MOZJS_CREATE_ARCHIVE: 1 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository_owner }}/mozjs + +jobs: + mac-arm: + runs-on: macos-14 + needs: create-release + strategy: + fail-fast: false + matrix: + features: ["--features streams"] + env: + RUSTC_WRAPPER: sccache + CCACHE: sccache + SCCACHE_GHA_ENABLED: "true" + RELEASE_ID: ${{ needs.create-release.outputs.release-id }} + steps: + - uses: actions/checkout@v4 + - name: Install deps + run: | + # Unlink and re-link to prevent errors when github mac runner images + # https://github.com/actions/setup-python/issues/577 + brew list -1 | grep python | while read formula; do brew unlink $formula; brew link --overwrite $formula; done + brew install llvm yasm + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + - name: Build + run: | + cargo build --verbose ${{ matrix.features }} + cargo test --tests --examples --verbose ${{ matrix.features }} + - name: Upload release asset + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + "https://uploads.github.com/repos/${REPO}/releases/${RELEASE_ID}/assets?name=libmozjs-aarch64-apple-darwin.tar.gz" \ + --data-binary "@target/libmozjs-aarch64-apple-darwin.tar.gz" + + mac-x86_64: + runs-on: macos-13 + needs: create-release + strategy: + fail-fast: false + matrix: + features: ["--features streams"] + env: + RUSTC_WRAPPER: sccache + CCACHE: sccache + SCCACHE_GHA_ENABLED: "true" + RELEASE_ID: ${{ needs.create-release.outputs.release-id }} + steps: + - uses: actions/checkout@v4 + - name: Install deps + run: | + # Unlink and re-link to prevent errors when github mac runner images + # https://github.com/actions/setup-python/issues/577 + brew list -1 | grep python | while read formula; do brew unlink $formula; brew link --overwrite $formula; done + brew install llvm yasm + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + - name: Build + run: | + cargo build --verbose ${{ matrix.features }} + cargo test --tests --examples --verbose ${{ matrix.features }} + - name: Upload release asset + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + "https://uploads.github.com/repos/${REPO}/releases/${RELEASE_ID}/assets?name=libmozjs-x86_64-apple-darwin.tar.gz" \ + --data-binary "@target/libmozjs-x86_64-apple-darwin.tar.gz" + + linux: + env: + RUSTC_WRAPPER: "sccache" + CCACHE: sccache + SCCACHE_GHA_ENABLED: "true" + runs-on: ubuntu-latest + needs: create-release + strategy: + fail-fast: false + matrix: + features: ["--features streams"] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Install deps + run: | + sudo apt install llvm -y + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + - name: Build + run: | + cargo build --verbose ${{ matrix.features }} + cargo test --tests --examples --verbose ${{ matrix.features }} + - name: Upload release asset + env: + RELEASE_ID: ${{ needs.create-release.outputs.release-id }} + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + "https://uploads.github.com/repos/${REPO}/releases/${RELEASE_ID}/assets?name=libmozjs-x86_64-unknown-linux-gnu.tar.gz" \ + --data-binary "@target/libmozjs-x86_64-unknown-linux-gnu.tar.gz" + + windows: + runs-on: windows-latest + needs: create-release + strategy: + fail-fast: false + matrix: + features: ["--features streams"] + env: + LINKER: "lld-link.exe" + CC: "clang-cl" + CXX: "clang-cl" + MOZTOOLS_PATH: "${{ github.workspace }}\\target\\dependencies\\moztools-4.0" + CCACHE: sccache + SCCACHE_GHA_ENABLED: "true" + RELEASE_ID: ${{ needs.create-release.outputs.release-id }} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + - name: Install deps + run: | + curl -SL "https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-4.0.zip" --create-dirs -o target/dependencies/moztools.zip + cd target/dependencies && unzip -qo moztools.zip -d . + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + - name: Build Windows + shell: cmd + run: | + cargo build --verbose ${{ matrix.features }} + cargo test --tests --examples --verbose ${{ matrix.features }} + - name: Upload release asset + uses: actions/upload-release-asset@v1 + with: + upload_url: https://uploads.github.com/repos/${{ github.repository_owner }}/mozjs/releases/${{ needs.create-release.outputs.release-id }}/assets{?name,label} + asset_path: ./target/libmozjs-x86_64-pc-windows-msvc.tar.gz + asset_name: libmozjs-x86_64-pc-windows-msvc.tar.gz + asset_content_type: application/tar+gzip + + create-release: + runs-on: ubuntu-latest + steps: + - name: Create release + id: create-release + run: | + NIGHTLY_TAG=$(date "+%F") + RELEASE_URL=$(gh release create "${NIGHTLY_TAG}" \ + --draft \ + --title "${NIGHTLY_TAG}" \ + --notes 'Version release based on servo/mozjs@${{ github.sha }}' \ + --repo ${REPO}) + TEMP_TAG=$(basename "$RELEASE_URL") + RELEASE_ID=$( \ + gh api -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/${REPO}/releases/tags/${TEMP_TAG}" \ + | jq '.id' \ + ) + echo "RELEASE_ID=${RELEASE_ID}" >> ${GITHUB_OUTPUT} + outputs: + release-id: ${{ steps.create-release.outputs.RELEASE_ID }} + + publish-release: + name: Result + runs-on: ubuntu-latest + needs: + ["create-release", "mac-arm", "mac-x86_64", "linux", "windows"] + if: ${{ always() }} + env: + RELEASE_ID: ${{ needs.create-release.outputs.release-id }} + steps: + - name: Publish as latest (success) + if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} + run: | + gh api \ + --method PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${REPO}/releases/${RELEASE_ID} \ + -F draft=false + - name: Publish as latest (failure) + if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + run: | + gh api \ + --method PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${REPO}/releases/${RELEASE_ID} \ + -F prerelease=true -F draft=false + + From ad84256598d2fa36be93d740d8a364d064b1ba45 Mon Sep 17 00:00:00 2001 From: Wu Wayne Date: Thu, 29 Feb 2024 16:05:44 +0900 Subject: [PATCH 2/5] Rename CI pipeline --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 723db0dfed2..73a9a392ad1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Rust +name: Prebuilt mozjs release on: push: From c5bf7c2a0c78e91da251893fccbdab159edfaa7c Mon Sep 17 00:00:00 2001 From: Wu Wayne Date: Thu, 29 Feb 2024 18:10:03 +0900 Subject: [PATCH 3/5] Update CI trigger condition --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 73a9a392ad1..cba5fbc50b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,6 @@ name: Prebuilt mozjs release on: push: branches: [main] - pull_request: env: RUST_BACKTRACE: 1 From d3e69acfb3e8e7baeb5dd2ea7ffdf0f6c7e212aa Mon Sep 17 00:00:00 2001 From: Wu Wayne Date: Thu, 29 Feb 2024 19:38:05 +0900 Subject: [PATCH 4/5] Merge CI into one file --- .github/workflows/release.yml | 216 ---------------------------------- .github/workflows/rust.yml | 86 +++++++++++++- 2 files changed, 81 insertions(+), 221 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index cba5fbc50b5..00000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,216 +0,0 @@ -name: Prebuilt mozjs release - -on: - push: - branches: [main] - -env: - RUST_BACKTRACE: 1 - SHELL: /bin/bash - CARGO_INCREMENTAL: 0 - MOZJS_CREATE_ARCHIVE: 1 - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: ${{ github.repository_owner }}/mozjs - -jobs: - mac-arm: - runs-on: macos-14 - needs: create-release - strategy: - fail-fast: false - matrix: - features: ["--features streams"] - env: - RUSTC_WRAPPER: sccache - CCACHE: sccache - SCCACHE_GHA_ENABLED: "true" - RELEASE_ID: ${{ needs.create-release.outputs.release-id }} - steps: - - uses: actions/checkout@v4 - - name: Install deps - run: | - # Unlink and re-link to prevent errors when github mac runner images - # https://github.com/actions/setup-python/issues/577 - brew list -1 | grep python | while read formula; do brew unlink $formula; brew link --overwrite $formula; done - brew install llvm yasm - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.3 - - name: Build - run: | - cargo build --verbose ${{ matrix.features }} - cargo test --tests --examples --verbose ${{ matrix.features }} - - name: Upload release asset - run: | - curl -L \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -H "Content-Type: application/octet-stream" \ - "https://uploads.github.com/repos/${REPO}/releases/${RELEASE_ID}/assets?name=libmozjs-aarch64-apple-darwin.tar.gz" \ - --data-binary "@target/libmozjs-aarch64-apple-darwin.tar.gz" - - mac-x86_64: - runs-on: macos-13 - needs: create-release - strategy: - fail-fast: false - matrix: - features: ["--features streams"] - env: - RUSTC_WRAPPER: sccache - CCACHE: sccache - SCCACHE_GHA_ENABLED: "true" - RELEASE_ID: ${{ needs.create-release.outputs.release-id }} - steps: - - uses: actions/checkout@v4 - - name: Install deps - run: | - # Unlink and re-link to prevent errors when github mac runner images - # https://github.com/actions/setup-python/issues/577 - brew list -1 | grep python | while read formula; do brew unlink $formula; brew link --overwrite $formula; done - brew install llvm yasm - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.3 - - name: Build - run: | - cargo build --verbose ${{ matrix.features }} - cargo test --tests --examples --verbose ${{ matrix.features }} - - name: Upload release asset - run: | - curl -L \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -H "Content-Type: application/octet-stream" \ - "https://uploads.github.com/repos/${REPO}/releases/${RELEASE_ID}/assets?name=libmozjs-x86_64-apple-darwin.tar.gz" \ - --data-binary "@target/libmozjs-x86_64-apple-darwin.tar.gz" - - linux: - env: - RUSTC_WRAPPER: "sccache" - CCACHE: sccache - SCCACHE_GHA_ENABLED: "true" - runs-on: ubuntu-latest - needs: create-release - strategy: - fail-fast: false - matrix: - features: ["--features streams"] - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - name: Install deps - run: | - sudo apt install llvm -y - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.3 - - name: Build - run: | - cargo build --verbose ${{ matrix.features }} - cargo test --tests --examples --verbose ${{ matrix.features }} - - name: Upload release asset - env: - RELEASE_ID: ${{ needs.create-release.outputs.release-id }} - run: | - curl -L \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -H "Content-Type: application/octet-stream" \ - "https://uploads.github.com/repos/${REPO}/releases/${RELEASE_ID}/assets?name=libmozjs-x86_64-unknown-linux-gnu.tar.gz" \ - --data-binary "@target/libmozjs-x86_64-unknown-linux-gnu.tar.gz" - - windows: - runs-on: windows-latest - needs: create-release - strategy: - fail-fast: false - matrix: - features: ["--features streams"] - env: - LINKER: "lld-link.exe" - CC: "clang-cl" - CXX: "clang-cl" - MOZTOOLS_PATH: "${{ github.workspace }}\\target\\dependencies\\moztools-4.0" - CCACHE: sccache - SCCACHE_GHA_ENABLED: "true" - RELEASE_ID: ${{ needs.create-release.outputs.release-id }} - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - with: - targets: ${{ matrix.target }} - - name: Install deps - run: | - curl -SL "https://github.com/servo/servo-build-deps/releases/download/msvc-deps/moztools-4.0.zip" --create-dirs -o target/dependencies/moztools.zip - cd target/dependencies && unzip -qo moztools.zip -d . - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.3 - - name: Build Windows - shell: cmd - run: | - cargo build --verbose ${{ matrix.features }} - cargo test --tests --examples --verbose ${{ matrix.features }} - - name: Upload release asset - uses: actions/upload-release-asset@v1 - with: - upload_url: https://uploads.github.com/repos/${{ github.repository_owner }}/mozjs/releases/${{ needs.create-release.outputs.release-id }}/assets{?name,label} - asset_path: ./target/libmozjs-x86_64-pc-windows-msvc.tar.gz - asset_name: libmozjs-x86_64-pc-windows-msvc.tar.gz - asset_content_type: application/tar+gzip - - create-release: - runs-on: ubuntu-latest - steps: - - name: Create release - id: create-release - run: | - NIGHTLY_TAG=$(date "+%F") - RELEASE_URL=$(gh release create "${NIGHTLY_TAG}" \ - --draft \ - --title "${NIGHTLY_TAG}" \ - --notes 'Version release based on servo/mozjs@${{ github.sha }}' \ - --repo ${REPO}) - TEMP_TAG=$(basename "$RELEASE_URL") - RELEASE_ID=$( \ - gh api -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "/repos/${REPO}/releases/tags/${TEMP_TAG}" \ - | jq '.id' \ - ) - echo "RELEASE_ID=${RELEASE_ID}" >> ${GITHUB_OUTPUT} - outputs: - release-id: ${{ steps.create-release.outputs.RELEASE_ID }} - - publish-release: - name: Result - runs-on: ubuntu-latest - needs: - ["create-release", "mac-arm", "mac-x86_64", "linux", "windows"] - if: ${{ always() }} - env: - RELEASE_ID: ${{ needs.create-release.outputs.release-id }} - steps: - - name: Publish as latest (success) - if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} - run: | - gh api \ - --method PATCH \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${REPO}/releases/${RELEASE_ID} \ - -F draft=false - - name: Publish as latest (failure) - if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} - run: | - gh api \ - --method PATCH \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${REPO}/releases/${RELEASE_ID} \ - -F prerelease=true -F draft=false - - diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8ee0a1c5f3c..7e6f3c7c46a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,14 +15,20 @@ env: RUST_BACKTRACE: 1 SHELL: /bin/bash CARGO_INCREMENTAL: 0 + MOZJS_CREATE_ARCHIVE: 1 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository_owner }}/mozjs jobs: mac: - runs-on: macos-13 strategy: fail-fast: false matrix: - features: ["--features debugmozjs", ""] + features: ["--features debugmozjs", "--features streams"] + platform: + - { target: aarch64-apple-darwin, os: macos-14 } + - { target: x86_64-apple-darwin, os: macos-13 } + runs-on: ${{ matrix.platform.os }} env: RUSTC_WRAPPER: sccache CCACHE: sccache @@ -41,6 +47,12 @@ jobs: run: | cargo build --verbose ${{ matrix.features }} cargo test --tests --examples --verbose ${{ matrix.features }} + - name: Upload artifact + if: ${{ contains(matrix.features, '--features streams') }} + uses: actions/upload-artifact@v4 + with: + path: ./target/libmozjs-${{ matrix.platform.target }}.tar.gz + name: libmozjs-${{ matrix.platform.target }}.tar.gz linux: env: RUSTC_WRAPPER: "sccache" @@ -50,7 +62,7 @@ jobs: strategy: fail-fast: false matrix: - features: ["--features debugmozjs", ""] + features: ["--features debugmozjs", "--features streams"] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -65,17 +77,23 @@ jobs: cargo test --tests --examples --verbose ${{ matrix.features }} - name: Check wrappers integrity # we generate wrappers only without debugmozjs - if: ${{ matrix.features == '' }} + if: ${{ matrix.features == '--features streams' }} run: | bash ./mozjs/src/generate_wrappers.sh git diff --quiet --exit-code + - name: Upload artifact + if: ${{ contains(matrix.features, '--features streams') }} + uses: actions/upload-artifact@v4 + with: + path: ./target/libmozjs-x86_64-unknown-linux-gnu.tar.gz + name: libmozjs-x86_64-unknown-linux-gnu.tar.gz windows: runs-on: windows-latest strategy: fail-fast: false matrix: - features: ["--features debugmozjs", ""] + features: ["--features debugmozjs", "--features streams"] target: ["x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"] env: LINKER: "lld-link.exe" @@ -104,6 +122,12 @@ jobs: shell: cmd run: | cargo test --tests --examples --verbose --target ${{ matrix.target }} ${{ matrix.features }} + - name: Upload artifact + if: ${{ contains(matrix.features, '--features streams') }} + uses: actions/upload-artifact@v4 + with: + path: ./target/${{ matrix.target }}/libmozjs-x86_64-pc-windows-msvc.tar.gz + name: libmozjs-x86_64-pc-windows-msvc.tar.gz android: runs-on: ubuntu-latest @@ -178,3 +202,55 @@ jobs: - name: Mark the job as unsuccessful if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} run: exit 1 + + # create-release: + # runs-on: ubuntu-latest + # if: github.ref == 'refs/heads/main' && github.event_name == 'push' + # steps: + # - name: Create release + # id: create-release + # run: | + # NIGHTLY_TAG=$(date "+%F") + # RELEASE_URL=$(gh release create "${NIGHTLY_TAG}" \ + # --draft \ + # --title "${NIGHTLY_TAG}" \ + # --notes 'Version release based on servo/mozjs@${{ github.sha }}' \ + # --repo ${REPO}) + # TEMP_TAG=$(basename "$RELEASE_URL") + # RELEASE_ID=$( \ + # gh api -H "Accept: application/vnd.github+json" \ + # -H "X-GitHub-Api-Version: 2022-11-28" \ + # "/repos/${REPO}/releases/tags/${TEMP_TAG}" \ + # | jq '.id' \ + # ) + # echo "RELEASE_ID=${RELEASE_ID}" >> ${GITHUB_OUTPUT} + # outputs: + # release-id: ${{ steps.create-release.outputs.RELEASE_ID }} + + # publish-release: + # name: Result + # runs-on: ubuntu-latest + # needs: + # ["create-release", "mac", "linux", "windows"] + # if: github.ref == 'refs/heads/main' && github.event_name == 'push' + # env: + # RELEASE_ID: ${{ needs.create-release.outputs.release-id }} + # steps: + # - name: Publish as latest (success) + # if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} + # run: | + # gh api \ + # --method PATCH \ + # -H "Accept: application/vnd.github+json" \ + # -H "X-GitHub-Api-Version: 2022-11-28" \ + # /repos/${REPO}/releases/${RELEASE_ID} \ + # -F draft=false + # - name: Publish as latest (failure) + # if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + # run: | + # gh api \ + # --method PATCH \ + # -H "Accept: application/vnd.github+json" \ + # -H "X-GitHub-Api-Version: 2022-11-28" \ + # /repos/${REPO}/releases/${RELEASE_ID} \ + # -F prerelease=true -F draft=false From 7c1b25af2917e9f1effb775fef18a23906916444 Mon Sep 17 00:00:00 2001 From: Wu Wayne Date: Thu, 29 Feb 2024 20:48:20 +0900 Subject: [PATCH 5/5] Add release steps --- .github/workflows/rust.yml | 139 +++++++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 54 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7e6f3c7c46a..6875ae423f7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,8 +15,8 @@ env: RUST_BACKTRACE: 1 SHELL: /bin/bash CARGO_INCREMENTAL: 0 - MOZJS_CREATE_ARCHIVE: 1 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MOZJS_CREATE_ARCHIVE: 1 REPO: ${{ github.repository_owner }}/mozjs jobs: @@ -29,10 +29,12 @@ jobs: - { target: aarch64-apple-darwin, os: macos-14 } - { target: x86_64-apple-darwin, os: macos-13 } runs-on: ${{ matrix.platform.os }} + needs: create-draft-release env: RUSTC_WRAPPER: sccache CCACHE: sccache SCCACHE_GHA_ENABLED: "true" + RELEASE_ID: ${{ needs.create-draft-release.outputs.release-id }} steps: - uses: actions/checkout@v4 - name: Install deps @@ -53,12 +55,23 @@ jobs: with: path: ./target/libmozjs-${{ matrix.platform.target }}.tar.gz name: libmozjs-${{ matrix.platform.target }}.tar.gz + - name: Upload release asset + if: ${{ contains(matrix.features, '--features streams') && needs.create-draft-release.outputs.release-id != '' }} + uses: actions/upload-release-asset@v1 + with: + upload_url: https://uploads.github.com/repos/${{ github.repository_owner }}/mozjs/releases/${{ needs.create-draft-release.outputs.release-id }}/assets{?name,label} + asset_path: ./target/libmozjs-${{ matrix.platform.target }}.tar.gz + asset_name: libmozjs-${{ matrix.platform.target }}.tar.gz + asset_content_type: application/tar+gzip + linux: env: RUSTC_WRAPPER: "sccache" CCACHE: sccache SCCACHE_GHA_ENABLED: "true" + RELEASE_ID: ${{ needs.create-draft-release.outputs.release-id }} runs-on: ubuntu-latest + needs: create-draft-release strategy: fail-fast: false matrix: @@ -87,9 +100,18 @@ jobs: with: path: ./target/libmozjs-x86_64-unknown-linux-gnu.tar.gz name: libmozjs-x86_64-unknown-linux-gnu.tar.gz + - name: Upload release asset + if: ${{ contains(matrix.features, '--features streams') && needs.create-draft-release.outputs.release-id != '' }} + uses: actions/upload-release-asset@v1 + with: + upload_url: https://uploads.github.com/repos/${{ github.repository_owner }}/mozjs/releases/${{ needs.create-draft-release.outputs.release-id }}/assets{?name,label} + asset_path: ./target/libmozjs-x86_64-unknown-linux-gnu.tar.gz + asset_name: libmozjs-x86_64-unknown-linux-gnu.tar.gz + asset_content_type: application/tar+gzip windows: runs-on: windows-latest + needs: create-draft-release strategy: fail-fast: false matrix: @@ -102,6 +124,7 @@ jobs: MOZTOOLS_PATH: "${{ github.workspace }}\\target\\dependencies\\moztools-4.0" CCACHE: sccache SCCACHE_GHA_ENABLED: "true" + RELEASE_ID: ${{ needs.create-draft-release.outputs.release-id }} steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -128,6 +151,14 @@ jobs: with: path: ./target/${{ matrix.target }}/libmozjs-x86_64-pc-windows-msvc.tar.gz name: libmozjs-x86_64-pc-windows-msvc.tar.gz + - name: Upload release asset + if: ${{ !contains(matrix.target, 'aarch64') && contains(matrix.features, '--features streams') && needs.create-draft-release.outputs.release-id != '' }} + uses: actions/upload-release-asset@v1 + with: + upload_url: https://uploads.github.com/repos/${{ github.repository_owner }}/mozjs/releases/${{ needs.create-draft-release.outputs.release-id }}/assets{?name,label} + asset_path: ./target/${{ matrix.target }}/libmozjs-x86_64-pc-windows-msvc.tar.gz + asset_name: libmozjs-x86_64-pc-windows-msvc.tar.gz + asset_content_type: application/tar+gzip android: runs-on: ubuntu-latest @@ -189,11 +220,63 @@ jobs: run: | git diff --staged --no-ext-diff --quiet --exit-code + create-draft-release: + runs-on: ubuntu-latest + steps: + - name: Create draft release + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + id: create-release + run: | + NIGHTLY_TAG=$(date "+%F") + RELEASE_URL=$(gh release create "${NIGHTLY_TAG}" \ + --draft \ + --title "${NIGHTLY_TAG}" \ + --notes 'Version release based on servo/mozjs@${{ github.sha }}' \ + --repo ${REPO}) + TEMP_TAG=$(basename "$RELEASE_URL") + RELEASE_ID=$( \ + gh api -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/${REPO}/releases/tags/${TEMP_TAG}" \ + | jq '.id' \ + ) + echo "RELEASE_ID=${RELEASE_ID}" >> ${GITHUB_OUTPUT} + outputs: + release-id: ${{ steps.create-release.outputs.RELEASE_ID }} + + publish-release: + name: Publish release + runs-on: ubuntu-latest + needs: + ["create-draft-release", "mac", "linux", "windows"] + env: + RELEASE_ID: ${{ needs.create-draft-release.outputs.release-id }} + steps: + - name: Publish as latest (success) + if: ${{ needs.create-draft-release.outputs.release-id != '' && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} + run: | + gh api \ + --method PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${REPO}/releases/${RELEASE_ID} \ + -F draft=false + - name: Publish as latest (failure) + if: ${{ needs.create-draft-release.outputs.release-id != '' && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }} + run: | + gh api \ + --method PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${REPO}/releases/${RELEASE_ID} \ + -F prerelease=true -F draft=false + exit 1 + build_result: name: Result runs-on: ubuntu-latest needs: - ["android", "linux", "linux-cross-compile", "mac", "windows", "integrity"] + ["android", "linux", "linux-cross-compile", "mac", "windows", "integrity", "create-draft-release", "publish-release"] if: ${{ always() }} steps: - name: Mark the job as successful @@ -202,55 +285,3 @@ jobs: - name: Mark the job as unsuccessful if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} run: exit 1 - - # create-release: - # runs-on: ubuntu-latest - # if: github.ref == 'refs/heads/main' && github.event_name == 'push' - # steps: - # - name: Create release - # id: create-release - # run: | - # NIGHTLY_TAG=$(date "+%F") - # RELEASE_URL=$(gh release create "${NIGHTLY_TAG}" \ - # --draft \ - # --title "${NIGHTLY_TAG}" \ - # --notes 'Version release based on servo/mozjs@${{ github.sha }}' \ - # --repo ${REPO}) - # TEMP_TAG=$(basename "$RELEASE_URL") - # RELEASE_ID=$( \ - # gh api -H "Accept: application/vnd.github+json" \ - # -H "X-GitHub-Api-Version: 2022-11-28" \ - # "/repos/${REPO}/releases/tags/${TEMP_TAG}" \ - # | jq '.id' \ - # ) - # echo "RELEASE_ID=${RELEASE_ID}" >> ${GITHUB_OUTPUT} - # outputs: - # release-id: ${{ steps.create-release.outputs.RELEASE_ID }} - - # publish-release: - # name: Result - # runs-on: ubuntu-latest - # needs: - # ["create-release", "mac", "linux", "windows"] - # if: github.ref == 'refs/heads/main' && github.event_name == 'push' - # env: - # RELEASE_ID: ${{ needs.create-release.outputs.release-id }} - # steps: - # - name: Publish as latest (success) - # if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} - # run: | - # gh api \ - # --method PATCH \ - # -H "Accept: application/vnd.github+json" \ - # -H "X-GitHub-Api-Version: 2022-11-28" \ - # /repos/${REPO}/releases/${RELEASE_ID} \ - # -F draft=false - # - name: Publish as latest (failure) - # if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} - # run: | - # gh api \ - # --method PATCH \ - # -H "Accept: application/vnd.github+json" \ - # -H "X-GitHub-Api-Version: 2022-11-28" \ - # /repos/${REPO}/releases/${RELEASE_ID} \ - # -F prerelease=true -F draft=false