Skip to content

More central release related fixes #2

More central release related fixes

More central release related fixes #2

# NPM registry supports only one source workflow per package: https://docs.npmjs.com/trusted-publishers#for-github-actions
name: Publish packages to the npm registry
on:
pull_request:
push:
branches: ['version-1.*.x']
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
environment: prod
permissions:
contents: read
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: proudust/gh-describe@70f72d4f6304ea053cf5a3d71c36211d5acc0c73
id: ghd
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
cache: 'sbt'
- uses: sbt/setup-sbt@v1
- run: sbt -Dproject.version=${{ steps.ghd.outputs.describe }} --batch ';lang-tests/test;lang-tests-js/test;repl/test;langJS/fullOptJS;replJS/fullOptJS'
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
- if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
run: |
SBT_VERSION=$(awk -F '[".]' '{print $3"."$4"."$5+1}' version.sbt)
PACKAGE_NAME=$(jq --raw-output .name lang/js/package.json)
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
PREID="${{ github.event.number }}-snapshot"
else
PREID="snapshot"
fi
npm version prerelease --preid=$PREID --no-git-tag-version
PREFIX=$SBT_VERSION-$PREID
NEXT=$(npm view $PACKAGE_NAME versions --json \
| jq --raw-output --arg prefix $PREFIX '[.[] | select(startswith($prefix))|capture("snapshot\\.(?<n>[0-9]+)").n|tonumber]|max + 1 // 0')
echo "VERSION=$PREFIX-$NEXT" >> $GITHUB_ENV
echo "TAG=snapshot" >> $GITHUB_ENV
- if: ${{ github.event_name == 'release' }}
run: |
echo "VERSION=$(echo ${{ github.release.tag_name }} | sed 's/^v//')" >> $GITHUB_ENV
echo "TAG=latest" >> $GITHUB_ENV
- run: |
cd lang/js
npm version $VERSION --no-git-tag-version
npm publish --provenance --access public --tag $TAG
cd ../../repl/js
npm version $VERSION --no-git-tag-version
npm publish --provenance --access public --tag $TAG
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_TOKEN }}