-
Notifications
You must be signed in to change notification settings - Fork 3
122 lines (102 loc) · 2.98 KB
/
cicd.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
name: CICD
on: [push]
jobs:
Validate:
runs-on: ubuntu-latest
steps:
- name: Clone Repo
uses: actions/[email protected]
with:
persist-credentials: false
fetch-depth: 0
- name: Set Up NodeJs
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install Dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm test
- name: Build
run: npm run build
- name: Cache Deployment
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: actions/[email protected]
env:
cache-name: deployment-cache
with:
path: './**/*'
key: ${{ github.event.after }}
CheckRelease:
needs: Validate
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Load Deployment
uses: actions/[email protected]
env:
cache-name: deployment-cache
with:
path: './**/*'
key: ${{ github.event.after }}
- name: Check PR Labels
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
npm run release:check
Deploy:
needs: CheckRelease
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Load Deployment
uses: actions/[email protected]
env:
cache-name: deployment-cache
with:
path: './**/*'
key: ${{ github.event.after }}
- name: Configure Git
env:
GH_EMAIL: ${{ secrets.GH_EMAIL }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_USER: ${{ secrets.GH_USER }}
run: |
git config --local user.name "$GH_USER"
git config --local user.email "$GH_EMAIL"
git remote set-url origin "https://x-access-token:[email protected]/$GITHUB_REPOSITORY"
- name: Validate Git Connection
run: |
git ls-remote origin > /dev/null
- name: Create Git Release
run: |
npm run release
- name: Push Git Release
run: |
git push --follow-tags origin $GITHUB_REF
- name: Configure NPM
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm set "//registry.npmjs.org/:_authToken=$NPM_TOKEN"
- name: Publish NPM Package
id: publish
run: |
npm publish
- name: Publish Release Notes
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
npm run release:post
- name: Revert Git Release
if: failure() && steps.publish.outcome == 'failure'
run: |
NEW_TAG=$(git tag --points-at HEAD)
git tag -d $NEW_TAG
git push --delete origin $NEW_TAG
git revert --no-commit HEAD
git commit -m "chore(release): Reverts failed publish $NEW_TAG [skip ci]"
git push origin $GITHUB_REF