1+ # Workflow to publish crates.io and GitHub releases
2+ # Changes to this workflow must be reviewed carefully!
13name : Publish
24
5+ # Workflow triggers should be strictly controlled,
6+ # as this will trigger publishing to crates.io.
7+ # We only want to publish on the main branch.
38on :
49 push :
510 branches : [main]
@@ -32,16 +37,19 @@ jobs:
3237 - run : ls -l ./*.tar.gz
3338 - name : Publish release if tag doesn't exist
3439 id : check-tag
35- if : ${{ inputs.release }}
3640 run : |
3741 RELEASE_TAG=mozjs-sys-v$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "mozjs_sys") | .version')
3842 git fetch --tags --quiet
3943 if ! git show-ref --tags --verify --quiet "refs/tags/${RELEASE_TAG}" ; then
4044 gh release create ${RELEASE_TAG} ./*.tar.gz
45+ echo "CREATE_RELEASE=true" >> ${GITHUB_OUTPUT}
46+ else
47+ echo "CREATE_RELEASE=false" >> ${GITHUB_OUTPUT}
4148 fi
4249 echo "RELEASE_TAG=${RELEASE_TAG}" >> ${GITHUB_OUTPUT}
4350 outputs :
4451 release-tag : ${{ steps.check-tag.outputs.RELEASE_TAG }}
52+ create-release : ${{ steps.check-tag.outputs.CREATE_RELEASE }}
4553
4654 verify-release :
4755 name : Verify release
5159 with :
5260 release-tag : ${{ needs.publish-github-release.outputs.release-tag }}
5361 rust_version : stable
62+
63+ # Our CI testing ensures that mozjs-sys and mozjs are always bumped together.
64+ # We always publish both versions, since mozjs depends on a speciifc version
65+ # of mozjs-sys
66+ publish-crates-io :
67+ name : Publish to crates.io
68+ runs-on : ubuntu-latest
69+ needs :
70+ - publish-github-release
71+ - verify-release
72+ permissions :
73+ id-token : write
74+ if : ${{ needs.publish-github-release.outputs.create-release }}
75+ steps :
76+ - uses : actions/checkout@v6
77+ - uses : rust-lang/crates-io-auth-action@v1
78+ id : auth
79+ # publish mozjs-sys
80+ - run : cargo publish -p mozjs-sys
81+ env :
82+ CARGO_REGISTRY_TOKEN : ${{ steps.auth.outputs.token }}
83+ # Wait a bit to ensure the release is published
84+ - run : sleep 5
85+ - run : cargo publish -p mozjs
86+ env :
87+ CARGO_REGISTRY_TOKEN : ${{ steps.auth.outputs.token }}
0 commit comments