Version Packages (#2418) #940
This file contains 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: Release | |
on: | |
push: | |
branches: | |
- main | |
# This workflow will run changesets depending on two different scenarios: | |
# | |
# 1. If we are landing a specific commit into main (Author PR), then | |
# changesets will check if there are changes verifying the Markdown files | |
# generated automatically: | |
# | |
# a) There are new versions and there's NO Release PR, then the changesets | |
# action will create a new Release PR. | |
# | |
# b) There's a Release PR, then the changesets action will update the | |
# existing Release PR with the new commit. | |
# | |
# NOTE: (in both cases, changesets will modify the new version in | |
# package.json for each package, and will remove the MD files as part of the | |
# Release PR). | |
# | |
# 2. If we are landing the Release PR into main, then the changesets action | |
# will publish the changes to npm. | |
# | |
# For more info about this workflow, see: | |
# https://github.com/changesets/action#usage | |
jobs: | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
fetch-depth: 0 | |
- name: Install & cache node_modules | |
uses: Khan/actions@shared-node-cache-v2 | |
with: | |
node-version: 20.x | |
- name: Create Release Pull Request or Publish to npm | |
id: changesets | |
uses: changesets/action@v1 | |
with: | |
publish: yarn publish:ci | |
env: | |
GITHUB_TOKEN: ${{ secrets.KHAN_ACTIONS_BOT_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Send a Slack notification if a publish fails | |
if: failure() | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }} | |
SLACK_MSG_AUTHOR: ${{ github.event.pull_request.user.login }} | |
SLACK_USERNAME: GithubGoose | |
SLACK_ICON_EMOJI: ":goose:" | |
SLACK_MESSAGE: "Something went wrong with the release of ${{ github.event.repository.name }}. \nPlease check the logs → https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
SLACK_TITLE: "Oops! I'm the Bad News Goose!" | |
SLACK_FOOTER: Wonder Blocks Slack Notification | |
MSG_MINIMAL: true | |
- name: Build Slack message | |
id: slack_message | |
if: steps.changesets.outputs.published == 'true' | |
# We have to do this in stages to make sure that the output into the | |
# GITHUB_ENV retains are lines and is valid for updating the env. | |
# This is based on: | |
# - LIVE: https://trstringer.com/github-actions-multiline-strings/ | |
# - ARCHIVE: https://web.archive.org/web/20211017170102/https://trstringer.com/github-actions-multiline-strings/ | |
# - LIVE: https://renehernandez.io/snippets/multiline-strings-as-a-job-output-in-github-actions/ | |
# - ARCHIVE: https://web.archive.org/web/20211115000540/https://renehernandez.io/snippets/multiline-strings-as-a-job-output-in-github-actions/ | |
run: | | |
UPDATED_PACKAGES=$(jq -r '[group_by(.name) | .[] | " - "+.[].name+"@"+.[].version] | join("\n")' <<< '${{ steps.changesets.outputs.publishedPackages }}') | |
UPDATED_PACKAGES="${UPDATED_PACKAGES//'%'/'%25'}" | |
UPDATED_PACKAGES="${UPDATED_PACKAGES//$'\n'/'%0A'}" | |
UPDATED_PACKAGES="${UPDATED_PACKAGES//$'\r'/'%0D'}" | |
echo "::set-output name=updated_packages::$UPDATED_PACKAGES" | |
- name: Send a Slack notification if a publish happens | |
if: steps.changesets.outputs.published == 'true' | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }} | |
SLACK_MSG_AUTHOR: ${{ github.event.pull_request.user.login }} | |
SLACK_USERNAME: GithubGoose | |
SLACK_ICON_EMOJI: ":goose:" | |
SLACK_MESSAGE: "A new version of ${{ github.event.repository.name }} was published! 🎉 \n${{ steps.slack_message.outputs.updated_packages }}\nRelease notes → https://github.com/${{ github.repository }}/releases/" | |
SLACK_TITLE: "New Wonder Blocks release!" | |
SLACK_FOOTER: Wonder Blocks Slack Notification | |
MSG_MINIMAL: true |