-
Notifications
You must be signed in to change notification settings - Fork 27
75 lines (63 loc) · 2.45 KB
/
preview-release-on-comment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Preview Release on Comment
permissions:
id-token: write
contents: read
pull-requests: write
issues: 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: Validate branch name
run: |
BRANCH_NAME=${{ steps.comment-branch.outputs.head_ref }}
if [[ ! "$BRANCH_NAME" =~ ^preview/[a-zA-Z0-9_-]+$ ]]; then
echo "Ignoring PR because of the branch name. Exiting workflow."
exit 1
fi
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
token: ${{ steps.generate_github_token.outputs.token }}
- name: Installing dependencies and building packages
uses: ./.github/actions/ci
- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
provenance=true
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- 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 }}