-
Notifications
You must be signed in to change notification settings - Fork 29
122 lines (102 loc) · 3.64 KB
/
ci.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
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: test and release
on:
pull_request:
push:
branches:
- master
jobs:
main:
env:
BASE_BRANCH: master
BASE_REPO_OWNER: MegafonWebLab
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Yarn cache
uses: actions/cache@v2
id: cache-yarn-ci
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Local Node.js modules cache
id: cache-node-modules-ci
uses: actions/cache@v2
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-nodemodules-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Linting commit messages
if: ${{ github.event_name == 'pull_request' }}
run: yarn exec commitlint -- --from=origin/${{ github.base_ref }} --to=HEAD
- name: Build
run: yarn build
- name: Linting sources
run: yarn lint
- name: Typecheck
run: yarn typecheck
- name: Tests
run: yarn test
- name: Define release conditions
id: branch
run: |
if
[ ${{ contains(github.event.head_commit.message, 'skip release') }} = false ] &&
[ ${{ github.event_name }} != pull_request ] &&
[ ${{ github.repository_owner }} = ${{ env.BASE_REPO_OWNER }} ] &&
[ ${{ github.ref }} = refs/heads/${{ env.BASE_BRANCH }} ];
then
echo ::set-output name=should_release::true
else
echo ::set-output name=should_release::false
fi
- name: Configure CI Git User
if: steps.branch.outputs.should_release == 'true'
run: |
git config --global user.name 'Megafon CI'
git config --global user.email '[email protected]'
git remote set-url origin https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY
- name: Authenticate with NPM Registry
if: steps.branch.outputs.should_release == 'true'
run: |
echo "registry=http://registry.npmjs.org/" >> .npmrc
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
npm whoami
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish
if: steps.branch.outputs.should_release == 'true'
run: yarn exec lerna publish -- --yes
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
- name: Generate release info
if: ${{ github.event_name == 'pull_request' }}
env:
PULL_REQUEST_NUMBER: ${{ github.event.number }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PULL_REQUEST_BODY: ${{ github.event.pull_request.body }}
run: node ./.github/get-release-info.js
- name: Upload release info to artifacts
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v2
with:
name: pr-release-info
path: ./release-info-${{ github.event.number }}.txt
if-no-files-found: ignore
retention-days: 1