-
Notifications
You must be signed in to change notification settings - Fork 4
56 lines (50 loc) · 1.62 KB
/
main.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
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install and build
run: yarn
- name: Run Tests
run: yarn test >> coverage.txt
- name: Extract coverage percentage
id: extract_coverage
run: |
COVERAGE=$(awk '/Statements/ {print $3}' coverage.txt | tr -d '%')
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
echo "COVERAGE=$COVERAGE"
- name: Create coverage badge
run: |
# Ensure the COVERAGE environment variable is properly formatted
COVERAGE="${{ env.COVERAGE }}"
# Create the JSON payload
echo "{\"schemaVersion\": 1, \"label\": \"coverage\", \"message\": \"$COVERAGE%\", \"color\": \"brightgreen\"}" > badge.json
# Use curl to post the JSON to Shields.io
curl -X POST -H "Content-Type: application/json" \
-d @badge.json \
https://img.shields.io/endpoint \
-o coverage-badge.json
- name: Configure Git for pushing
run: |
git config user.name "GitHub Action"
git config user.email "action@github.com"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
- name: Commit coverage badge
run: |
mv coverage-badge.json ./coverage.json
git add .
# if ! git diff-index --quiet HEAD; then
git commit -m "Update coverage badge"
git push origin master
# fi
- name: Push changes
run: |
git push origin HEAD:master