Skip to content

Commit b0a7b16

Browse files
committed
ci: makework
1 parent 433c0ca commit b0a7b16

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
git config --global user.email "$1"
3+
shift
4+
git config --global user.name "$1"
5+
shift
6+
message="$1"
7+
shift
8+
if [ $(git status --porcelain "$@" | egrep '^ M' | wc -l) -gt 0 ]; then
9+
git add "$@"
10+
git commit -m "$message"
11+
git push || git pull --rebase
12+
git push
13+
fi

.github/workflows/copyright-year.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
dir=${1:-$PWD}
3+
dates=($(git log --date=format:%Y --pretty=format:'%ad' --reverse | sort | uniq))
4+
if [ "${#dates[@]}" -eq 1 ]; then
5+
datestr="${dates}"
6+
else
7+
datestr="${dates}-${dates[${#dates[@]}-1]}"
8+
fi
9+
10+
stripDate='s/^((.*)Copyright\b(.*?))((?:,\s*)?(([0-9]{4}\s*-\s*[0-9]{4})|(([0-9]{4},\s*)*[0-9]{4})))(?:,)?\s*(.*)\n$/$1$9\n/g'
11+
addDate='s/^.*Copyright(?:\s*\(c\))? /Copyright \(c\) '$datestr' /g'
12+
for l in $dir/LICENSE*; do
13+
perl -pi -e "$stripDate" $l
14+
perl -pi -e "$addDate" $l
15+
done

.github/workflows/isaacs-makework.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "various tidying up tasks to silence nagging"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
makework:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
- name: Use Node.js
17+
uses: actions/[email protected]
18+
with:
19+
node-version: 16.x
20+
- name: put repo in package.json
21+
run: node .github/workflows/package-json-repo.js
22+
- name: check in package.json if modified
23+
run: |
24+
bash -x .github/workflows/commit-if-modified.sh \
25+
26+
"package.json Repo Bot" \
27+
"chore: add repo to package.json" \
28+
package.json package-lock.json
29+
- name: put all dates in license copyright line
30+
run: bash .github/workflows/copyright-year.sh
31+
- name: check in licenses if modified
32+
run: |
33+
bash .github/workflows/commit-if-modified.sh \
34+
35+
"License Year Bot" \
36+
"chore: add copyright year to license" \
37+
LICENSE*
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
3+
const pf = require.resolve(`${process.cwd()}/package.json`)
4+
const pj = require(pf)
5+
6+
if (!pj.repository && process.env.GITHUB_REPOSITORY) {
7+
const fs = require('fs')
8+
const server = process.env.GITHUB_SERVER_URL || 'https://github.com'
9+
const repo = `${server}/${process.env.GITHUB_REPOSITORY}`
10+
pj.repository = repo
11+
const json = fs.readFileSync(pf, 'utf8')
12+
const match = json.match(/^\s*\{[\r\n]+([ \t]*)"/)
13+
const indent = match[1]
14+
const output = JSON.stringify(pj, null, indent || 2) + '\n'
15+
fs.writeFileSync(pf, output)
16+
}

0 commit comments

Comments
 (0)