Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit b2ebc8d

Browse files
add the script used check the Go repo health
1 parent a2c06ff commit b2ebc8d

4 files changed

Lines changed: 87 additions & 3 deletions

File tree

scripts/get-repos/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import {Octokit} from '@octokit/rest'
2+
import { Command } from 'commander/esm.mjs';
23

3-
const LANGUAGES = ["JavaScript", "Go"]
4+
const program = new Command();
5+
program.option('-l, --languages [lang...]', 'languages (e.g. JavaScript, Go)', ['JavaScript', 'Go'])
6+
program.parse(process.argv);
7+
const opts = program.opts();
8+
9+
const LANGUAGES = opts.languages;
410
const ORGS = ["ipfs", "ipfs-shipyard", "ipld", "libp2p", "multiformats"]
511

612
const options = {}

scripts/get-repos/package-lock.json

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/get-repos/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"author": "",
1111
"license": "MIT",
1212
"dependencies": {
13-
"@octokit/rest": "^18.5.2"
13+
"@octokit/rest": "^18.5.2",
14+
"commander": "^8.0.0"
1415
}
1516
}

scripts/health.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
to_status() {
4+
if [[ $1 == 0 ]]; then
5+
printf ""
6+
return
7+
fi
8+
printf ""
9+
}
10+
11+
check_go_mod_tidy() {
12+
if [[ ! -f go.mod || ! -f go.sum ]]; then
13+
echo 1
14+
return
15+
fi
16+
cp go.mod go.mod.orig
17+
cp go.sum go.sum.orig
18+
go mod tidy &> /dev/null
19+
diff go.mod go.mod.orig > /dev/null
20+
if [[ $? != 0 ]]; then
21+
echo 1
22+
return
23+
fi
24+
diff go.sum go.sum.orig > /dev/null
25+
echo $?
26+
}
27+
28+
check_go_fmt() {
29+
out=$(gofmt -l . | xargs)
30+
if [[ -z "$out" ]]; then
31+
echo 0
32+
return
33+
fi
34+
echo 1
35+
}
36+
37+
for repo in $(node get-repos/index.js -l Go | jq -r '.[]'); do
38+
tmp=$(mktemp -d)
39+
pushd $tmp > /dev/null
40+
git clone -q https://github.com/$repo .
41+
if [[ ! -f .github/workflows/go-check.yml ]]; then # if the workflows aren't deployed yet
42+
numcommits=$(git rev-list --count --since="Oct 1 2020" --all --no-merges)
43+
pr=$(git branch -r --no-merged | grep -c web3-bot/sync)
44+
if [[ $pr == 0 ]]; then # if there's no PR to add the workflows
45+
gomodtidy=$(check_go_mod_tidy)
46+
gofmt=$(check_go_fmt)
47+
go test -failfast ./... &> /dev/null
48+
gotest=$?
49+
go test -failfast -race ./... &> /dev/null
50+
gotestrace=$?
51+
go vet ./... &> /dev/null
52+
govet=$?
53+
staticcheck ./... &> /dev/null
54+
staticcheck=$?
55+
echo "$repo $numcommits false $(to_status $gomodtidy) $(to_status $gofmt) $(to_status $gotest) $(to_status $gotestrace) $(to_status $govet) $(to_status $staticcheck)"
56+
else
57+
echo "$repo $numcommits true"
58+
fi
59+
fi
60+
popd > /dev/null
61+
rm -rf $tmp
62+
done
63+

0 commit comments

Comments
 (0)