Skip to content
52 changes: 52 additions & 0 deletions mise-tasks/fix/golang
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
#MISE description="Fix golang files"
#MISE quiet=true
#MISE tools={ "go:github.com/daixiang0/gci" = "0.13.6", yq = "4.45.4", gofumpt = "0.8.0", }
DEFAULT_GOLANG_CONFIG="${DEFAULT_GOLANG_CONFIG:-https://raw.githubusercontent.com/abcxyz/actions/main/default.golangci.yml}"
HASH="$(echo -n "DEFAULT_GOLANG_CONFIG" | sha256sum | cut -d' ' -f1)"
ABC_MISE_CACHE="${HOME}/.cache/abc/mise"
GOLANG_CONFIG="${ABC_MISE_CACHE}/${HASH}.golangci.yml"
mkdir -p "${ABC_MISE_CACHE}"
if [[ -f .golangci.yml ]]; then
GOLANG_CONFIG=".golangci.yml"
elif [[ -f .golangci.yaml ]]; then
GOLANG_CONFIG=".golangci.yaml"
elif [[ ! -f "${GOLANG_CONFIG}" ]]; then
echo "Fetching golang config: ${DEFAULT_GOLANG_CONFIG}"
wget "${DEFAULT_GOLANG_CONFIG}" -O "${GOLANG_CONFIG}"
fi
echo "golang config: ${GOLANG_CONFIG}"

gci_enabled="$(yq -r '.linters.enable | map(select(. == "gci")) | .[]' "${GOLANG_CONFIG}")"
gofmt_enabled="$(yq -r '.linters.enable | map(select(. == "gofmt")) | .[]' "${GOLANG_CONFIG}")"
gofumpt_enabled="$(yq -r '.linters.enable | map(select(. == "gofumpt")) | .[]' "${GOLANG_CONFIG}")"

if [[ "${gci_enabled}" == "gci" ]]; then
sections="$(yq -r '.linters-settings.gci.sections.[]' "${GOLANG_CONFIG}")"
skip_generated="$(yq -r '.linters-settings.gci.skip-generated' "${GOLANG_CONFIG}")"
custom_order="$(yq -r '.linters-settings.gci.custom-order' "${GOLANG_CONFIG}")"

gci_args=()
while IFS='' read -r section; do
gci_args+=("-s=${section}")
done < <(echo "${sections}")
if [[ "${skip_generated}" == "true" ]]; then
gci_args+=(--skip-generated)
fi
if [[ "${custom_order}" == "true" ]]; then
gci_args+=(--custom-order)
fi
gci write "${gci_args[@]}" .
fi

if [[ "${gofmt_enabled}" == "gofmt" ]]; then
if which go >/dev/null; then
go fmt ./...
else
echo "Skipping 'go fmt' because no go binary was found - Did you forget to 'mise use go'?"
fi
fi

if [[ "${gofumpt_enabled}" == "gofumpt" ]]; then
gofumpt -l -w .
fi
8 changes: 8 additions & 0 deletions mise-tasks/fix/terraform
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#MISE description="Fix terraform files"
#MISE quiet=true
if which terraform >/dev/null; then
terraform fmt -recursive
else
echo "Skipping 'terraform fmt' because no binary was found - Did you forget to 'mise use terraform'?"
fi
12 changes: 12 additions & 0 deletions mise-tasks/lint/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#MISE description="Lint java files"
#MISE quiet=true
#MISE tools={ "ubi:hadolint/hadolint" = "latest" }
DEFAULT_HADOLINT_CONFIG="https://raw.githubusercontent.com/abcxyz/actions/main/.hadolint.yml"
ABC_MISE_CACHE="${HOME}/.cache/abc/mise"
HADOLINT_CONFIG="${ABC_MISE_CACHE}/.hadolint.yml"
mkdir -p "${ABC_MISE_CACHE}"
if [[ ! -f "${HADOLINT_CONFIG}" ]]; then
wget "${DEFAULT_HADOLINT_CONFIG}" -P "${ABC_MISE_CACHE}"
fi
git ls-files | grep -E '(dockerfile|Dockerfile)' | xargs hadolint -c "${HADOLINT_CONFIG}" --format=tty
12 changes: 12 additions & 0 deletions mise-tasks/lint/github
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#MISE description="Lint github workflows and actions"
#MISE quiet=true
#MISE tools={ shellcheck = "0.10.0", actionlint = "1.7.7" }
GITHUB_FORMAT='{{range $err := .}}::error file={{$err.Filepath}},line={{$err.Line}},col={{$err.Column}}::{{$err.Filepath}}@{{$err.Line}} {{$err.Message}}%0A```%0A{{replace $err.Snippet "\\n" "%0A"}}%0A```\n{{end}}'
if [[ -n "${GITHUB_WORKSPACE}" ]]; then FORMAT="${GITHUB_FORMAT}"; else FORMAT=""; fi

actionlint \
-color \
-format "${FORMAT}" \
-ignore 'SC2016:' \
-ignore 'label ".+" is unknown'
19 changes: 19 additions & 0 deletions mise-tasks/lint/golang
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
#MISE description="Lint golang files"
#MISE quiet=true
#MISE tools={ golangci-lint = "1.64" }
DEFAULT_GOLANG_CONFIG="${DEFAULT_GOLANG_CONFIG:-https://raw.githubusercontent.com/abcxyz/actions/main/default.golangci.yml}"
HASH="$(echo -n "DEFAULT_GOLANG_CONFIG" | sha256sum | cut -d' ' -f1)"
ABC_MISE_CACHE="${HOME}/.cache/abc/mise"
GOLANG_CONFIG="${ABC_MISE_CACHE}/${HASH}.golangci.yml"
mkdir -p "${ABC_MISE_CACHE}"
if [[ -f .golangci.yml ]]; then
GOLANG_CONFIG=".golangci.yml"
elif [[ -f .golangci.yaml ]]; then
GOLANG_CONFIG=".golangci.yaml"
elif [[ ! -f "${GOLANG_CONFIG}" ]]; then
echo "Fetching golang config: ${DEFAULT_GOLANG_CONFIG}"
wget "${DEFAULT_GOLANG_CONFIG}" -O "${GOLANG_CONFIG}"
fi
echo "golang config: ${GOLANG_CONFIG}"
golangci-lint run -c "${GOLANG_CONFIG}" ./...
6 changes: 6 additions & 0 deletions mise-tasks/lint/java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
#MISE description="Lint java files"
#MISE quiet=true
#MISE tools={ "ubi:google/google-java-format" = "latest" }
git ls-files | grep -E '\.(java)' | xargs \
google-java-format -i
6 changes: 6 additions & 0 deletions mise-tasks/lint/ratchet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
#MISE description="Lint java files"
#MISE quiet=true
#MISE tools={ "ubi:sethvargo/ratchet" = "latest" }
git ls-files | grep -E '\.(java)' | xargs \
ratchet lint
14 changes: 14 additions & 0 deletions mise-tasks/lint/shell
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#MISE description="Lint shell files"
#MISE quiet=true
#MISE tools={ shellcheck = "0.10.0" }

# Find all bash scripts even if they don't have an explicit extension.
git ls-files | grep -E '^([^.]+|.*\.(sh|zsh|bash))$' | xargs file --mime-type \
| grep "text/x-shellscript" | awk '{ print substr($1, 1, length($1)-1) }' \
| xargs shellcheck \
--check-sourced \
--enable=all \
--severity=style \
--format=tty \
--color=always
11 changes: 11 additions & 0 deletions mise-tasks/lint/terraform
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
#MISE description="Lint terraform files"
#MISE quiet=true
#MISE tools={ "ubi:abcxyz/terraform-linter" = "latest" }
if which terraform >/dev/null; then
terraform fmt -recursive -check
else
echo "Skipping 'terraform fmt' because no binary was found - Did you forget to 'mise use terraform'?"
fi

git ls-files | grep -E '\.(tf)' | xargs terraform-linter lint
13 changes: 13 additions & 0 deletions mise-tasks/lint/yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#MISE description="Lint yaml files"
#MISE quiet=true
#MISE tools={ pipx = "1.7.1", python = "3.12", yamllint = "1.35.1" }
if [[ -n "${GITHUB_WORKSPACE}" ]]; then FORMAT="github"; else FORMAT="colored"; fi
DEFAULT_YAML_CONFIG="https://raw.githubusercontent.com/abcxyz/actions/main/.yamllint.yml"
ABC_MISE_CACHE="${HOME}/.cache/abc/mise"
YAML_CONFIG="${ABC_MISE_CACHE}/.yamllint.yml"
mkdir -p "${ABC_MISE_CACHE}"
if [[ ! -f "${YAML_CONFIG}" ]]; then
wget "${DEFAULT_YAML_CONFIG}" -P "${ABC_MISE_CACHE}"
fi
git ls-files | grep -E '\.(yaml|yml)' | xargs yamllint --format "${FORMAT}" -c "${YAML_CONFIG}"