-
Notifications
You must be signed in to change notification settings - Fork 585
177 lines (160 loc) · 5.82 KB
/
publish-package-release.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Publish Package Release
on:
workflow_dispatch:
inputs:
tag:
description: Release version tag
required: true
type: string
default: 'latest'
commit:
description: Optional commit to publish from
required: false
type: string
package:
description: 'Package'
required: true
default: 'realm'
type: choice
options:
- '@realm/babel-plugin'
- '@realm/common'
- '@realm/network-transport'
- '@realm/react'
- '@realm/tools'
- '@realm/web'
jobs:
publish-package-release:
runs-on: ubuntu-latest
steps:
- run: echo "Publishing release for ${{inputs.package}}"
- uses: kanga333/[email protected]
name: Map package to environment variables
with:
key: "${{inputs.package}}"
map: |
{
"@realm/babel-plugin": {
"PACKAGE_PATH": "packages/babel-plugin",
"PACKAGE_NAME": "@realm/babel-plugin",
"VERSION_PREFIX": "babel-plugin-",
"RELEASE_TITLE": "Realm Babel Plugin",
"SDK_NAME": "Babel Plugin"
},
"@realm/common": {
"PACKAGE_PATH": "packages/realm-common",
"PACKAGE_NAME": "@realm/common",
"VERSION_PREFIX": "realm-common-",
"RELEASE_TITLE": "Realm Common",
"SDK_NAME": "Common"
},
"@realm/network-transport": {
"PACKAGE_PATH": "packages/realm-network-transport",
"PACKAGE_NAME": "@realm/network-transport",
"VERSION_PREFIX": "realm-network-transport-",
"RELEASE_TITLE": "Realm Network Transport",
"SDK_NAME": "Network Transport"
},
"@realm/react": {
"PACKAGE_PATH": "packages/realm-react",
"PACKAGE_NAME": "@realm/react",
"VERSION_PREFIX": "realm-react-",
"RELEASE_TITLE": "Realm React",
"SDK_NAME": "React"
},
"@realm/tools": {
"PACKAGE_PATH": "packages/realm-tools",
"PACKAGE_NAME": "@realm/tools",
"VERSION_PREFIX": "realm-tools-",
"RELEASE_TITLE": "Realm Tools",
"SDK_NAME": "Tools"
},
"@realm/web": {
"PACKAGE_PATH": "packages/realm-web",
"PACKAGE_NAME": "realm-web",
"VERSION_PREFIX": "realm-web-",
"RELEASE_TITLE": "Realm Web",
"SDK_NAME": "Web"
}
}
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive
ref: ${{ inputs.commit || github.event.pull_request.head.sha }}
- name: Setup node version
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install node modules
run: npm ci --ignore-scripts
- name: Bundle package
run: npm run bundle --workspace=${{env.PACKAGE_NAME}}
- name: Read version
id: get-version
run: |
pkgVersion=$(jq -r .version ${{env.PACKAGE_PATH}}/package.json)
echo "version=$pkgVersion" >> $GITHUB_OUTPUT
shell: bash
- name: Publish ${{env.RELEASE_TITLE}} v${{ steps.get-version.outputs.version }} on NPM
working-directory: ${{env.PACKAGE_PATH}}
run: npm publish --tag '${{ inputs.tag}}'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Find Release PR
uses: juliangruber/[email protected]
id: find-pull-request
with:
branch: ${{ github.ref }}
- name: Merge Pull Request
uses: juliangruber/merge-pull-request-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.find-pull-request.outputs.number }}
method: squash
- name: Checkout base branch (after merge)
uses: actions/checkout@v3
with:
submodules: recursive
ref: ${{ steps.find-pull-request.outputs.base-ref }}
- name: Extract Changelog
run: node scripts/extract-changelog.js ${{ steps.get-version.outputs.version }} ${{ github.workspace }}/${{env.PACKAGE_PATH}}/CHANGELOG.md > EXTRACTED_CHANGELOG.md
- name: Create Github Release
uses: ncipollo/release-action@v1
with:
bodyFile: EXTRACTED_CHANGELOG.md
name: ${{env.RELEASE_TITLE}} v${{ steps.get-version.outputs.version }}
tag: ${{env.VERSION_PREFIX}}v${{ steps.get-version.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
- name: 'Post to #realm-releases'
uses: realm/ci-actions/release-to-slack@v3
with:
changelog: EXTRACTED_CHANGELOG.md
sdk: ${{env.SDK_NAME}}
webhook-url: ${{ secrets.SLACK_RELEASE_WEBHOOK }}
version: ${{ steps.get-version.outputs.version }}
# This job might fail due to failed markdown-to-slack conversion.
continue-on-error: true
- name: Update Changelog
working-directory: ${{ github.workspace }}/${{env.PACKAGE_PATH}}
run: ${{ github.workspace }}/scripts/changelog-header.sh
- name: Create vNext PR
id: vnext-pr
uses: peter-evans/create-pull-request@v4
with:
branch: prepare-${{env.VERSION_PREFIX}}vnext
title: Prepare for ${{env.RELEASE_TITLE}} vNext
body: Update Changelog for vNext
delete-branch: true
commit-message: Prepare for vNext
base: ${{ steps.find-pull-request.outputs.base-ref }}
- name: Merge Pull Request
uses: juliangruber/merge-pull-request-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.vnext-pr.outputs.pull-request-number }}
method: squash