Skip to content

Merge pull request #952 from pantheon-systems/KIT-126-snapshot-releas… #4

Merge pull request #952 from pantheon-systems/KIT-126-snapshot-releas…

Merge pull request #952 from pantheon-systems/KIT-126-snapshot-releas… #4

name: Snapshot Release
on:
push:
branches:
- feat/*
pull_request:
branches:
- feat/*
permissions: read-all
jobs:
snapshot_release:
name: Snapshot Release
runs-on: ubuntu-latest
steps:
# ensure the github.actor is a member of the team to prevent unauthorized releases
- name: Check for authorized user
uses: tspascoal/get-user-teams-membership@v3
id: check-authorization
with:
username: ${{ github.actor }}
team: 'decoupled-kit'
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Fail if not authorized
if: steps.check-authorization.outputs.isTeamMember == 'false'
run: exit 1
- name: Checkout code
uses: actions/checkout@v3
- name: Setup node and pmpm
uses: ./.github/actions/setup-node
with:
pnpm: 'true'
# there is no action for snapshot releases so we need to add the npm token and run the commands manually
- name: Append npm token to .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
provenance=true
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# https://github.com/changesets/changesets/issues/1195
# Snapshots won't work in pre mode so we exit pre mode
- name: Exit pre mode
run: pnpm changeset pre exit
- name: Version and publish snapshot release
id: version-and-publish
run: |
echo "TAG_NAME=$(basename ${{ github.head_ref || github.ref_name }})" >> $GITHUB_ENV
echo "tag_name=$(basename ${{ github.head_ref || github.ref_name }})" >> $GITHUB_OUTPUT
pnpm changeset version --snapshot $TAG_NAME
pnpm changeset publish --snapshot --no-git-tag --tag $TAG_NAME
- name: Send Slack success message
if: success()
id: slack-success
uses: slackapi/[email protected]
with:
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ github.workflow }} Succeeded :large_green_circle:",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Snapshot release for ${{ steps.version-and-publish.outputs.tag_name }} released to npm"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"action_id": "basic_success_view",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- name: Send Slack failure message
if: failure()
id: slack-failure
uses: slackapi/[email protected]
with:
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ github.workflow }} Failed :red_circle:",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Snapshot release for ${{ steps.version-and-publish.outputs.tag_name }} failed"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"action_id": "basic_failure_view",
"text": {
"type": "plain_text",
"text": "View Job"
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK