-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (143 loc) · 5.26 KB
/
publish-intermediate.yml
File metadata and controls
162 lines (143 loc) · 5.26 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
161
162
name: Publish intermediate npm package
on:
workflow_dispatch:
inputs:
pr_number:
description: "Issue or PR number"
required: true
pull_request:
types: [opened, reopened, closed, synchronize, ready_for_review]
branches:
- "beta-4"
jobs:
publish-npm-package:
name: Publish NPM Package
runs-on: ubuntu-latest
if: "!contains(fromJson('[\"cresh-ci\", \"dependabot[bot]\", \"dependabot-preview[bot]\"]'), github.actor)"
outputs:
PR_NUMBER: ${{ env.PR_NUMBER }}
steps:
- name: Checkout Repository
if: github.event.action != 'closed'
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
if: github.event.action != 'closed'
uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'npm'
registry-url: https://npm.pkg.github.com/
scope: '@creshpay'
- name: Issue number
if: github.event.action != 'closed'
id: issue-number
run: |
if [ -z $PR_NUMBER ]; then
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV
else
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
fi
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Build dist
if: github.event.action != 'closed'
run: make
- name: NPM Version
if: github.event.action != 'closed'
id: publish-version
run: |
VERSION=$(cat package.json | jq -r '.version')
SHORT_SHA=$(git rev-parse --short HEAD)
FULL_VERSION=$VERSION-pr${{ env.PR_NUMBER }}.${SHORT_SHA}
npm --no-git-tag-version version ${FULL_VERSION}
echo "::set-output name=VERSION::${FULL_VERSION}"
PACKAGE_NAME=$(cat package.json | jq -r '.name')
echo "::set-output name=PACKAGE_NAME::${PACKAGE_NAME}"
- name: Publish
if: github.event.action != 'closed'
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: make publish
- name: Write comment
uses: actions/github-script@v5
if: github.event.action != 'closed'
env:
VERSION: ${{steps.publish-version.outputs.VERSION}}
PACKAGE_NAME: ${{steps.publish-version.outputs.PACKAGE_NAME}}
with:
script: |
const heading = '🔥🔥🔥 Intermediate npm package 🔥🔥🔥'
const { VERSION, PACKAGE_NAME, PR_NUMBER } = process.env
const comments = (await github.rest.issues.listComments({
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: PR_NUMBER,
})).data
let comment;
for (let i in comments){
if(comments[i] && comments[i].body && comments[i].body.includes(heading)){
comment = comments[i]
break
}
}
const body = `
${heading}
New version: ${VERSION}
To install it: \`npm i ${PACKAGE_NAME}@${VERSION}\`
`
body.replace(/^\s+/gm, '')
if (comment) {
await github.rest.issues.deleteComment({
repo: context.repo.repo,
owner: context.repo.owner,
comment_id: comment.id,
})
}
await github.rest.issues.createComment({
repo: context.repo.repo,
issue_number: PR_NUMBER,
owner: context.repo.owner,
body,
})
clean-npm:
needs:
- publish-npm-package
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get short sha
shell: bash
id: get-short-sha
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
echo "::set-output name=SHORT_SHA::$SHORT_SHA"
- name: Delete previous versions when pushing new one
if: github.event.action == 'synchronize' || github.event_name == 'workflow_dispatch'
uses: creshpay/action-ghcr-batch-delete-versions@v1
with:
github-access-token: ${{ secrets.CI_ADMIN_PKG_TOKEN }}
org: "${{ github.repository_owner }}"
package_name: "ui-elements"
package_type: "npm"
selector: |
type=name;operator=contains;value=-pr${{ needs.publish-npm-package.outputs.PR_NUMBER }}.
excluder: |
type=name;operator=contains;value=-pr${{ needs.publish-npm-package.outputs.PR_NUMBER }}.${{ steps.get-short-sha.outputs.SHORT_SHA }}
dry-run: "0"
- name: Delete images related to the PR when the PR is closed
if: github.event.action == 'closed'
uses: creshpay/action-ghcr-batch-delete-versions@v1
with:
github-access-token: ${{ secrets.CI_ADMIN_PKG_TOKEN }}
org: "${{ github.repository_owner }}"
package_name: "ui-elements"
package_type: "npm"
selector: |
type=name;operator=contains;value=-pr${{ needs.publish-npm-package.outputs.PR_NUMBER }}.
dry-run: "0"