-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sintroduce GitHub actions to catch bad PRs
- Loading branch information
Showing
6 changed files
with
162 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Go | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
verify: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22.3' | ||
|
||
- name: verify source | ||
run: hack/verify.sh | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22.3' | ||
|
||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.58 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
cd $(dirname $0)/.. | ||
|
||
EXIT_CODE=0 | ||
|
||
errcho() { | ||
echo $@ >&2 | ||
} | ||
|
||
try() { | ||
local title="$1" | ||
shift | ||
|
||
echo "====================================" | ||
echo "$title" | ||
echo "====================================" | ||
echo | ||
|
||
startTime=$(date +%s) | ||
|
||
set +e | ||
$@ | ||
exitCode=$? | ||
set -e | ||
|
||
elapsed=$(($(date +%s) - $startTime)) | ||
|
||
if [[ $exitCode -eq 0 ]]; then | ||
echo -e "\n[${elapsed}s] SUCCESS :)" | ||
else | ||
echo -e "\n[${elapsed}s] FAILED." | ||
EXIT_CODE=1 | ||
fi | ||
|
||
git reset --hard --quiet | ||
git clean --force | ||
|
||
echo | ||
} | ||
|
||
function verify_go_mod_tidy() ( | ||
set -e | ||
|
||
(set -x; go mod tidy) | ||
|
||
if ! git diff --exit-code; then | ||
echo "Please run go mod tidy." | ||
return 1 | ||
fi | ||
|
||
echo "go.mod is tidy." | ||
) | ||
|
||
function ensure_gimps() { | ||
location=gimps | ||
|
||
if ! [ -x "$(command -v gimps)" ]; then | ||
version=0.6.0 | ||
arch="$(go env GOARCH)" | ||
os="$(go env GOOS)" | ||
url="https://github.com/xrstf/gimps/releases/download/v${version}/gimps_${version}_${os}_${arch}.tar.gz" | ||
location=/tmp/gimps | ||
|
||
errcho "Downloading gimps v$version..." | ||
wget -qO- "$url" | tar xzOf - "gimps_${version}_${os}_${arch}/gimps" > $location | ||
chmod +x $location | ||
fi | ||
|
||
echo "$location" | ||
} | ||
|
||
function verify_go_imports() ( | ||
set -e | ||
|
||
gimps="$(ensure_gimps)" | ||
|
||
(set -x; $gimps .) | ||
|
||
if ! git diff --exit-code; then | ||
echo "Some import statements are not properly grouped. Please run https://github.com/xrstf/gimps or sort them manually." | ||
return 1 | ||
fi | ||
|
||
echo "Go import statements are properly sorted." | ||
) | ||
|
||
function verify_go_build() ( | ||
set -e | ||
|
||
if ! (set -x; make build); then | ||
echo "Code does not compile." | ||
return 1 | ||
fi | ||
|
||
echo "Code compiles." | ||
) | ||
|
||
function verify_go_lint() ( | ||
set -e | ||
|
||
if ! (set -x; golangci-lint run ./...); then | ||
echo "Computer says no." | ||
return 1 | ||
fi | ||
|
||
echo "Code looks sane." | ||
) | ||
|
||
try "go.mod tidy?" verify_go_mod_tidy | ||
try "gimpsed?" verify_go_imports | ||
try "Go code builds?" verify_go_build | ||
|
||
exit $EXIT_CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.