Release Please #391
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 Please | |
on: | |
schedule: | |
- cron: '0 5 * * *' | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
env: | |
# Set to 'alpha', 'beta', or 'rc' to create a prerelease. | |
PRERELEASE: 'false' | |
MAJOR_VERSION: 11 | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Next release | |
if: ${{ env.PRERELEASE != 'false' }} | |
id: next-release | |
run: | | |
# Log commands and exit on error. | |
set -exo pipefail | |
if [[ "${PRERELEASE}" != "alpha" && "${PRERELEASE}" != "beta" && "${PRERELEASE}" != "rc" ]]; then | |
echo "Invalid PRERELEASE value. Must be 'alpha', 'beta', or 'rc'." | |
exit 1 | |
fi | |
# Get the current prerelease version. | |
ACC="Accept: application/vnd.github+json" | |
VER="X-GitHub-Api-Version: 2022-11-28" | |
JSON='map(.tag_name) | [.[] | select(startswith("${{ env.MAJOR_VERSION }}.")) ] | .[0] // empty' | |
CURRENT_RELEASE=$(gh api -H "${ACC}" -H "${VER}" /repos/${{ github.repository }}/releases | jq -r "${JSON}") | |
# Bump the prerelease version. | |
if [[ -z "$CURRENT_RELEASE" || "$CURRENT_RELEASE" != "${{ env.MAJOR_VERSION }}.0.0-${{ env.PRERELEASE }}."* ]]; then | |
NEXT_VERSION="${{ env.MAJOR_VERSION }}.0.0-${{ env.PRERELEASE }}.0" | |
else | |
NEXT_VERSION=$(npx --yes semver -i prerelease $CURRENT_RELEASE) | |
fi | |
# If version is empty, exit. | |
if [ -z "$NEXT_VERSION" ]; then | |
echo "Not able to determine prerelease version." | |
exit 1 | |
fi | |
echo "Next release version: $NEXT_VERSION" | |
echo "next-release=$NEXT_VERSION" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | |
- uses: google-github-actions/release-please-action@v3 | |
id: release | |
with: | |
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"deprecation","section":"Deprecations","hidden":false}]' | |
release-type: 'node' | |
default-branch: '${{ github.ref_name }}' | |
package-name: 'stache' | |
pull-request-title-pattern: 'chore: release ${version}' | |
labels: 'autorelease ${{ github.ref_name }}: pending' | |
release-labels: 'autorelease ${{ github.ref_name }}: tagged' | |
release-as: '${{ steps.next-release.outputs.next-release }}' | |
prerelease: ${{ env.PRERELEASE != 'false' }} | |
draft-pull-request: true | |
include-v-in-tag: false | |
token: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}' | |
- uses: actions/checkout@v4 | |
with: | |
token: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}' | |
- uses: actions/setup-node@v4 | |
id: setup-node | |
with: | |
node-version-file: '.nvmrc' | |
# Workaround to avoid "Post Run actions/setup-node" failures. | |
# See: https://github.com/actions/setup-node/issues/317 | |
- name: Ensure cache directory exists | |
if: ${{ !steps.release.outputs.release_created }} | |
run: mkdir -p /home/runner/.npm | |
continue-on-error: true | |
- name: Cache node modules | |
if: ${{ steps.release.outputs.release_created }} | |
id: cache | |
uses: actions/cache@v4 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-modules-${{ hashFiles('package-lock.json') }} | |
- name: npm install | |
if: ${{ steps.release.outputs.release_created && steps.cache.outputs.cache-hit != 'true' }} | |
run: npm ci | |
- name: Build | |
if: ${{ steps.release.outputs.release_created }} | |
run: npx skyux-dev create-packages-dist --skipNxCache | |
- name: Publish | |
if: ${{ steps.release.outputs.release_created }} | |
run: npx skyux-dev publish-packages-dist | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Capture logs | |
if: ${{ failure() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: npm-logs | |
path: /home/runner/.npm/_logs | |
retention-days: 3 | |
- name: Notify Slack (success) | |
if: ${{ steps.release.outputs.release_created }} | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: Successfully published Stache ${{ steps.release.outputs.tag_name }} to NPM. http://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/CHANGELOG.md | |
SLACK_ICON: https://github.com/blackbaud.png?size=48 | |
SLACK_USERNAME: Stache | |
- name: Notify Slack (failure) | |
if: ${{ failure() && steps.release.outputs.release_created }} | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_COLOR: ${{ job.status }} | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: Failed to publish Stache ${{ steps.release.outputs.tag_name }} to NPM! | |
SLACK_ICON: https://github.com/blackbaud.png?size=48 | |
SLACK_USERNAME: Stache | |
- name: Notify Slack (failure, non-release) | |
if: ${{ failure() && !steps.release.outputs.release_created }} | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_COLOR: ${{ job.status }} | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: Failed when preparing Stache release! | |
SLACK_ICON: https://github.com/blackbaud.png?size=48 | |
SLACK_USERNAME: Stache | |
#cor-skyux-notifications | |
SLACK_CHANNEL: C01GY7ZP4HM |