update contribute #34
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: Preview Release on Comment | |
permissions: | |
contents: read | |
pull-requests: write | |
issues: write | |
statuses: write | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
release: | |
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '[preview_deployment]') | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
steps: | |
# Get GitHub token via the CT Changesets App | |
- name: Generate GitHub token (via CT Changesets App) | |
id: generate_github_token | |
uses: tibdex/[email protected] | |
with: | |
app_id: ${{ secrets.CT_CHANGESETS_APP_ID }} | |
private_key: ${{ secrets.CT_CHANGESETS_APP_PEM }} | |
- name: Get branch of PR | |
uses: xt0rted/pull-request-comment-branch@v1 | |
id: comment-branch | |
- name: Ensure branch name matches 'preview/**' | |
run: | | |
BRANCH_NAME=${{ steps.comment-branch.outputs.head_ref }} | |
if [[ ! "$BRANCH_NAME" =~ ^preview/ ]]; then | |
echo "Branch name does not match 'preview/**'. Exiting workflow." | |
exit 1 | |
fi | |
- name: Set latest commit status as pending | |
uses: myrotvorets/set-commit-status-action@master | |
with: | |
sha: ${{ steps.comment-branch.outputs.head_sha }} | |
token: ${{ steps.generate_github_token.outputs.token }} | |
status: pending | |
- name: Checkout PR branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.comment-branch.outputs.head_ref }} | |
token: ${{ steps.generate_github_token.outputs.token }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
registry-url: https://registry.npmjs.org/ | |
scope: "@commercetools" | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Installing dependencies and building packages | |
uses: ./.github/actions/ci | |
- name: Publishing preview releases to npm registry | |
run: | | |
BRANCH_NAME=${{ steps.comment-branch.outputs.head_ref }} | |
PREVIEW_TAG=$(echo "$BRANCH_NAME" | sed -e 's/^preview\///') | |
pnpm changeset version --snapshot ${PREVIEW_TAG} | |
pnpm changeset publish --tag ${PREVIEW_TAG} | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_github_token.outputs.token }} | |
- name: Post workflow result on PR as a comment | |
if: always() | |
run: | | |
gh issue comment ${{ github.event.issue.number }} \ | |
--body "Release workflow ${{ job.status == 'success' && 'succeeded ✅' || 'failed ❌' }}\nSee details: [Workflow Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set latest commit status as ${{ job.status }} | |
uses: myrotvorets/set-commit-status-action@master | |
if: always() | |
with: | |
sha: ${{ steps.comment-branch.outputs.head_sha }} | |
token: ${{ steps.generate_github_token.outputs.token }} | |
status: ${{ job.status }} |