Skip to content

Commit ced56a7

Browse files
committed
chore: switch to workflow for contributors badge
1 parent a988073 commit ced56a7

File tree

6 files changed

+112
-5
lines changed

6 files changed

+112
-5
lines changed

.all-contributorsrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,5 @@
140140
]
141141
}
142142
],
143-
"contributorsPerLine": 7,
144-
"skipCi": true
143+
"contributorsPerLine": 7
145144
}

.github/workflows/docs.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Docs
2+
on:
3+
push:
4+
paths:
5+
- .all-contributorsrc
6+
- .github/workflows/docs.yml
7+
workflow_dispatch:
8+
9+
jobs:
10+
contributors:
11+
name: Update contributors badge
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- uses: actions/setup-node@v1
17+
with:
18+
node-version: 12.x
19+
20+
- run: npm install
21+
22+
- run: npm run all-contributors-badge
23+
24+
- uses: EndBug/[email protected]
25+
with:
26+
message: "[auto] docs: update contributors badge"
27+
add: README.md
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Add & Commit
2-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
3-
[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)
4-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
2+
[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat)](#contributors-)
53

64
You can use this GitHub Action to commit changes made in your workflow run directly to your repo: for example, you use it to lint your code, update documentation, commit updated builds, etc....
75

package-lock.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"build": "npm i && ncc build src/main.ts --minify --out lib",
88
"watch": "ncc build src/main.ts --watch --out lib",
9+
"all-contributors-badge": "ts-node scripts/all-contributors-badge",
910
"test": "echo \"Error: no test specified\" && exit 1"
1011
},
1112
"repository": {
@@ -37,6 +38,7 @@
3738
"@zeit/ncc": "^0.21.1",
3839
"all-contributors-cli": "^6.16.1",
3940
"eslint": "^6.8.0",
41+
"ts-node": "^8.10.2",
4042
"typescript": "^3.6.4"
4143
}
4244
}

scripts/all-contributors-badge.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as fs from 'fs'
2+
import { resolve } from 'path'
3+
4+
function path(...segments: string[]) {
5+
return resolve(__dirname, '..', ...segments)
6+
}
7+
8+
const README = fs.readFileSync(path('README.md'), { encoding: 'utf8' }),
9+
{ contributors } = JSON.parse(fs.readFileSync(path('.all-contributorsrc'), { encoding: 'utf8' }))
10+
if (!(contributors instanceof Array)) throw new Error('Invalid config file')
11+
12+
const updatedREADME = README
13+
.split('\n')
14+
.map(line =>
15+
line.startsWith('[![All Contributors](https://img.shields.io/badge/all_contributors-')
16+
? `[![All Contributors](https://img.shields.io/badge/all_contributors-${contributors.length}-orange.svg?style=flat)](#contributors-)`
17+
: line
18+
).join('\n')
19+
20+
fs.writeFileSync(path('README.md'), updatedREADME)

0 commit comments

Comments
 (0)