4.8.1 #509
Workflow file for this run
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: Publish Package to npmjs | |
on: | |
release: | |
types: [published] | |
jobs: | |
validate-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions-ecosystem/action-regex-match@v2 | |
id: tag-match | |
with: | |
text: ${{ github.event.release.tag_name }} | |
regex: '^\d+\.\d+\.\d+$' | |
- run: echo "Please create tag for release with format like 4.0.1" && exit 1 | |
if: ${{ steps.tag-match.outputs.match == '' }} | |
# Old create-checkly versions still look for the tag with a `v` prefix. | |
# We can automatically push the necessary tag to keep those working. | |
- name: Create tag for old create-checkly versions | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/v${{ github.event.release.tag_name }}', | |
sha: context.sha | |
}) | |
# Build package and publish a prerelease | |
prerelease: | |
needs: validate-tag | |
permissions: | |
id-token: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
# Setup .npmrc file to publish to npm | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '16.x' | |
registry-url: 'https://registry.npmjs.org' | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# Ensure that the README is published with the package | |
- run: rm -f packages/cli/README.md && cp README.md packages/cli | |
- run: npm ci | |
- name: Add SHORT_SHA env property with commit short sha | |
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
- name: Set version and publish prerelease for 'cli' package | |
run: | | |
npm --no-git-tag-version version ${{ github.event.release.tag_name }}-prerelease-${{ env.SHORT_SHA }} --workspace packages/cli | |
npm publish --provenance --workspace packages/cli --tag prerelease | |
- name: Set version and publish prerelease for 'create-cli' package | |
run: | | |
npm --no-git-tag-version version ${{ github.event.release.tag_name }}-prerelease-${{ env.SHORT_SHA }} --workspace packages/create-cli | |
npm publish --provenance --workspace packages/create-cli --tag prerelease | |
- name: Output prerelease packages versions | |
run: | | |
npm pkg get version --workspace packages/cli | |
npm pkg get version --workspace packages/create-cli | |
# Slack failure alert | |
- name: Slack Failure Notification | |
if: ${{ failure() }} | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_USERNAME: Checkly Github Bot | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: cli | |
SLACK_ICON: https://github.com/checkly.png?size=48 | |
SLACK_COLOR: ${{ job.status }} | |
SLACK_TITLE: ':red_circle: NPM prerelease failed' | |
SLACK_MESSAGE: by ${{ github.actor }} | |
SLACK_FOOTER: '' | |
# Slack success alert | |
- name: Slack Success Notification | |
if: ${{ success() }} | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_USERNAME: Checkly Github Bot | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: cli | |
SLACK_ICON: https://github.com/checkly.png?size=48 | |
SLACK_COLOR: ${{ job.status }} | |
SLACK_TITLE: ':white_check_mark: NPM prerelease succeeded' | |
SLACK_MESSAGE: by ${{ github.actor }} | |
SLACK_FOOTER: '' | |
# Publish package to NPM | |
release: | |
runs-on: ubuntu-latest | |
environment: production | |
needs: prerelease | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: main | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '16.x' | |
registry-url: 'https://registry.npmjs.org' | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# Ensure that the README is published with the package | |
- run: rm -f packages/cli/README.md && cp README.md packages/cli | |
- run: npm ci | |
- name: Set version and publish 'cli' package | |
run: | | |
npm --no-git-tag-version version ${{ github.event.release.tag_name }} --workspace packages/cli | |
npm publish --provenance --workspace packages/cli | |
- name: Set version and publish 'create-cli' package | |
run: | | |
npm --no-git-tag-version version ${{ github.event.release.tag_name }} --workspace packages/create-cli | |
npm publish --provenance --workspace packages/create-cli | |
- name: Output final packages versions | |
run: | | |
npm pkg get version --workspace packages/cli | |
npm pkg get version --workspace packages/create-cli | |
# Slack failure alert | |
- name: Slack Failure Notification | |
if: ${{ failure() }} | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_USERNAME: Checkly Github Bot | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: cli | |
SLACK_ICON: https://github.com/checkly.png?size=48 | |
SLACK_COLOR: ${{ job.status }} | |
SLACK_TITLE: ':red_circle: NPM publish failed' | |
SLACK_MESSAGE: by ${{ github.actor }} | |
SLACK_FOOTER: '' | |
# Slack success alert | |
- name: Slack Success Notification | |
if: ${{ success() }} | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_USERNAME: Checkly Github Bot | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: cli | |
SLACK_ICON: https://github.com/checkly.png?size=48 | |
SLACK_COLOR: ${{ job.status }} | |
SLACK_TITLE: ':white_check_mark: NPM publish succeeded' | |
SLACK_MESSAGE: by ${{ github.actor }} | |
SLACK_FOOTER: '' |