Skip to content

Publish

Publish #63

Workflow file for this run

name: Publish
on:
release:
types: [published]
jobs:
ci:
uses: ./.github/workflows/ci.yml
cd:
needs:
- ci
runs-on: ubuntu-latest
steps:
- name: Debug info
run: |
cat <<EOF
Release tag name: ${{ github.event.release.tag_name }}
Release target commit-ish: ${{ github.event.release.target_commitish }}
EOF
- name: Determine NPM tag
id: npm_tag
shell: bash
run: |
case ${{ github.event.release.target_commitish }} in
develop | main | master)
if [[ ${{ github.event.release.prerelease }} == true ]]; then
npm_tag=beta
else
npm_tag=latest
fi
;;
*)
# use the branch name
npm_tag="${{ github.event.release.target_commitish }}"
;;
esac
echo "Determined NPM tag: [$npm_tag]"
echo "npm_tag=${npm_tag}" >> "$GITHUB_OUTPUT"
- name: Check NPM tag
run: |
if [ -z "${{ steps.npm_tag.outputs.npm_tag }}" ]; then
echo "Refusing to publish with empty NPM tag."
exit 1
fi
- name: Config GitHub user
shell: bash
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'github-actions@localhost'
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
with:
token: ${{ secrets.PAT_RELEASE_PUSH }} # persists the token for pushing to the repo later
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- uses: ./.github/actions/install-dependencies
- name: Update the version in the package files
shell: bash
run: |
GIT_TAG="${{github.event.release.tag_name}}"
NEW_VERSION="${GIT_TAG/v/}"
npm version "$NEW_VERSION" --no-git-tag-version
git add package* && git commit -m "chore(release): $NEW_VERSION [skip ci]"
# Install dependencies after the version update so that
# the build outputs refer to the newest version of inner packages
- uses: ./.github/actions/install-dependencies
- name: Publish scratch-svg-renderer
run: |
npm run build --workspace @scratch/scratch-svg-renderer
npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-svg-renderer
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish scratch-render
run: |
npm run build --workspace @scratch/scratch-render
npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-render
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish scratch-vm
run: |
npm run build --workspace @scratch/scratch-vm
npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-vm
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish scratch-gui
run: |
cp ./packages/scratch-gui/package.json ./packages/scratch-gui/package-copy.json
jq 'del(.exports["./standalone"])' ./packages/scratch-gui/package.json | npx sponge ./packages/scratch-gui/package.json
npm run build:dist --workspace @scratch/scratch-gui
npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-gui
mv ./packages/scratch-gui/package-copy.json ./packages/scratch-gui/package.json
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish scratch-gui-standalone
run: |
bash ./scripts/prepare-standalone-gui.sh
npm --workspace=@scratch/scratch-gui-standalone run clean && npm --workspace=@scratch/scratch-gui-standalone run build:dist-standalone
npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-gui-standalone
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Push to develop
shell: bash
run: |
git fetch origin develop
TAG_NAME="${{github.event.release.tag_name}}"
LAST_COMMIT_ID="$(git rev-parse $TAG_NAME)"
DEVELOP_COMMIT_ID="$(git rev-parse origin/develop)"
if [ "$LAST_COMMIT_ID" = "$DEVELOP_COMMIT_ID" ]; then
git push origin HEAD:develop
else
echo "Not pushing to develop because the tag we're operating on is behind"
fi
# See https://stackoverflow.com/a/24849501
- name: Change connected commit on release
shell: bash
run: |
git tag -f "${{github.event.release.tag_name}}" HEAD
git push -f origin "refs/tags/${{github.event.release.tag_name}}"