-
Notifications
You must be signed in to change notification settings - Fork 26
74 lines (65 loc) · 2.13 KB
/
test.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
on:
push:
branches:
- '*'
- '!badges'
jobs:
test:
runs-on: ubuntu-latest
name: A job to test this action
steps:
# Get current banch name to use it as dest directory
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_REF#refs/heads/}" >> "${GITHUB_OUTPUT}"
id: extract_branch
- name: Prepare environment
id: coverage
run: |
# Generates a GitHub Workflow output named `lines` with a coverage value
echo "lines=${COVERAGE}" >> "${GITHUB_OUTPUT}"
# Output values to be used by other steps
echo "path=${BADGE_PATH}" >> "${GITHUB_OUTPUT}"
echo "branch=${BRANCH}" >> "${GITHUB_OUTPUT}"
env:
COVERAGE: 53.5%
BADGE_PATH: ${{ steps.extract_branch.outputs.branch }}/test-badge.svg
BRANCH: badges
- uses: actions/checkout@v4
with:
ref: ${{ steps.coverage.outputs.branch }}
# Create the directory where badges will be saved, if needed
- name: Create destination directory
env:
BADGE_PATH: ${{ steps.coverage.outputs.path }}
run: mkdir -p "${BADGE_PATH%/*}"
# Use the output from the `coverage` step
- name: Generate the badge SVG image
uses: emibcn/badge-action@v2.0.2
id: badge
with:
label: 'Test coverage'
status: ${{ steps.coverage.outputs.lines }}
color: 'blue,555,daf'
path: ${{ steps.coverage.outputs.path }}
- name: Upload badge as artifact
uses: actions/upload-artifact@v3
with:
name: badge
path: ${{ steps.coverage.outputs.path }}
if-no-files-found: error
- name: Commit badge
continue-on-error: true
env:
BADGE: ${{ steps.coverage.outputs.path }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add "${BADGE}"
git commit -m "Add/Update badge"
- name: Push badge commit
uses: ad-m/github-push-action@master
if: ${{ success() }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.coverage.outputs.branch }}