-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update perms to make reviewdog work * Add test files * Fix sha for shfmt action * Rename linter pre-submit file * run golangci-lint manually * Fix workflows * Reduce permissions * fix lint workflow * fix lint workflow * use sha for setup-go * Add shellcheck job * run yamllint manually * add runs-on * fix untarring githubci-lint * fix untarring githubci-lint * output github actions commands * remove uncessary code * Remove test files * code cleanup * Add golangci-lint checksum check * Actually untar golangci-lint * add debug * Restore correct hash * Checksum the right file * fix dir * Remove unused ldflags * Disable linters generating issues for now * Disable stylecheck for now * Fix trailing spaces * Exit with positive error codes * Update references to reusable actions. * Add Makefile to make running linters easier * remove trailing whitespace * Fix formatting options for yamllint * Fix yamllint issues * Fix tag comments * Add docs on local development. * Update comment * Linters ignore vendor directory * Fix whitespace
- Loading branch information
Ian Lewis
authored
Jul 22, 2022
1 parent
e49ee2a
commit 1a55da8
Showing
16 changed files
with
264 additions
and
64 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
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
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,64 @@ | ||
name: Lint | ||
|
||
on: [pull_request] | ||
|
||
permissions: | ||
# Needed to check out the repo. | ||
contents: read | ||
|
||
jobs: | ||
golangci-lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 | ||
- uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923 # tag=v3.2.0 | ||
with: | ||
go-version: "1.18" | ||
- env: | ||
GOLANGCI_LINT_VERSION: "1.46.2" | ||
GOLANGCI_LINT_CHECKSUM: "242cd4f2d6ac0556e315192e8555784d13da5d1874e51304711570769c4f2b9b" | ||
run: | | ||
set -euo pipefail | ||
#Install golangci-lint | ||
curl -sSLo golangci-lint.tar.gz "https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz" | ||
echo "golangci-lint checksum is $(sha256sum golangci-lint.tar.gz | awk '{ print $1 }')" | ||
echo "expected checksum is $GOLANGCI_LINT_CHECKSUM" | ||
echo "$GOLANGCI_LINT_CHECKSUM golangci-lint.tar.gz" | sha256sum --strict --check --status || exit -2 | ||
tar xf golangci-lint.tar.gz | ||
mv golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint /usr/local/bin | ||
# Run golangci-lint | ||
make golangci-lint | ||
shellcheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 | ||
- env: | ||
SHELLCHECK_VERSION: "0.8.0" | ||
run: | | ||
set -euo pipefail | ||
# Install shellcheck | ||
wget -qO- "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar -xJf - | ||
mv "shellcheck-v$SHELLCHECK_VERSION/shellcheck" /usr/local/bin | ||
# Run shellcheck and output github actions commands. | ||
# See: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions | ||
make shellcheck | ||
yamllint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 | ||
- env: | ||
YAMLLINT_VERSION: "1.26.3" | ||
run: | | ||
set -euo pipefail | ||
# Install yamllint | ||
pip install "yamllint==${YAMLLINT_VERSION}" | ||
# Run yamllint | ||
make yamllint |
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 |
---|---|---|
|
@@ -35,4 +35,3 @@ jobs: | |
go-version: 1.18 | ||
config-file: .github/workflows/configs-go/config-release.yml | ||
compile-builder: true | ||
|
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,82 @@ | ||
SHELL := /bin/bash | ||
OUTPUT_FORMAT = $(shell if [ "${GITHUB_ACTIONS}" == "true" ]; then echo "github"; else echo ""; fi) | ||
|
||
.PHONY: help | ||
help: ## Shows all targets and help from the Makefile (this message). | ||
@echo "slsa-github-generator Makefile" | ||
@echo "Usage: make [COMMAND]" | ||
@echo "" | ||
@grep --no-filename -E '^([/a-z.A-Z0-9_%-]+:.*?|)##' $(MAKEFILE_LIST) | \ | ||
awk 'BEGIN {FS = "(:.*?|)## ?"}; { \ | ||
if (length($$1) > 0) { \ | ||
printf " \033[36m%-20s\033[0m %s\n", $$1, $$2; \ | ||
} else { \ | ||
if (length($$2) > 0) { \ | ||
printf "%s\n", $$2; \ | ||
} \ | ||
} \ | ||
}' | ||
|
||
## Testing | ||
##################################################################### | ||
|
||
unit-test: ## Runs all unit tests. | ||
# Run unit tests for the detect-workflow action. | ||
cd .github/actions/detect-workflow | ||
go mod vendor | ||
go test -mod=vendor -v ./... | ||
# Run unit tests for the main package. | ||
cd - | ||
go mod vendor | ||
go test -mod=vendor -v ./... | ||
|
||
|
||
## Linters | ||
##################################################################### | ||
|
||
lint: ## Run all linters. | ||
lint: golangci-lint shellcheck yamllint | ||
|
||
golangci-lint: ## Runs the golangci-lint linter. | ||
@set -e;\ | ||
extraargs=""; \ | ||
if [ "$(OUTPUT_FORMAT)" == "github" ]; then \ | ||
extraargs="--out-format github-actions"; \ | ||
fi; \ | ||
golangci-lint run -c .golangci.yml ./... $$extraargs | ||
|
||
shellcheck: ## Runs the shellcheck linter. | ||
@set -e;\ | ||
FILES=$$(find . -type f -not -iwholename '*/.git/*' -not -iwholename '*/vendor/*' -not -iwholename '*/node_modules/*' -exec bash -c 'file "$$1" | cut -d':' -f2 | grep --quiet shell' _ {} \; -print); \ | ||
if [ "$(OUTPUT_FORMAT)" == "github" ]; then \ | ||
echo -n $$FILES | xargs shellcheck -f json --external-sources | jq -c '.[]' | while IFS="" read -r p || [ -n "$$p" ]; do \ | ||
LEVEL=$$(echo "$$p" | jq -c '.level // empty' | tr -d '"'); \ | ||
FILE=$$(echo "$$p" | jq -c '.file // empty' | tr -d '"'); \ | ||
LINE=$$(echo "$$p" | jq -c '.line // empty' | tr -d '"'); \ | ||
ENDLINE=$$(echo "$$p" | jq -c '.endLine // empty' | tr -d '"'); \ | ||
COL=$$(echo "$$p" | jq -c '.column // empty' | tr -d '"'); \ | ||
ENDCOL=$$(echo "$$p" | jq -c '.endColumn // empty' | tr -d '"'); \ | ||
MESSAGE=$$(echo "$$p" | jq -c '.message // empty' | tr -d '"'); \ | ||
case $$LEVEL in \ | ||
"info") \ | ||
echo "::notice file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \ | ||
;; \ | ||
"warning") \ | ||
echo "::warning file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \ | ||
;; \ | ||
"error") \ | ||
echo "::error file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \ | ||
;; \ | ||
esac; \ | ||
done; \ | ||
else \ | ||
echo -n $$FILES | xargs shellcheck --external-sources; \ | ||
fi | ||
|
||
yamllint: ## Runs the yamllint linter. | ||
@set -e;\ | ||
extraargs=""; \ | ||
if [ "$(OUTPUT_FORMAT)" == "github" ]; then \ | ||
extraargs="-f github"; \ | ||
fi; \ | ||
yamllint -c .yamllint.yaml . $$extraargs |
Oops, something went wrong.