Skip to content

Commit 5dfbefb

Browse files
committed
Improve CI
1 parent 805dac6 commit 5dfbefb

File tree

6 files changed

+65
-45
lines changed

6 files changed

+65
-45
lines changed

.github/fmt/entrypoint.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
#!/usr/bin/env bash
22

3-
source .github/lib.sh
3+
source .github/lib.sh || exit 1
44

5-
gofmt -w -s .
6-
go run go.coder.com/go-tools/cmd/goimports -w "-local=$(go list -m)" .
7-
go run mvdan.cc/sh/cmd/shfmt -w -s -sr .
5+
gen() {
6+
# Unfortunately, this is the only way to ensure go.mod and go.sum are correct.
7+
# See https://github.com/golang/go/issues/27005
8+
go list ./... > /dev/null
9+
go mod tidy
810

9-
if [[ $CI ]] && unstaged_files; then
11+
go install github.com/golang/protobuf/protoc-gen-go
12+
go generate ./...
13+
}
14+
15+
fmt() {
16+
gofmt -w -s .
17+
go run go.coder.com/go-tools/cmd/goimports -w "-local=$(go list -m)" .
18+
go run mvdan.cc/sh/cmd/shfmt -w -s -sr .
19+
}
20+
21+
gen
22+
fmt
23+
24+
if [[ $CI && $(unstaged_files) != "" ]]; then
1025
set +x
1126
echo
12-
echo "files are not formatted correctly"
27+
echo "files either need generation or are formatted incorrectly"
1328
echo "please run:"
1429
echo "./test.sh"
1530
echo

.github/lib.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ export PAGER=cat
77

88
# shellcheck disable=SC2034
99
# CI is used by the scripts that source this file.
10-
CI=${GITHUB_ACTION-}
10+
export CI=${GITHUB_ACTION-}
1111

1212
if [[ $CI ]]; then
1313
export GOFLAGS=-mod=readonly
1414
fi
1515

16-
function unstaged_files() {
17-
[[ $(git ls-files --other --modified --exclude-standard) != "" ]]
16+
unstaged_files() {
17+
git ls-files --other --modified --exclude-standard
1818
}
19-

.github/lint/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM codercom/playcicache
2+
3+
LABEL "com.github.actions.name"="lint"
4+
LABEL "com.github.actions.description"="lint"
5+
LABEL "com.github.actions.icon"="code"
6+
LABEL "com.github.actions.color"="purple"
7+
8+
COPY entrypoint.sh /entrypoint.sh
9+
10+
CMD ["/entrypoint.sh"]

.github/lint/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
source .github/lib.sh || exit 1
4+
5+
(
6+
shopt -s globstar nullglob dotglob
7+
shellcheck ./**/*.sh
8+
)
9+
10+
go vet -composites=false ./...
11+
go run golang.org/x/lint/golint -set_exit_status ./...

.github/test/entrypoint.sh

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
11
#!/usr/bin/env bash
22

3-
source .github/lib.sh
4-
5-
# Unfortunately, this is the only way to ensure go.mod and go.sum are correct.
6-
# See https://github.com/golang/go/issues/27005
7-
go list ./... > /dev/null
8-
go mod tidy
9-
10-
go install golang.org/x/tools/cmd/stringer
11-
go generate ./...
12-
13-
if [[ $CI ]] && unstaged_files; then
14-
set +x
15-
echo
16-
echo "generated code needs an update"
17-
echo "please run:"
18-
echo "./test.sh"
19-
echo
20-
git status
21-
exit 1
22-
fi
23-
24-
(
25-
shopt -s globstar nullglob dotglob
26-
shellcheck ./**/*.sh
27-
)
28-
29-
go vet -composites=false ./...
3+
source .github/lib.sh || exit 1
304

315
COVERAGE_PROFILE=$(mktemp)
326
go test -race -v "-coverprofile=${COVERAGE_PROFILE}" -vet=off ./...
337
go tool cover "-func=${COVERAGE_PROFILE}"
348

359
if [[ $CI ]]; then
36-
bash <(curl -s https://codecov.io/bash)
10+
bash <(curl -s https://codecov.io/bash) -f "$COVERAGE_PROFILE"
3711
else
3812
go tool cover "-html=${COVERAGE_PROFILE}" -o=coverage.html
13+
14+
set +x
15+
echo
16+
echo "please open coverage.html to see detailed test coverage stats"
3917
fi

test.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#!/usr/bin/env bash
22

3-
# This is for local testing. See .github for CI.
3+
# This script is for local testing. See .github for CI.
44

5-
source ./.github/lib.sh
5+
source .github/lib.sh || exit 1
6+
cd "$(dirname "${0}")"
67

78
function docker_run() {
8-
local dir=$1
9+
local DIR="$1"
10+
local IMAGE
11+
IMAGE="$(docker build -q "$DIR")"
912
docker run \
1013
-v "${PWD}:/repo" \
1114
-v "$(go env GOPATH):/go" \
1215
-v "$(go env GOCACHE):/root/.cache/go-build" \
1316
-w /repo \
14-
"$(docker build -q "$dir")"
17+
"${IMAGE}"
1518
}
19+
20+
if [[ $# -gt 0 ]]; then
21+
docker_run ".github/$*"
22+
exit 0
23+
fi
24+
1625
docker_run .github/fmt
26+
docker_run .github/lint
1727
docker_run .github/test
18-
19-
set +x
20-
echo "please open coverage.html to see detailed test coverage stats"

0 commit comments

Comments
 (0)