forked from changesets/changesets
-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (126 loc) · 6.04 KB
/
publish.yml
File metadata and controls
148 lines (126 loc) · 6.04 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Publish
on:
push:
branches:
- main
- next
issue_comment:
types: [created]
concurrency: ${{ github.workflow }}-${{ github.event_name == 'issue_comment' && github.event.issue.number || github.ref }}
permissions: {} # each job should define its own permission explicitly
jobs:
publish:
name: Publish
if: github.repository == 'changesets/changesets' && github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: write # to create release (changesets/action)
issues: write # to post issue comments (changesets/action)
pull-requests: write # to create pull request (changesets/action)
id-token: write # to use OpenID Connect token for trusted publishing (changesets/action)
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/ci-setup
with:
node-version: 24
- name: Create Release Pull Request or Publish to npm
# https://github.com/changesets/action
uses: changesets/action@v1
with:
# this expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
version: yarn version-packages
publish_pr:
if: github.repository == 'changesets/changesets' && github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/publish-pr')
timeout-minutes: 20
runs-on: ubuntu-latest
permissions:
contents: read # to checkout the pull request
id-token: write # to use OpenID Connect token for trusted publishing
issues: write # to post comments and reactions
pull-requests: write # to post reactions on PR comments
steps:
- name: Report in-progress reaction
id: report_in_progress
run: |
REACTION_ID=$(gh api /repos/${{github.repository}}/issues/comments/${{github.event.comment.id}}/reactions -f content='eyes' --jq '.id')
echo "in_progress_reaction_id=$REACTION_ID" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if user is authorized to publish
id: check_authorization
run: |
if [[ $AUTHOR_ASSOCIATION == 'MEMBER' || $AUTHOR_ASSOCIATION == 'OWNER' || $AUTHOR_ASSOCIATION == 'COLLABORATOR' ]]
then
echo "User is authorized to publish"
else
echo "User is not authorized to publish"
exit 1
fi
env:
AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
- uses: actions/checkout@v4
- name: Checkout pull request
run: gh pr checkout ${{ github.event.issue.number }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if Version Packages PR
id: check_version_packages
run: |
IS_VERSION_PACKAGES_PR=$(gh pr view ${{ github.event.issue.number }} --json headRefName --jq '.headRefName|startswith("changeset-release/")')
echo "is_version_packages_pr=$IS_VERSION_PACKAGES_PR" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# for Version Packages PR we want to publish the state from before the Version Packages commit
- name: Reset Version Packages PR
if: steps.check_version_packages.outputs.is_version_packages_pr == 'true'
run: git reset --hard HEAD~1
- uses: ./.github/actions/ci-setup
with:
node-version: 24
- name: Compute snapshot version
id: snapshot_version
run: |
PUBLISH_TAG="pr${{ github.event.issue.number }}"
SNAPSHOT_TAG="${PUBLISH_TAG}.$(git rev-parse --short HEAD)"
echo "publish_tag=$PUBLISH_TAG" >> "$GITHUB_OUTPUT"
echo "snapshot_tag=$SNAPSHOT_TAG" >> "$GITHUB_OUTPUT"
echo "version=0.0.0-$SNAPSHOT_TAG" >> "$GITHUB_OUTPUT"
- run: yarn changeset version --snapshot "${{ steps.snapshot_version.outputs.snapshot_tag }}" --snapshot-prerelease-template "{tag}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: yarn build
- name: Publish snapshot versions
run: yarn changeset publish --tag "${{ steps.snapshot_version.outputs.publish_tag }}"
- name: Post comment with published version
run: |
cat <<'BODY' > /tmp/comment-body.md
Published snapshot version `${{ steps.snapshot_version.outputs.version }}` in response to [this comment](${{ github.event.comment.html_url }}).
BODY
gh issue comment "${{ github.event.issue.number }}" --body-file /tmp/comment-body.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post failure comment
if: failure()
run: |
FAILED_JOB_ID=$(gh api "/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs" --jq ".jobs[] | select(.name == \"$GITHUB_JOB\") | .id")
LINK="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${FAILED_JOB_ID}"
cat <<BODY > /tmp/comment-body.md
Snapshot publish triggered by [this comment](${{ github.event.comment.html_url }}) failed. [See the failed job](${LINK}).
BODY
gh issue comment "${{ github.event.issue.number }}" --body-file /tmp/comment-body.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add result reaction
if: always() && steps.report_in_progress.outcome == 'success'
run: |
gh api /repos/${{github.repository}}/issues/comments/${{github.event.comment.id}}/reactions \
-f content="${{ job.status == 'success' && 'rocket' || '-1' }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove in-progress reaction
if: always() && steps.report_in_progress.outcome == 'success'
run: gh api -X DELETE /repos/${{github.repository}}/issues/comments/${{github.event.comment.id}}/reactions/${{steps.report_in_progress.outputs.in_progress_reaction_id}}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}