-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (120 loc) · 4.06 KB
/
ci.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
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
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
PR_NUMBER: '${{ github.event.number }}'
SOURCE_BRANCH: $GITHUB_HEAD_REF
FIXER_BRANCH: auto-fixed/$GITHUB_HEAD_REF
TITLE: 'chore: apply fixes from JS-CS-Fixer'
DESCRIPTION: This merge request applies JS code style fixes from an analysis carried out through GitHub Actions.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
lint:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18.x]
os: [ubuntu-latest]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Enable Corepack
run: corepack enable
- name: Install Dependencies
run: pnpm install
- name: Lint
run: cd .stacks && pnpm run lint
typecheck:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18.x]
os: [ubuntu-latest]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Enable Corepack
run: corepack enable
- name: Install dependencies
run: pnpm install
- name: Typecheck
run: pnpm run test:types
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18.x]
os: [ubuntu-latest]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Enable Corepack
run: corepack enable
- name: Install Dependencies
run: pnpm install
- name: Test Suite
run: pnpm run test
# you may need to "Allow GitHub Actions to create and approve pull requests"
# https://stackoverflow.com/questions/72376229/github-actions-is-not-permitted-to-create-or-approve-pull-requests-createpullre
js-cs-fixer:
if: github.event_name == 'pull_request' && ! startsWith(github.ref, 'refs/heads/auto-fixed/')
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18]
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Enable Corepack
run: corepack enable
- name: Install Dependencies
run: pnpm install
- name: Prepare Git User
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "[email protected]"
git checkout -B "${{ env.FIXER_BRANCH }}"
- name: Apply auto-fixers
run: pnpm lint:fix
- name: Create Fixer PR
run: |
if [[ -z $(git status --porcelain) ]]; then
echo "Nothing to fix... Exiting."
exit 0
fi
OPEN_PRS=`curl --silent -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open"`
OPEN_FIXER_PRS=`echo ${OPEN_PRS} | grep -o "\"ref\": \"${{ env.FIXER_BRANCH }}\"" | wc -l`
git commit -am "${{ env.TITLE }}"
git push origin "${{ env.FIXER_BRANCH }}" --force
if [ ${OPEN_FIXER_PRS} -eq "0" ]; then
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/pulls" \
-d "{ \"head\":\"${{ env.FIXER_BRANCH }}\", \"base\":\"${{ env.SOURCE_BRANCH }}\", \"title\":\"${{ env.TITLE }}\", \"body\":\"${{ env.DESCRIPTION }}\n\nTriggered by #${{ env.PR_NUMBER }}\" }"
fi
exit 1