-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (61 loc) · 1.99 KB
/
upload-badge.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
name: Upload Badge
on:
workflow_dispatch:
inputs:
label:
description: 'Label for the badge'
required: true
default: 'Build'
message:
description: 'Message for the badge'
required: true
default: 'Passing'
color:
description: 'Color for the badge'
required: true
default: 'green'
badgeId:
description: 'Id for the badge'
required: true
default: 'build'
permissions:
contents: write
jobs:
CreateBadgeJsonString:
runs-on: ubuntu-latest
outputs:
badgeJsonString: ${{ steps.createBadgeJsonString.outputs.badgeJsonString }}
steps:
- name: Create badge json string
id: createBadgeJsonString
run: |
jsonString="{\"label\": \"${{ github.event.inputs.label }}\", \"message\": \"${{ github.event.inputs.message }}\", \"color\": \"${{ github.event.inputs.color }}\"}"
echo $jsonString
echo "badgeJsonString=$jsonString" >> $GITHUB_OUTPUT
PushJsonFile:
needs: CreateBadgeJsonString
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: CreateJsonFile
id: createJsonFile
run: |
badgeFileName="${{ github.event.inputs.badgeId }}.json"
folderName=$(dirname "$badgeFileName")
mkdir -p "$folderName"
echo '${{ needs.CreateBadgeJsonString.outputs.badgeJsonString }}' > "$badgeFileName"
cat "$badgeFileName"
- name: CommitFiles
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add .
if [[ "$(git diff-index -p HEAD --)" != "" ]]; then
git commit -m "Add badge ${{ github.event.inputs.badgeId }}"
git push origin HEAD:main
else
echo "Badges unchanged. Skipping."
fi