forked from libp2p/test-plans
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (69 loc) · 2.5 KB
/
update-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
77
78
79
name: Update Badge
on:
workflow_run:
workflows:
- libp2p transport interop test
types:
- completed
branches:
- master
defaults:
run:
shell: bash
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
env:
BADGE_NAME: Interop Dashboard
jobs:
update-badge:
runs-on: ubuntu-latest
steps:
- id: workflow
env:
WORKFLOW_PATH: ${{ github.event.workflow.path }}
run: echo "name=${WORKFLOW_PATH#.github/workflows/}" >> $GITHUB_OUTPUT
- uses: pl-strflt/job-summary-url-action@v1
id: metadata
with:
workflow: ${{ steps.workflow.outputs.name }}
run_id: ${{ github.event.workflow_run.id }}
run_attempt: ${{ github.event.workflow_run.run_attempt }}
job: latest
- uses: actions/checkout@v3
- id: update
uses: actions/github-script@v6
env:
BADGE_URL: ${{ github.event.workflow.badge_url }}
SUMMARY_URL: ${{ steps.metadata.outputs.job_summary_url }}
with:
script: |
const fs = require('fs')
const badgeName = process.env.BADGE_NAME
const badgeURL = process.env.BADGE_URL
const refName = process.env.GITHUB_REF_NAME
const summaryURL = process.env.SUMMARY_URL
const searchValue = new RegExp(`\\[!\\[${badgeName}\\]\\(.*\\)\\]\\(.*\\)`, 'g')
const replaceValue = `[![${badgeName}](${badgeURL}?branch=${refName})](${summaryURL})`
console.log(`Searching for: ${searchValue}`)
console.log(`To replace it with: ${replaceValue}`)
const readme = fs.readFileSync('README.md').toString()
const updatedReadme = readme.replace(searchValue, replaceValue)
if (readme !== updatedReadme) {
console.log('Updating README')
fs.writeFileSync('README.md', updatedReadme)
return true
} else {
console.log('README does not need to be updated')
return false
}
# https://github.com/orgs/community/discussions/26560
- if: steps.update.outputs.result == 'true'
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
- if: steps.update.outputs.result == 'true'
run: |
git add README.md
git commit -m 'chore: update the link to the interop dashboard [skip ci]'
git push