-
Notifications
You must be signed in to change notification settings - Fork 2
114 lines (100 loc) · 3.56 KB
/
npm-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
name: npm-publish
concurrency:
group: npm-publish-${{github.sha}}
cancel-in-progress: false
on:
push:
branches:
- main
paths-ignore:
- src/**/*.spec.ts
- .github/**/*
defaults:
run:
working-directory: ./
shell: bash
env:
PUSH_TOKEN: ${{ secrets.GH_TOKEN }}
PACKAGE_TOKEN: ${{ secrets.GH_TOKEN }}
jobs:
check-pusher:
defaults:
run:
working-directory: .
runs-on: ubuntu-latest
outputs:
PUSH_TOKEN_OWNER: ${{steps.push-token-owner.outputs.PUSH_TOKEN_OWNER}}
steps:
- run: |
PUSH_TOKEN_OWNER=`gh api user | jq -r .login`
echo "::set-output name=PUSH_TOKEN_OWNER::$PUSH_TOKEN_OWNER"
echo "PUSH_TOKEN_OWNER is $PUSH_TOKEN_OWNER"
echo "PUSHER is $PUSHER"
id: push-token-owner
env:
GH_TOKEN: ${{ env.PUSH_TOKEN }}
PUSHER: ${{ github.event.pusher.name }}
ci-label-test:
needs: check-pusher
# 봇이 액션을 일으키는 것을 방지 (푸시한 사람이 토큰 OWNER인 경우 작동하지 않음)
if: github.event.pusher.name != needs.check-pusher.outputs.PUSH_TOKEN_OWNER
outputs:
has_ci_skip_label: ${{contains(fromJSON(steps.PR.outputs.pr).labels.*.name, 'ci-skip')}}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: 8BitJonny/gh-get-current-pr@1.1.0
id: PR
with:
github-token: ${{ secrets.GH_TOKEN }}
build:
needs: ci-label-test
if: needs.ci-label-test.outputs.has_ci_skip_label == 'false'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 100 # 최근 100개 커밋에서 package.json 버전변경 확인
token: ${{ env.PUSH_TOKEN }}
- uses: actions/setup-node@v2
with:
node-version: '20'
cache: 'npm'
registry-url: 'https://npm.pkg.github.com'
# Defaults to the user or organization that owns the workflow file
scope: '@day1co'
- name: Version change check
id: version-changed
# package.json 파일의 diff를 확보한 후 `+ "version":` 라인을 확인함.
# GNU grep의 exit 코드에 따른 Github Actions의 Fail 방지를 위해 무조건 true를 리턴하게 함.
run: |
VERSION_CHANGED=$(git diff ${{ github.event.before }}..${{ github.event.after }} package.json | (grep -c -E "^\+\s+\"version\"" || true) )
echo "::set-output name=version_changed::$VERSION_CHANGED"
- name: npm version patch when versionChanged eq 0
if: ${{ steps.version-changed.outputs.version_changed == 0 }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
npm --no-git-tag-version version patch
PACKAGE_NAME=$(jq -r .name package.json)
PACKAGE_VERSION=$(jq -r .version package.json)
git status
git commit -m "$PACKAGE_NAME: bump up to $PACKAGE_VERSION" package.json package-lock.json
git pull --rebase
git push origin
- name: publish
env:
NODE_AUTH_TOKEN: ${{ env.PACKAGE_TOKEN }}
run: |
npm ci
npm publish
CHANGE_LOG=$(git --no-pager log ${{ github.event.before }}..${{ github.event.after }} --pretty=format:"%an - %s")
./.github/npm-publish-slack.sh "$CHANGE_LOG" ${{ secrets.SLACK_WEBHOOK_URL }}