Skip to content

Commit dcddf02

Browse files
committed
update-badge generic
1 parent 33cd737 commit dcddf02

File tree

2 files changed

+54
-25
lines changed

2 files changed

+54
-25
lines changed

.github/workflows/update-badge.yml

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
workflow_run:
1010
workflows:
1111
- Test Production (e2e)
12+
- Test Dev (e2e)
1213
types:
1314
- completed
1415
branches:
@@ -23,41 +24,67 @@ concurrency:
2324
cancel-in-progress: true
2425

2526
jobs:
26-
update-badge:
27+
update-badge-prod:
2728
runs-on: ubuntu-latest
2829
steps:
2930
- uses: pl-strflt/job-summary-url-action@v1
3031
id: metadata
3132
with:
32-
workflow: test-prod-e2e.yml # ${{ github.event.workflow.path }}
33+
workflow: ${{ github.event.workflow.path }}
3334
run_id: ${{ github.event.workflow_run.id }}
3435
run_attempt: ${{ github.event.workflow_run.run_attempt }}
3536
job: aggregate
3637
- uses: actions/checkout@v3
38+
- id: update
39+
uses: actions/github-script@v6
40+
env:
41+
WORKFLOW_PATH: ${{ github.event.workflow.path }}
42+
BADGE_URL: ${{ github.event.workflow.badge_url }}
43+
SUMMARY_URL: ${{ steps.metadata.outputs.job_summary_url }}
44+
with:
45+
script: |
46+
const fs = require('fs')
47+
48+
const workflowPath = process.env.WORKFLOW_PATH
49+
const badgeURL = process.env.BADGE_URL
50+
const refName = process.env.GITHUB_REF_NAME
51+
const summaryURL = process.env.SUMMARY_URL
52+
53+
console.log(`
54+
workflowPath: ${workflowPath}
55+
badgeURL: ${badgeURL}
56+
refName: ${refName}
57+
summaryURL: ${summaryURL}
58+
`)
59+
60+
function escapeRegExp(string) {
61+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
62+
}
63+
64+
const searchValue = new RegExp(`\\[!\\[([^\\]]+)\\]\\(.*${escapeRegExp(badgeURL)}.*\\)\\]\\(.*\\)`, 'g')
65+
const replaceValue = `[![$1](${badgeURL}?branch=${refName})](${summaryURL})`
66+
67+
console.log(`Searching for: ${searchValue}`)
68+
console.log(`To replace it with: ${replaceValue}`)
69+
70+
const readme = fs.readFileSync('README.md').toString()
71+
const updatedReadme = readme.replace(searchValue, replaceValue)
72+
73+
if (readme !== updatedReadme) {
74+
console.log('Updating README')
75+
fs.writeFileSync('README.md', updatedReadme)
76+
return true
77+
} else {
78+
console.log('README does not need to be updated')
79+
return false
80+
}
3781
# https://github.com/orgs/community/discussions/26560
38-
- run: |
82+
- if: steps.update.outputs.result == 'true'
83+
run: |
3984
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
4085
git config user.name "github-actions[bot]"
41-
- run: |
42-
echo GITHUB_JOB_SUMMARY_URL=${GITHUB_JOB_SUMMARY_URL}
43-
IN='[![Conformance Production Dashboard](https://github.com/ipfs/gateway-conformance/actions/workflows/test-prod-e2e.yml/badge.svg?branch=master)](.*)'
44-
ESCAPED_IN=$(printf '%s\n' "$IN" | sed -e 's/[][\/!&]/\\&/g')
45-
46-
OUT="[![Conformance Production Dashboard](https://github.com/ipfs/gateway-conformance/actions/workflows/test-prod-e2e.yml/badge.svg?branch=master)](${GITHUB_JOB_SUMMARY_URL})"
47-
48-
sed -i "s;${ESCAPED_IN};${OUT};" README.md
49-
env:
50-
GITHUB_JOB_SUMMARY_URL: ${{ steps.metadata.outputs.job_summary_url }}
51-
REPOSITORY: ${{ github.repository }}
52-
- id: git
53-
run: |
54-
if [[ -n $(git diff --shortstat 2> /dev/null | tail -n1) ]]; then
55-
echo "dirty=1" >> $GITHUB_OUTPUT
56-
else
57-
echo "dirty=0" >> $GITHUB_OUTPUT
58-
fi
59-
- if: steps.git.outputs.dirty == '1'
86+
- if: steps.update.outputs.result == 'true'
6087
run: |
6188
git add README.md
62-
git commit -m 'chore: update the link to the dashboard [skip ci]'
63-
git push
89+
git commit -m 'chore: update the link to the interop dashboard [skip ci]'
90+
git push

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
`gateway-conformance` is a tool designed to test if an IPFS Gateway implementation complies with the IPFS Gateway Specification correctly. The tool is distributed as a Docker image, as well as a GitHub Action(s).
44

5-
[![Conformance Production Dashboard](https://github.com/ipfs/gateway-conformance/actions/workflows/test-prod-e2e.yml/badge.svg?branch=master)]()
5+
[![Conformance Production Dashboard](https://github.com/singulargarden/gateway-conformance/workflows/Test%20Dev%20(e2e)/badge.svg?branch=main)]()
6+
7+
[![Conformance Dev Dashboard](https://github.com/singulargarden/gateway-conformance/workflows/Test%20Production%20(e2e)/badge.svg?branch=main)]()
68

79
## Table of Contents
810

0 commit comments

Comments
 (0)