Skip to content

Commit

Permalink
update-badge generic
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Jul 28, 2023
1 parent 33cd737 commit dcddf02
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 25 deletions.
75 changes: 51 additions & 24 deletions .github/workflows/update-badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
workflow_run:
workflows:
- Test Production (e2e)
- Test Dev (e2e)
types:
- completed
branches:
Expand All @@ -23,41 +24,67 @@ concurrency:
cancel-in-progress: true

jobs:
update-badge:
update-badge-prod:
runs-on: ubuntu-latest
steps:
- uses: pl-strflt/job-summary-url-action@v1
id: metadata
with:
workflow: test-prod-e2e.yml # ${{ github.event.workflow.path }}
workflow: ${{ github.event.workflow.path }}
run_id: ${{ github.event.workflow_run.id }}
run_attempt: ${{ github.event.workflow_run.run_attempt }}
job: aggregate
- uses: actions/checkout@v3
- id: update
uses: actions/github-script@v6
env:
WORKFLOW_PATH: ${{ github.event.workflow.path }}
BADGE_URL: ${{ github.event.workflow.badge_url }}
SUMMARY_URL: ${{ steps.metadata.outputs.job_summary_url }}
with:
script: |
const fs = require('fs')
const workflowPath = process.env.WORKFLOW_PATH
const badgeURL = process.env.BADGE_URL
const refName = process.env.GITHUB_REF_NAME
const summaryURL = process.env.SUMMARY_URL
console.log(`
workflowPath: ${workflowPath}
badgeURL: ${badgeURL}
refName: ${refName}
summaryURL: ${summaryURL}
`)
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const searchValue = new RegExp(`\\[!\\[([^\\]]+)\\]\\(.*${escapeRegExp(badgeURL)}.*\\)\\]\\(.*\\)`, 'g')
const replaceValue = `[![$1](${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
- run: |
- 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]"
- run: |
echo GITHUB_JOB_SUMMARY_URL=${GITHUB_JOB_SUMMARY_URL}
IN='[![Conformance Production Dashboard](https://github.com/ipfs/gateway-conformance/actions/workflows/test-prod-e2e.yml/badge.svg?branch=master)](.*)'
ESCAPED_IN=$(printf '%s\n' "$IN" | sed -e 's/[][\/!&]/\\&/g')
OUT="[![Conformance Production Dashboard](https://github.com/ipfs/gateway-conformance/actions/workflows/test-prod-e2e.yml/badge.svg?branch=master)](${GITHUB_JOB_SUMMARY_URL})"
sed -i "s;${ESCAPED_IN};${OUT};" README.md
env:
GITHUB_JOB_SUMMARY_URL: ${{ steps.metadata.outputs.job_summary_url }}
REPOSITORY: ${{ github.repository }}
- id: git
run: |
if [[ -n $(git diff --shortstat 2> /dev/null | tail -n1) ]]; then
echo "dirty=1" >> $GITHUB_OUTPUT
else
echo "dirty=0" >> $GITHUB_OUTPUT
fi
- if: steps.git.outputs.dirty == '1'
- if: steps.update.outputs.result == 'true'
run: |
git add README.md
git commit -m 'chore: update the link to the dashboard [skip ci]'
git push
git commit -m 'chore: update the link to the interop dashboard [skip ci]'
git push
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

`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).

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

[![Conformance Dev Dashboard](https://github.com/singulargarden/gateway-conformance/workflows/Test%20Production%20(e2e)/badge.svg?branch=main)]()

## Table of Contents

Expand Down

0 comments on commit dcddf02

Please sign in to comment.