Skip to content

Commit

Permalink
Add prebuilt mozjs archive CI (#454)
Browse files Browse the repository at this point in the history
* Add release CI pipeline

* Rename CI pipeline

* Update CI trigger condition

* Merge CI into one file

* Add release steps

* Update widnow target arguments

* Simplify release workflow

* Add release check CI

* Update trigger condition and remove deps

* Add CARGO_TARGET_DIR on Windows job

* Merge all jobs in release into one

* Check from artifact as well

* Extract --features

* Rename MOZJS_ARCHIVE path

* Fix missed matrix.features

* Update release jobs

* Update release tag name and check if exist before release

* Update release job to check remote tags

* Simplify release job steps instead

* Revert latest commit

* Fix tag variable

---------

Co-authored-by: Samson <[email protected]>
  • Loading branch information
wusyong and sagudev authored Mar 9, 2024
1 parent 8190669 commit 20f7934
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 12 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

name: Version Release Check

on:
release:
types: [published]
workflow_call:
inputs:
release-tag:
required: true
type: string

env:
RUST_BACKTRACE: 1
SHELL: /bin/bash
CARGO_INCREMENTAL: 0

jobs:
verify-archive:
strategy:
fail-fast: false
matrix:
platform:
- { target: aarch64-apple-darwin, os: macos-14 }
- { target: x86_64-apple-darwin, os: macos-13 }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
- { target: x86_64-pc-windows-msvc, os: windows-latest }
runs-on: ${{ matrix.platform.os }}
env:
RELEASE_TAG: ${{ github.event_name == 'release' && github.ref_name || inputs.release-tag }}
MOZJS_ARCHIVE: libmozjs-${{ matrix.platform.target }}.tar.gz
steps:
- uses: actions/checkout@v4
- name: Download prebuilt mozjs from artifact
if: ${{ env.RELEASE_TAG == '' }}
uses: actions/download-artifact@v4
with:
name: libmozjs-${{ matrix.platform.target }}.tar.gz
- name: Download prebuilt mozjs from release
if: ${{ env.RELEASE_TAG != '' }}
run: |
curl -L https://github.com/${{ github.repository_owner }}/mozjs/releases/download/${{ env.RELEASE_TAG }}/libmozjs-${{ matrix.platform.target }}.tar.gz -o libmozjs-${{ matrix.platform.target }}.tar.gz
- name: Build
run: |
cargo build --verbose --features streams
cargo test --tests --examples --verbose --features streams
81 changes: 69 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ env:
RUST_BACKTRACE: 1
SHELL: /bin/bash
CARGO_INCREMENTAL: 0
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MOZJS_CREATE_ARCHIVE: 1

jobs:
mac:
runs-on: macos-13
strategy:
fail-fast: false
matrix:
features: ["--features debugmozjs", ""]
features: ["debugmozjs", "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
Expand All @@ -39,8 +44,15 @@ jobs:
uses: mozilla-actions/[email protected]
- name: Build
run: |
cargo build --verbose ${{ matrix.features }}
cargo test --tests --examples --verbose ${{ matrix.features }}
cargo build --verbose --features ${{ matrix.features }}
cargo test --tests --examples --verbose --features ${{ matrix.features }}
- name: Upload artifact
if: ${{ contains(matrix.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"
Expand All @@ -50,7 +62,7 @@ jobs:
strategy:
fail-fast: false
matrix:
features: ["--features debugmozjs", ""]
features: ["debugmozjs", "streams"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -61,21 +73,27 @@ jobs:
uses: mozilla-actions/[email protected]
- name: Build
run: |
cargo build --verbose ${{ matrix.features }}
cargo test --tests --examples --verbose ${{ matrix.features }}
cargo build --verbose --features ${{ matrix.features }}
cargo test --tests --examples --verbose --features ${{ matrix.features }}
- name: Check wrappers integrity
# we generate wrappers only without debugmozjs
if: ${{ matrix.features == '' }}
if: ${{ matrix.features == 'streams' }}
run: |
bash ./mozjs/src/generate_wrappers.sh
git diff --quiet --exit-code
- name: Upload artifact
if: ${{ contains(matrix.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: ["debugmozjs", "streams"]
target: ["x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"]
env:
LINKER: "lld-link.exe"
Expand All @@ -98,12 +116,18 @@ jobs:
- name: Build Windows
shell: cmd
run: |
cargo build --verbose --target ${{ matrix.target }} ${{ matrix.features }}
cargo build --verbose --target ${{ matrix.target }} --features ${{ matrix.features }}
- name: Test Windows
if: ${{ !contains(matrix.target, 'aarch64') }}
shell: cmd
run: |
cargo test --tests --examples --verbose --target ${{ matrix.target }} ${{ matrix.features }}
cargo test --tests --examples --verbose --target ${{ matrix.target }} --features ${{ matrix.features }}
- name: Upload artifact
if: ${{ !contains(matrix.target, 'aarch64') && contains(matrix.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
Expand Down Expand Up @@ -165,11 +189,43 @@ jobs:
run: |
git diff --staged --no-ext-diff --quiet --exit-code
publish-release:
name: Check version and publish release
runs-on: ubuntu-latest
needs:
["linux", "mac", "windows"]
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Publish release if tag doesn't exist
id: check-tag
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
run: |
RELEASE_TAG=mozjs-sys-v$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "mozjs_sys") | .version')
git fetch --tags --quiet
if ! git show-ref --tags --verify --quiet "refs/tags/${RELEASE_TAG}" ; then
gh release create ${RELEASE_TAG} ./*.tar.gz
fi
echo "RELEASE_TAG=${RELEASE_TAG}" >> ${GITHUB_OUTPUT}
outputs:
release-tag: ${{ steps.check-tag.outputs.RELEASE_TAG }}

verify-release:
name: Verify release
needs: publish-release
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
uses: ./.github/workflows/release.yml
with:
release-tag: ${{ needs.publish-release.outputs.release-tag }}

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", "publish-release", "verify-release"]
if: ${{ always() }}
steps:
- name: Mark the job as successful
Expand All @@ -178,3 +234,4 @@ jobs:
- name: Mark the job as unsuccessful
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1

0 comments on commit 20f7934

Please sign in to comment.