Publish #58
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
| with: | |
| token: ${{ secrets.PAT_RELEASE_PUSH }} # persists the token for pushing to the repo later | |
| - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4 | |
| 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: | | |
| jq ' | |
| .name = "@scratch/scratch-gui-standalone" | | |
| del(.peerDependencies) | | |
| .exports."." = .exports."./standalone" | | |
| del(.exports."./standalone") | |
| ' ./packages/scratch-gui/package.json | npx sponge ./packages/scratch-gui/package.json | |
| 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}}" | |
| - name: Deploy scratch-svg-renderer to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./packages/scratch-svg-renderer/playground | |
| destination_dir: scratch-svg-renderer | |
| full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" | |
| - name: Deploy scratch-render to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./packages/scratch-render/playground | |
| destination_dir: scratch-render | |
| full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" | |
| - name: Deploy scratch-vm to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./packages/scratch-vm/playground | |
| destination_dir: scratch-vm | |
| full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" | |
| - name: Deploy scratch-gui to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./packages/scratch-gui/build | |
| destination_dir: scratch-gui | |
| full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" |