-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (48 loc) · 1.65 KB
/
ci-tests.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
name: Tests for merging a PR on main
on:
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install dependencies
run: yarn install
- name: Run tests
id: test
run: yarn test
- name: Add label based on test results
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ ${{ steps.test.outcome }} == 'success' ]]; then
LABEL_TO_ADD='ci-passing'
LABEL_TO_REMOVE='ci-failing'
else
LABEL_TO_ADD='ci-failing'
LABEL_TO_REMOVE='ci-passing'
fi
ISSUE_NUMBER=$(echo "${{ github.event.pull_request.url }}" | awk -F/ '{print $NF}')
# Remove the opposite label if it exists
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/labels/$LABEL_TO_REMOVE"
# Add the desired label
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/labels" \
-d "{\"labels\":[\"$LABEL_TO_ADD\"]}"