From 8f0489a6226b443edcd4a859b7be83d225948478 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sun, 10 Nov 2024 10:01:22 -0500 Subject: [PATCH 1/2] build: add pre-commit tooling + basic go/shell/yaml hooks docs: mention pre-commit --- .pre-commit-config.yaml | 16 ++++++++++++++++ README.md | 4 ++++ bootstrap.sh | 8 ++++++++ 3 files changed, 28 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100755 bootstrap.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..633f7c2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-yaml + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck + - repo: https://github.com/tekwizely/pre-commit-golang + rev: master + hooks: + - id: go-test-mod + - id: go-fmt + - id: go-vet-mod diff --git a/README.md b/README.md index b9c18cb..9dc8e31 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,7 @@ curl https://forge.karnov.club/spadinastan/spud/raw/branch/main/install.sh | bas To pull a specific version, supply a `$SPUD_VERSION` that corresponds to an existing release tag, and to control where the binary is unpacked and installed, supply `$SPUD_ROOT`. + +## Development + +The `bootstrap.sh` script should be run to prepare any pre-commit hooks and other required tooling for local development. Checks can be run manually via `pipx run pre-commit run -a`. diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..6dac009 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [[ -z "$(command -v pipx)" ]]; then + echo "ERROR: Pre-commit tooling requires pipx to be available." + exit 1 +fi + +pipx run pre-commit install -- 2.45.2 From 24e795e1aab36fda2e4eccaef2e648a665014496 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sun, 10 Nov 2024 10:11:10 -0500 Subject: [PATCH 2/2] ci: run pre-commit on pr + push --- .forgejo/workflows/pull-request.yml | 41 ++++++++++++++++++ .forgejo/workflows/push.yml | 67 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .forgejo/workflows/pull-request.yml create mode 100644 .forgejo/workflows/push.yml diff --git a/.forgejo/workflows/pull-request.yml b/.forgejo/workflows/pull-request.yml new file mode 100644 index 0000000..5244179 --- /dev/null +++ b/.forgejo/workflows/pull-request.yml @@ -0,0 +1,41 @@ +name: Pull-Request +on: [pull_request] + +jobs: + static-analysis: + runs-on: runner-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.23 + - name: Validate Yaml + run: pipx run pre-commit run check-yaml -a + - name: Validate shell scripts + run: pipx run pre-commit run shellcheck -a + - name: Check formatting + run: pipx run pre-commit run go-fmt -a + - name: Check code patterns + run: pipx run pre-commit run go-vet-mod -a + tests: + runs-on: runner-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.23 + - name: Tests + run: pipx run pre-commit run go-test-mod -a + post-run: + runs-on: runner-latest + needs: [static-analysis,tests] + if: ${{ always() }} + steps: + - name: Export trace + uses: https://forge.karnov.club/marc/opentelemetry-trace-export-forgejo-action@main + with: + otlp-endpoint: "http://otel.home.karnov.club:4318" + forgejo-token: ${{ secrets.GITHUB_TOKEN }} + forgejo-base-url: ${{ env.GITHUB_SERVER_URL }} + run-id: ${{ env.GITHUB_RUN_NUMBER }} + repo-name: ${{ env.GITHUB_REPOSITORY }} diff --git a/.forgejo/workflows/push.yml b/.forgejo/workflows/push.yml new file mode 100644 index 0000000..3ce9dd1 --- /dev/null +++ b/.forgejo/workflows/push.yml @@ -0,0 +1,67 @@ +name: Push +on: + push: + branches: [main] + +jobs: + pre-run: + runs-on: runner-latest + steps: + - uses: https://forge.karnov.club/marc/push-status-to-discord-action@main + with: + webhook-url: ${{secrets.DISCORD_WEBHOOK_URL}} + status: "Started" + init: true + static-analysis: + runs-on: runner-latest + needs: [pre-run] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.23 + - name: Validate Yaml + run: pipx run pre-commit run check-yaml -a + - name: Validate shell scripts + run: pipx run pre-commit run shellcheck -a + - name: Check formatting + run: pipx run pre-commit run go-fmt -a + - name: Check code patterns + run: pipx run pre-commit run go-vet-mod -a + tests: + runs-on: runner-latest + needs: [pre-run] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.23 + - name: Tests + run: pipx run pre-commit run go-test-mod -a + post-run: + runs-on: runner-latest + needs: [static-analysis,tests] + steps: + - name: Export trace + uses: https://forge.karnov.club/marc/opentelemetry-trace-export-forgejo-action@main + with: + otlp-endpoint: "http://otel.home.karnov.club:4318" + forgejo-token: ${{ secrets.GITHUB_TOKEN }} + forgejo-base-url: ${{ env.GITHUB_SERVER_URL }} + run-id: ${{ env.GITHUB_RUN_NUMBER }} + repo-name: ${{ env.GITHUB_REPOSITORY }} + - name: Notify success + uses: https://forge.karnov.club/marc/push-status-to-discord-action@main + if: ${{always() && success()}} + with: + webhook-url: ${{secrets.DISCORD_WEBHOOK_URL}} + status: "Success" + variant: "success" + - name: Notify failure + uses: https://forge.karnov.club/marc/push-status-to-discord-action@main + if: ${{always() && failure()}} + with: + webhook-url: ${{secrets.DISCORD_WEBHOOK_URL}} + status: "Failure" + variant: "failure" + -- 2.45.2