diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..2b78a90 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,7 @@ +# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#example-of-a-codeowners-file +# This is a comment. +# Each line is a file pattern followed by one or more owners. + +# These owners will be the default owners for everything in +# the repo. +* @johnko diff --git a/.github/git-has-uncommited-changes.sh b/.github/git-has-uncommited-changes.sh new file mode 100644 index 0000000..371a9d3 --- /dev/null +++ b/.github/git-has-uncommited-changes.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -euxo pipefail + +git version + +git diff --exit-code diff --git a/.github/pre-commit.sh b/.github/pre-commit.sh new file mode 100644 index 0000000..6b6c2e9 --- /dev/null +++ b/.github/pre-commit.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euxo pipefail + +ANY_ERROR=false + +set +e + +if type tofu &>/dev/null; then + bash -ex .github/opentofu-fmt.sh + # shellcheck disable=SC2181 + [[ $? -ne 0 ]] && ANY_ERROR=true + bash -ex .github/opentofu-validate.sh + # shellcheck disable=SC2181 + [[ $? -ne 0 ]] && ANY_ERROR=true +fi + +if type terraform &>/dev/null; then + bash -ex .github/terraform-fmt.sh + # shellcheck disable=SC2181 + [[ $? -ne 0 ]] && ANY_ERROR=true + bash -ex .github/terraform-validate.sh + # shellcheck disable=SC2181 + [[ $? -ne 0 ]] && ANY_ERROR=true +fi + +if type shellcheck &>/dev/null; then + bash -ex .github/shellcheck.sh + # shellcheck disable=SC2181 + [[ $? -ne 0 ]] && ANY_ERROR=true +fi + +if type shfmt &>/dev/null; then + bash -ex .github/shfmt.sh + # shellcheck disable=SC2181 + [[ $? -ne 0 ]] && ANY_ERROR=true +fi + +set -e + +if [[ "true" == "$ANY_ERROR" ]]; then + exit 1 +fi diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..f25ae81 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,14 @@ +{ + "allowedCommands": [ + "/bin/bash .github/helm-dep.sh" + ], + "extends": [ + "github>johnko/renovate-config" + ], + "postUpgradeTasks": { + "commands": [ + "/bin/bash .github/helm-dep.sh" + ], + "executionMode": "branch" + } +} diff --git a/.github/setup-git-pre-commit-hooks.sh b/.github/setup-git-pre-commit-hooks.sh new file mode 100644 index 0000000..e73a4d0 --- /dev/null +++ b/.github/setup-git-pre-commit-hooks.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euxo pipefail + +SCRIPT_DIR=$(dirname "$0") +pushd "$SCRIPT_DIR" + +if [[ -e ./pre-commit.sh ]] && [[ -d ../.git/hooks ]]; then + install -m 700 ./pre-commit.sh ../.git/hooks/pre-commit +fi diff --git a/.github/shellcheck.sh b/.github/shellcheck.sh new file mode 100644 index 0000000..5c32d7e --- /dev/null +++ b/.github/shellcheck.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -exo pipefail + +# when running in CI and shellcheck doesn't exist, install it +if [[ "true" == "$CI" ]]; then + if ! type shellcheck &>/dev/null; then + SUDO='' + if type sudo &>/dev/null; then + SUDO=sudo + fi + if type brew &>/dev/null; then + brew install shellcheck + elif type snap &>/dev/null; then + INSTALL_COMMAND="snap install shellcheck" + # shellcheck disable=SC2086 + $INSTALL_COMMAND || $SUDO $INSTALL_COMMAND + elif type apt &>/dev/null; then + SUDO='' + if type sudo &>/dev/null; then + SUDO=sudo + fi + INSTALL_COMMAND="apt install --yes shellcheck" + # shellcheck disable=SC2086 + $INSTALL_COMMAND || $SUDO $INSTALL_COMMAND + fi + fi +fi +set -u + +shellcheck --version + +set +e + +# git submodule status | awk '{print "-a -not -path **/"$2"/**"}' | tr "\n" " " | sed "s,\*\*/,'*/,g" | sed "s,/\*\*,/*',g" ; echo "\\" + +find . -type f \( -name '*.sh' -o -name '*.envrc' \) \ + -a -not -path '*/.terraform/modules/*' \ + \ + -a -not -path '*/.bash-git-prompt/*' -a -not -path '*/.zsh/kube-ps1/*' -a -not -path '*/.zsh/pure/*' -a -not -path '*/.zsh/zsh-colored-man-pages/*' -a -not -path '*/.zsh/zsh-command-time/*' -a -not -path '*/docker-files/squid/ref/docker-squid-cache-all/*' -a -not -path '*/docker-files/squid/ref/squid-in-a-can/*' -a -not -path '*/docker-files/squid/ref/squid-npm/*' \ + \ + -a -not -name 'macos-homebrew.sh' \ + -print0 | xargs -0 --max-procs=2 --verbose -I{} shellcheck --check-sourced --external-sources {} diff --git a/.github/shfmt.sh b/.github/shfmt.sh new file mode 100644 index 0000000..2f3b2d3 --- /dev/null +++ b/.github/shfmt.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -exo pipefail + +# when running in CI and shfmt doesn't exist, install it +if [[ "true" == "$CI" ]]; then + if ! type shfmt &>/dev/null; then + SUDO='' + if type sudo &>/dev/null; then + SUDO=sudo + fi + if type brew &>/dev/null; then + brew install shfmt + elif type snap &>/dev/null; then + INSTALL_COMMAND="snap install shfmt" + # shellcheck disable=SC2086 + $INSTALL_COMMAND || $SUDO $INSTALL_COMMAND + elif type go &>/dev/null; then + if [[ ! -d "$HOME/bin" ]]; then + mkdir -p "$HOME/bin" + fi + export GOBIN="$HOME/bin" + export PATH="$GOBIN:$PATH" + go install mvdan.cc/sh/v3/cmd/shfmt@v3.11.0 + ls -l "$GOBIN/shfmt" + elif type apt &>/dev/null; then + SUDO='' + if type sudo &>/dev/null; then + SUDO=sudo + fi + INSTALL_COMMAND="apt install --yes shfmt" + # shellcheck disable=SC2086 + $INSTALL_COMMAND || $SUDO $INSTALL_COMMAND + fi + fi +fi +set -u + +shfmt --version + +# Diff with +shfmt --diff --simplify --indent 2 --case-indent ./ +find . -type f -name '*.envrc' -print0 | xargs -0 --max-procs=2 --verbose -I{} shfmt --diff --simplify --indent 2 --case-indent {} + +# Fix with +# shfmt --write --simplify --indent 2 --case-indent ./ +# find . -type f -name '*.envrc' -print0 | xargs -0 --max-procs=2 --verbose -I{} shfmt --write --simplify --indent 2 --case-indent {} +# bash -ex ./.github/git-has-uncommited-changes.sh diff --git a/.github/workflows/renovate-config.yml b/.github/workflows/renovate-config.yml new file mode 100644 index 0000000..86ffc8d --- /dev/null +++ b/.github/workflows/renovate-config.yml @@ -0,0 +1,43 @@ +# THIS FILE'S LICENSE: +# Copyright 2020 WhiteSource Ltd + +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + preset: + container: + image: ghcr.io/renovatebot/renovate:42.1.3 + # github hosted runners are running as `1001:127` (ubuntu:docker) + options: -u 1001:0 --group-add 1000 --group-add 12021 --group-add 127 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + show-progress: false + - name: testing ${{ matrix.file }} + run: | + if [ -e ${{ matrix.file }}.json ]; then + renovate-config-validator ${{ matrix.file }}.json + fi + strategy: + matrix: + file: + - .github/renovate + - default + timeout-minutes: 10 +name: renovate-config +on: + pull_request: + paths: + - .github/renovate.json + - .github/workflows/renovate-config.yml + - default.json +permissions: + contents: read diff --git a/.github/workflows/renovate.yml b/.github/workflows/renovate.yml new file mode 100644 index 0000000..c941ed5 --- /dev/null +++ b/.github/workflows/renovate.yml @@ -0,0 +1,26 @@ +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + call-workflow: + secrets: inherit + uses: johnko/renovate-config/.github/workflows/renovate-shared.yml@main + with: + logLevel: ${{ inputs.logLevel }} + overrideSchedule: ${{ inputs.overrideSchedule == 'true' && 'true' || '' }} +name: Renovate +on: + schedule: + - cron: 30 12 * * SUN,SAT # UTC + workflow_dispatch: + inputs: + logLevel: + default: info + description: Override default log level + required: false + type: string + overrideSchedule: + default: "false" + description: Override all schedules + required: false + type: string diff --git a/.github/workflows/shell-checks.yml b/.github/workflows/shell-checks.yml new file mode 100644 index 0000000..46f2fd8 --- /dev/null +++ b/.github/workflows/shell-checks.yml @@ -0,0 +1,32 @@ +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + show-progress: false + - name: Test with shellcheck + run: | + bash -ex .github/shellcheck.sh + timeout-minutes: 10 + shfmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + show-progress: false + - name: Apply shfmt and find unformatted files + run: | + bash -ex .github/shfmt.sh + timeout-minutes: 10 +name: shell-checks +on: + pull_request: + paths: + - .github/shellcheck.sh + - .github/shfmt.sh + - .github/workflows/shell-checks.yml + - '**.sh' diff --git a/.github/workflows/yaml-checks.yml b/.github/workflows/yaml-checks.yml new file mode 100644 index 0000000..38203f0 --- /dev/null +++ b/.github/workflows/yaml-checks.yml @@ -0,0 +1,23 @@ +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + yq-pretty: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + show-progress: false + - name: Apply yq --prettyPrint and find unformatted files + run: | + bash -ex .github/yq-pretty.sh + timeout-minutes: 10 +name: yaml-checks +on: + pull_request: + paths: + - .github/git-has-uncommited-changes.sh + - .github/workflows/yaml-checks.yml + - .github/yq-pretty.sh + - '**.yaml' + - '**.yml' diff --git a/.github/yq-pretty.sh b/.github/yq-pretty.sh new file mode 100644 index 0000000..318a0e0 --- /dev/null +++ b/.github/yq-pretty.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euxo pipefail + +yq --version + +find . -type f \( -name '*.yaml' -o -name '*.yml' \) -not -path '*/lab/charts/*' -not -path '*/lab/traefik/*' -not -path '*/docker-files/squid/ref/*' -print0 | xargs -0 --max-procs=2 --verbose -I{} yq --exit-status --inplace --no-colors --prettyPrint 'sort_keys(..)' {} + +bash -ex ./.github/git-has-uncommited-changes.sh