Skip to content

Commit cfe4abc

Browse files
committed
ci(workflows): use tested continuous-deployment workflow
1 parent 42e90c6 commit cfe4abc

File tree

2 files changed

+87
-34
lines changed

2 files changed

+87
-34
lines changed

.github/workflows/continuous-deployment.yml

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# - https://github.com/actions/github-script
66
# - https://github.com/actions/setup-node
7-
# - https://github.com/devmasx/merge-branch
7+
# - https://github.com/actions-registry/github-repo-sync-upstream
88
# - https://github.com/bdougie/close-issues-based-on-label
99

1010
---
@@ -17,17 +17,21 @@ on:
1717
workflow_dispatch:
1818
inputs:
1919
tag:
20-
description: 'Release tag'
20+
description: release tag
2121
required: true
2222
jobs:
23-
continuous-deployment:
23+
get-deployment-details:
24+
name: Get deployment details
2425
if: |
2526
github.event.inputs.tag ||
2627
(startsWith(github.event.pull_request.head.ref, 'release/')
2728
&& github.event.pull_request.merged == true)
2829
runs-on: ubuntu-latest
30+
outputs:
31+
publish_command: ${{ steps.publish_command.outputs.command }}
32+
tag: ${{ steps.release.outputs.tag }}
2933
steps:
30-
- id: get-release-details
34+
- id: release
3135
name: Get release details
3236
uses: actions/github-script@v4
3337
with:
@@ -39,7 +43,8 @@ jobs:
3943
}
4044
4145
core.exportVariable('tag', tag)
42-
- id: get-publish-command
46+
core.setOutput('tag', tag)
47+
- id: publish_command
4348
name: Get publish command
4449
uses: actions/github-script@v4
4550
with:
@@ -52,20 +57,22 @@ jobs:
5257
5358
dtags = `--access public ${dtags}`.trim()
5459
55-
core.exportVariable('publish_command', `npm publish build ${dtags}`)
56-
- id: publish-release
60+
core.setOutput('command', `npm publish ./build ${dtags}`)
61+
publish-release:
62+
name: Publish GitHub Release
63+
needs: get-deployment-details
64+
runs-on: ubuntu-latest
65+
steps:
66+
- id: publish
5767
name: Publish GitHub release
5868
uses: actions/github-script@v4
5969
with:
60-
github-token: ${{ secrets.PAT_REPO_FLDV_ADMIN }}
6170
script: |
6271
const endpoint = 'GET /repos/{owner}/{repo}/releases'
6372
const releases = await github.paginate(endpoint, context.repo)
6473
65-
const release = releases.find(release => {
66-
console.log(process.env.tag, release)
67-
68-
return release.name.startsWith(process.env.tag)
74+
const release = releases.find(({ name }) => {
75+
return name.startsWith(process.env.tag)
6976
})
7077
7178
if (release && release.draft) {
@@ -76,61 +83,108 @@ jobs:
7683
tag_name: process.env.tag
7784
})
7885
}
86+
publish-package:
87+
name: Publish package to GPR & NPM
88+
needs: [get-deployment-details, publish-release]
89+
runs-on: ubuntu-latest
90+
env:
91+
NPM_TOKEN_FLDV: ${{ secrets.NPM_TOKEN_FLDV }}
92+
PAT_GPR_FLDV: ${{ secrets.PAT_GPR_FLDV }}
93+
steps:
94+
- id: checkout
95+
name: Checkout branch
96+
uses: actions/checkout@v2
97+
with:
98+
ref: ${{ github.head_ref }}
7999
- id: setup-npmrc-gpr
80100
name: Setup .npmrc file [GPR]
81101
uses: actions/setup-node@v2
82102
with:
103+
always-auth: true
104+
cache: yarn
105+
node-version: 16
83106
registry-url: 'https://npm.pkg.github.com'
84107
scope: '@flex-development'
108+
- id: dependencies
109+
name: Install dependencies
110+
run: yarn --immutable
111+
env:
112+
NODE_AUTH_TOKEN: ${{ secrets.PAT_GPR_FLDV }}
113+
- id: build
114+
name: Build project
115+
run: yarn build
116+
env:
117+
NODE_OPTIONS: -r tsconfig-paths/register
85118
- id: publish-to-gpr
86119
name: Publish package [GPR]
87-
run: ${publish_command}
120+
run: ${{ needs.get-deployment-details.outputs.publish_command }}
88121
env:
89122
NODE_AUTH_TOKEN: ${{ secrets.PAT_GPR_FLDV }}
90123
- id: setup-npmrc-npm
91124
name: Setup .npmrc file [NPM]
92125
uses: actions/setup-node@v2
93126
with:
94-
node-version: '14.x'
127+
cache: yarn
128+
node-version: 16
95129
registry-url: 'https://registry.npmjs.org'
96130
scope: '@flex-development'
97131
- id: publish-to-npm
98132
name: Publish package [NPM]
99-
run: ${publish_command}
133+
run: ${{ needs.get-deployment-details.outputs.publish_command }}
100134
env:
101135
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_FLDV }}
102-
- id: update-production-branch
103-
name: Update production branch
104-
uses: devmasx/merge-branch@v1.3.1
136+
update-production-branch:
137+
name: Update production branch
138+
needs: publish-package
139+
runs-on: ubuntu-latest
140+
steps:
141+
- id: checkout
142+
name: Checkout main branch
143+
uses: actions/checkout@v2
144+
with:
145+
ref: main
146+
- id: update
147+
uses: actions-registry/github-repo-sync-upstream@v0.0.2
105148
with:
106-
from_branch: next
107-
github_token: ${{ github.token }}
108-
target_branch: main
109-
type: now
110-
- id: close-merged-issues
111-
name: Close issues with status:merged label
149+
destination_branch: main
150+
source_branch: next
151+
source_repo: ${{ github.repository }}
152+
close-merged-issues:
153+
name: Close issues with status:merged label
154+
needs: update-production-branch
155+
runs-on: ubuntu-latest
156+
steps:
157+
- id: close
112158
uses: bdougie/close-issues-based-on-label@master
113159
env:
114160
GITHUB_TOKEN: ${{ github.token }}
115161
LABEL: status:merged
116-
- id: add-status-released-label
162+
add-status-released-label:
163+
name: Add status:released label to closed issues
164+
needs: close-merged-issues
165+
runs-on: ubuntu-latest
166+
steps:
167+
- id: add
117168
name: Add status:released label to merged issues
118169
uses: actions/github-script@v4
119170
with:
120171
script: |
121172
const opts = github.issues.listForRepo(context.repo)
122173
const issues = await github.paginate(opts)
123174
124-
await Promise.all(issues.map(issue => {
125-
issue.labels && issue.labels.forEach(({ name, number }) => {
126-
if (label.name === 'status:merged') {
175+
Promise.all(issues.map(async issue => {
176+
if (issue.labels) {
177+
const names = issue.labels.map(label => label.name)
178+
179+
const label_add = 'status:released'
180+
const label_check = 'status:merged'
181+
182+
if (!name.includes(label_add) && names.includes(label_check)) {
127183
return await github.issues.addLabels({
128184
...context.repo,
129-
issue_number: number,
130-
labels: ['status:released']
185+
issue_number: issue.number,
186+
labels: [label_add]
131187
})
132188
}
133-
134-
return
135-
})
189+
}
136190
}))

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"access": "public",
2323
"directory": "./build"
2424
},
25-
"files": [],
2625
"main": "./build/esm/index.js",
2726
"module": "./build/cjs/index.js",
2827
"types": "./build/esm/index.d.ts",

0 commit comments

Comments
 (0)