181 lines (176 loc) · 8.12 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
name: HashiBot Package Publisher
on:
pull_request:
branches:
- master
types: [opened, synchronize, ready_for_review, edited, closed]
jobs:
scan_changed_packages:
name: Scan changed packages
runs-on: ubuntu-latest
outputs:
packageName: ${{ steps.parse_changed.outputs.package_name }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Parse changed packages
id: parse_changed
run: |
echo "::set-output name=package_name::$( echo $(npx lerna changed --json || echo "{}") | jq -r 'if . | length == 1 then .[0].name | tostring else "N/A" end' )"
add_comment:
name: Add warning comment to PR author
runs-on: ubuntu-latest
needs: scan_changed_packages
if: ${{ needs.scan_changed_packages.outputs.packageName == 'N/A' }}
steps:
- name: Comment on PR
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: comments } = await github.issues.listComments({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.pull_request.number,
})
const body = "This pull request cannot be automatically published as we've detected multiple lerna packages have been affected. Please publish manually."
const dup = comments.find(c => c.body === body)
if (dup) {
core.warning('This comment already exists')
process.exit(0)
}
await github.issues.createComment({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.pull_request.number,
body
})
log_package:
name: Log package name
runs-on: ubuntu-latest
needs: scan_changed_packages
if: ${{ needs.scan_changed_packages.outputs.packageName != 'N/A' }}
steps:
- name: Log package name
env:
PACKAGE_NAME: ${{ needs.scan_changed_packages.outputs.packageName }}
run: |
echo "Change detected in package: $PACKAGE_NAME"
verify_description:
name: Verify description
runs-on: ubuntu-latest
needs: scan_changed_packages
outputs:
version: ${{ steps.version.outputs.version }}
releaseNotes: ${{ steps.release_notes.outputs.releaseNotes }}
if: ${{ needs.scan_changed_packages.outputs.packageName != 'N/A' }}
steps:
- name: Get semver keyword
id: version
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get contents of PR description
const prBody = context.payload.pull_request.body
// Parse lines of description
const prBodyLines = prBody.split('\n').map(x => x.trim()).filter(Boolean)
// Ensure version has been selected
const selectedVersion = prBodyLines.filter(x => x.match(/^-\s\[x\].*(major|minor|patch).*$/i))
if (!selectedVersion.length) return core.setFailed('Failed to find required version information! Ensure a SemVer category is selected in the pull request description.')
const [version] = /(major|minor|patch)/i.exec(selectedVersion[0])
if (!version) return core.setFailed('There was an error parsing the version. Please ensure an appropriate version is checked in the pull request description.')
core.setOutput("version", version)
- name: Get release notes
id: release_notes
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get contents of PR description
const prBody = context.payload.pull_request.body
// Parse lines of description
const prBodyLines = prBody.split('\n').map(x => x.trim()).filter(Boolean)
// Detect Release Notes
const releaseNotesStartIdx = prBodyLines.findIndex(line => line.match(/^<summary>release.*$/i))
const releaseNotesEndIdx = prBodyLines.findIndex(line => line.match(/^\<\/details>\s*$/i))
if (!releaseNotesStartIdx || !releaseNotesEndIdx) core.setFailed('Unable to parse release notes. Ensure release notes are included within the pull request description.')
// Extract release notes
const releaseNotes = Array.from({
length: releaseNotesEndIdx - releaseNotesStartIdx - 1
})
.map((_, i) => i + releaseNotesStartIdx + 1)
.map(idx => prBodyLines[idx])
.join('\n')
if (!releaseNotes.length || releaseNotes.startsWith('<!--')) return core.setFailed('Cannot find release notes associated with this pull request!')
core.setOutput("releaseNotes", releaseNotes)
# release_package:
# name: Publish package
# runs-on: ubuntu-latest
# needs: [scan_changed_packages, verify_description]
# if: ${{ needs.scan_changed_packages.outputs.packageName != 'N/A' && github.event.action == 'closed' && github.event.pull_request.merged == true }}
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0
# - run: git checkout master
# - name: Setup Node.js
# uses: actions/setup-node@v1
# with:
# node-version: "12.x"
# registry-url: "https://registry.npmjs.org"
# - run: npm ci --ignore-scripts
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
# - run: npm run vercel-build
# - name: Configure git credentials
# run: |
# git config --global user.email "mktg-dev-github-bot@hashicorp.com"
# git config --global user.name "HashiBot Web"
# - name: Tag major version
# if: ${{ needs.verify_description.outputs.version == 'Major'}}
# run: |
# echo 'VERSION<<EOF' >> $GITHUB_ENV
# ./node_modules/.bin/lerna version major --yes | jq -Rsr 'split(" => ") | .[1] | gsub("[\\n\\t]"; "")' >> $GITHUB_ENV
# echo 'EOF' >> $GITHUB_ENV
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
# - name: Tag minor version
# if: ${{ needs.verify_description.outputs.version == 'Minor'}}
# run: |
# echo 'VERSION<<EOF' >> $GITHUB_ENV
# ./node_modules/.bin/lerna version minor --yes | jq -Rsr 'split(" => ") | .[1] | gsub("[\\n\\t]"; "")' >> $GITHUB_ENV
# echo 'EOF' >> $GITHUB_ENV
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
# - name: Tag patch version
# if: ${{ needs.verify_description.outputs.version == 'Patch'}}
# run: |
# echo 'VERSION<<EOF' >> $GITHUB_ENV
# ./node_modules/.bin/lerna version patch --yes | jq -Rsr 'split(" => ") | .[1] | gsub("[\\n\\t]"; "")' >> $GITHUB_ENV
# echo 'EOF' >> $GITHUB_ENV
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
# - name: Print version
# run: echo $VERSION
# - name: Create GitHub release
# uses: actions/github-script@v2
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# github.repos.createRelease({
# owner: context.payload.repository.owner.login,
# repo: context.payload.repository.name,
# tag_name: `${process.env.PACKAGE_NAME}@${process.env.VERSION}`,
# body: process.env.RELEASE_NOTES,
# draft: false,
# prerelease: false,
# });
# env:
# PACKAGE_NAME: ${{ needs.scan_changed_packages.outputs.packageName }}
# RELEASE_NOTES: ${{ needs.verify_description.outputs.releaseNotes }}
# - name: Publish package
# run: ./node_modules/.bin/lerna publish from-package --yes
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}