-
Notifications
You must be signed in to change notification settings - Fork 2.9k
160 lines (143 loc) · 5.86 KB
/
Copy pathprerelease.yml
File metadata and controls
160 lines (143 loc) · 5.86 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
149
150
151
152
153
154
155
156
157
158
159
160
name: Prerelease
on:
push:
branches:
# Target release-x.x branches
- "release-*"
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
prerelease:
name: Changesets Prerelease
# Prevents changesets action from creating a PR on forks
if: github.repository == 'apollographql/apollo-client'
runs-on: ubuntu-latest
# Permissions necessary for Changesets to push a new branch and open PRs
# (for automated Version Packages PRs), and request the JWT for provenance.
# More info: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings
permissions:
contents: write
pull-requests: write
id-token: write
outputs:
packages: ${{ steps.changesets.outputs.publishedPackages }}
steps:
- uses: actions/create-github-app-token@v1
id: github-actions-bot-app-token
with:
app-id: 819772
private-key: ${{ secrets.APOLLO_GITHUB_ACTIONS_BOT_PRIVATE_KEY }}
# Check out the repository, using the Github Actions Bot app's token so
# that we can push later.
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ steps.github-actions-bot-app-token.outputs.token }}
# Fetch entire git history so Changesets can generate changelogs
# with the correct commits
fetch-depth: 0
- 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 }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ">=23.6.0"
- name: Install dependencies with cache
uses: bahmutov/npm-install@v1
- name: Check for pre.json file existence
id: check_files
uses: andstor/file-existence-action@v3.0.0
with:
files: ".changeset/pre.json"
- name: Enter prerelease mode (alpha by default)
# If .changeset/pre.json does not exist and we did not recently exit
# prerelease mode, enter prerelease mode with tag alpha
if: steps.check_files.outputs.files_exists == 'false' && !contains(github.event.head_commit.message, 'Exit prerelease')
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
npx changeset pre enter alpha
git add -A
git commit -m 'Enter prerelease mode'
git push
- name: Create prerelease PR
# If .changeset/pre.json exists and we are not currently cutting a
# release after merging a Version Packages PR
if: steps.check_files.outputs.files_exists == 'true' && !startsWith(github.event.head_commit.message, 'Version Packages')
uses: changesets/action@v1
with:
version: npm run changeset-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to npm + GitHub
id: changesets
# Only run publish if we're still in pre mode and the last commit was
# via an automatically created Version Packages PR
if: steps.check_files.outputs.files_exists == 'true' && startsWith(github.event.head_commit.message, 'Version Packages')
uses: changesets/action@v1
with:
version: echo "This step should never version"
publish: npm run changeset-publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
postrelease:
name: Postrelease
runs-on: ubuntu-latest
needs: prerelease
if: needs.prerelease.result == 'success' && fromJSON(needs.prerelease.outputs.packages)[0] != null
strategy:
matrix:
package: ${{ fromJSON(needs.prerelease.outputs.packages) }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ steps.github-actions-bot-app-token.outputs.token }}
- 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 }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ">=23.6.0"
- name: Install dependencies with cache
uses: bahmutov/npm-install@v1
- name: Tag release with next on npm
run: |
if NEXT=$(npm show ${{ matrix.package.name }}@next version) node -e 'process.exit(require("semver").gt(process.env.PUBLISHED,"${{ matrix.package.version }}")?0:1)'; then
npm dist-tag add ${{ matrix.package.name }}@${{ matrix.package.version }} next;
fi
- name: Send a Slack notification on publish
id: slack
uses: slackapi/slack-github-action@v1.27.0
with:
# Slack channel id, channel name, or user id to post message
# See also: https://api.slack.com/methods/chat.postMessage#channels
# You can pass in multiple channels to post to by providing
# a comma-delimited list of channel IDs
channel-id: "C01PS0CB41G"
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "A new version of `${{ matrix.package.name }}` was released: <https://github.com/apollographql/apollo-client/releases/tag/${{ matrix.package.name }}@${{ matrix.package.version }}|v${{ matrix.package.version }}> :rocket:"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}