-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (46 loc) · 1.64 KB
/
pr-closed.yaml
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
name: On closing PR
on:
pull_request_target:
types:
- closed
jobs:
unpublish:
name: Unpublish or Deprecate NPM previews for PR
runs-on: ubuntu-latest
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLIC_PUBLISH }}
steps:
- name: Checkout Source Code
uses: actions/checkout@v4
- name: Remove preview consumption comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_preview_consumption
delete: true
GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}
- name: Create .npmrc
# Reference the env variable NPM_TOKEN here, not the secret
run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
- name: Unpublish
run: |
toUnpublish=()
prNumber="${{github.event.number}}"
pkgName="@kong/design-tokens"
npm dist-tag rm "${pkgName}" "pr-${prNumber}" || true
for pkgVersion in $(npm view ${pkgName} --json|jq -r .versions|grep "\-pr.${prNumber}."|sed 's/,//'| sed 's/\"//g')
do
toUnpublish+=("${pkgName}@${pkgVersion}")
done
echo "List: ${toUnpublish[*]}"|sed 's/ /\n/g'
for (( i=${#toUnpublish[@]}-1; i>=0; i-- ))
do
echo ""
echo "*** deprecating: ${toUnpublish[i]}"
npm deprecate --force "${toUnpublish[i]}" "Deprecated PR preview" || true
done
for (( i=${#toUnpublish[@]}-1; i>=0; i-- ))
do
echo ""
echo "unpublishing: ${toUnpublish[i]}"
npm unpublish --force "${toUnpublish[i]}" || true
done