-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (169 loc) · 6.67 KB
/
publish.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# Inspired by: https://dev.to/xcanchal/automatic-versioning-in-a-lerna-monorepo-using-github-actions-4hij
name: Publish
on:
# Runs on pull requests merged into the main and beta branches
pull_request:
types:
- 'closed'
branches:
- 'main'
- 'beta'
# Allow one concurrent deployment
concurrency:
group: "publish"
cancel-in-progress: false
jobs:
packages:
# According to the "on" attribute that we configured, this workflow will trigger on every "Pull Request closed" event
# against beta or main, but what we actually want is to execute it ONLY when the Pull Request has been merged
# (not discarded).
if: github.event.pull_request.merged == true
name: ${{ matrix.registry.name }} package
runs-on: ubuntu-latest
# Allow GitHub Action to read repo and install/publish packages from GitHub Package Registry
permissions:
contents: read
packages: write
# Publish to both NPM and GitHub Package Registry
strategy:
matrix:
registry:
- name: npm
token: NPM_TOKEN
url: https://registry.npmjs.org
- name: GitHub
token: GITHUB_TOKEN
url: https://npm.pkg.github.com
steps:
- uses: actions/checkout@v3
with:
# Lerna needs the git history to automatically bump package versions
fetch-depth: 0
- name: Restore Lerna
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
# Publish to the provided registry...
registry-url: ${{ matrix.registry.url }}
# ...and under the byu-oit scope
scope: '@byu-oit'
# Install and link package dependencies
- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets[matrix.registry.token] }}
# Build the TypeScript outputs
- name: Build distribution packages
run: lerna run build
# Allow Lerna to make commits and create tags for the new versions in the repository. For that, we'll take
# advantage of the "github.actor" variable available in the environment.
- name: Set Git User
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# Lerna Version Command Docs: https://github.com/lerna/lerna/tree/main/libs/commands/version
- name: Beta Version
if: github.base_ref == 'beta'
env:
NODE_AUTH_TOKEN: ${{ secrets[matrix.registry.token] }}
run: lerna version --no-private --no-commit-hooks --no-push --conventional-commits --conventional-prerelease --preid beta --yes
- name: Version
if: github.base_ref == 'main'
env:
NODE_AUTH_TOKEN: ${{ secrets[matrix.registry.token] }}
run: lerna version --no-private --no-commit-hooks --no-push --conventional-commits --conventional-graduate --yes
# Lerna Publish Command Docs: https://github.com/lerna/lerna/tree/main/libs/commands/publish
- name: Publish Package
env:
NODE_AUTH_TOKEN: ${{ secrets[matrix.registry.token] }}
run: lerna publish from-git --yes --no-private
release:
name: GitHub Release
# According to the "on" attribute that we configured, this workflow will trigger on every "Pull Request closed" event
# against beta or main, but what we actually want is to execute it ONLY when the Pull Request has been merged
# (not discarded).
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
needs: [ packages ]
# Allow GitHub Action to read repo and install/publish packages from GitHub Package Registry
permissions:
contents: write
packages: read
steps:
- uses: actions/checkout@v3
with:
# Lerna needs the git history to automatically bump package versions
fetch-depth: 0
- name: Restore Lerna
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
# Allow Lerna to make commits and create tags for the new versions in the repository. For that, we'll take
# advantage of the "github.actor" variable available in the environment.
- name: Set Git User
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor}}@users.noreply.github.com"
# Lerna Version Command Docs: https://github.com/lerna/lerna/tree/main/libs/commands/version
# The difference between this job and the "publish" job is that we add `--create-release github` and removed
# `--no-push` to the lerna version command options.
- name: Publish Beta Releases to GitHub
if: github.base_ref == 'beta'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: lerna version --no-private --no-commit-hooks --conventional-commits --create-release github --conventional-prerelease --preid beta --yes
- name: Publish Releases to GitHub
if: github.base_ref == 'main'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: lerna version --no-private --no-commit-hooks --conventional-commits --create-release github --conventional-graduate --yes
documentation:
name: Docs on GitHub Pages
runs-on: ubuntu-latest
needs: [ packages ]
# Allow GitHub Actions to deploy documentation
permissions:
contents: read
actions: read
id-token: write
pages: write
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Build documentation site
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
- name: Install Dependencies
run: npm ci
- name: Build Pages
run: |
npm run build
npm run docs
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload docs directory
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2