From ed556dc9deb392dadda26c25b9c06d69d75850f8 Mon Sep 17 00:00:00 2001 From: Tate Date: Mon, 29 Jul 2024 21:15:34 -0600 Subject: [PATCH] Add Start Of CI (#1) --- .githooks/run-unit-tests.sh | 3 +++ .github/workflows/ci.yaml | 31 +++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ .tool-versions | 4 ++++ Makefile | 5 +---- flake.lock | 6 +++--- flake.nix | 10 +++++++++- main_test.go | 1 + shell.nix | 27 +++++++++++++++++++++++---- 9 files changed, 105 insertions(+), 12 deletions(-) create mode 100755 .githooks/run-unit-tests.sh create mode 100644 .github/workflows/ci.yaml create mode 100644 .pre-commit-config.yaml diff --git a/.githooks/run-unit-tests.sh b/.githooks/run-unit-tests.sh new file mode 100755 index 0000000..a8eba55 --- /dev/null +++ b/.githooks/run-unit-tests.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +make test diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..d2c7e6b --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,31 @@ +name: Lint +on: + push: + branches: + - main + pull_request: + +jobs: + pre-commit: + name: Pre-commit checks + runs-on: ubuntu-latest + steps: + - name: Checkout the Repo + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + fetch-depth: 0 # needed for pre-commit to work correctly + - name: Install Nix + uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b # v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + - name: Run pre-commit checks + env: + BASE_REF: ${{ github.base_ref }} + HEAD_REF: ${{ github.head_ref }} + run: | + nix develop -c sh -c "\ + git fetch origin ${BASE_REF}:${BASE_REF} &&\ + git fetch origin ${HEAD_REF}:${HEAD_REF} &&\ + gitdiffs=\$(git diff --name-only ${BASE_REF}...${HEAD_REF} | xargs) &&\ + echo \"changed files: \$gitdiffs\" &&\ + pre-commit run --hook-stage pre-push --show-diff-on-failure --color=always --files \${gitdiffs}" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b1dcd7c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: + - repo: https://github.com/tateexon/pre-commit-hooks + rev: ae90cefa2ad60cd90b16bab285751b2ad4a7e7a6 # v0.0.1 + hooks: + - id: go-lint + - id: go-mod-tidy + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # v4.6.0 + hooks: + - id: detect-private-key + - id: detect-aws-credentials + args: [--allow-missing-credentials] + - id: check-added-large-files + - id: check-json + - id: check-toml + - id: end-of-file-fixer + - id: check-case-conflict + - id: check-shebang-scripts-are-executable + - id: check-merge-conflict + - id: trailing-whitespace + - id: mixed-line-ending + args: ['--fix=lf'] + - repo: local + hooks: + - id: run-unit-tests + name: Run unit tests + entry: ./.githooks/run-unit-tests.sh + language: script + pass_filenames: false + stages: [pre-push] diff --git a/.tool-versions b/.tool-versions index 5705d07..5c9eee7 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,7 @@ golang 1.22.5 golangci-lint 1.59.1 typos 1.23.3 +shfmt 3.8.0 +shellcheck 0.10.0 +python 2.7.18 +pre-commit 2.7.1 diff --git a/Makefile b/Makefile index ad350c0..5c80599 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,6 @@ lint_fix: golangci-lint run --fix test: - go test -timeout 5m ./... - -test_cover: go test -timeout 5m -cover -covermode=count ./... build: @@ -19,4 +16,4 @@ eat_dogfood: go test -timeout 5m -cover -covermode=count $(shell go run main.go -b=origin/main -l=0) typos: - typos \ No newline at end of file + typos diff --git a/flake.lock b/flake.lock index 94ed893..f872074 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1712439257, - "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=", + "lastModified": 1722062969, + "narHash": "sha256-QOS0ykELUmPbrrUGmegAUlpmUFznDQeR4q7rFhl8eQg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599", + "rev": "b73c2221a46c13557b1b3be9c2070cc42cf01eb3", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 962a862..d65e194 100644 --- a/flake.nix +++ b/flake.nix @@ -9,7 +9,15 @@ outputs = inputs@{ self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; overlays = [ ]; }; + pkgs = import nixpkgs { + inherit system; + overlays = [ ]; + config = { + permittedInsecurePackages = [ + "python-2.7.18.8" + ]; + }; + }; in rec { devShell = pkgs.callPackage ./shell.nix { inherit pkgs; diff --git a/main_test.go b/main_test.go index 85e48f7..0e45924 100644 --- a/main_test.go +++ b/main_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tateexon/go-change-delta/golang" "github.com/tateexon/go-change-delta/utils" ) diff --git a/shell.nix b/shell.nix index 611bd8d..29d0292 100644 --- a/shell.nix +++ b/shell.nix @@ -10,23 +10,42 @@ let in mkShell' { nativeBuildInputs = [ + # basics + bash git - go curl + gnumake + jq + dasel + github-cli + + # go + go go-mockery gotools gopls delve golangci-lint - github-cli - jq - dasel + + # linting tools typos + pre-commit + python + shfmt + shellcheck ]; CGO_ENABLED = "0"; shellHook = '' + # Uninstall pre-commit hooks in case they get messed up + pre-commit uninstall > /dev/null || true + pre-commit uninstall --hook-type pre-push > /dev/null || true + + # enable pre-commit hooks + pre-commit install > /dev/null + pre-commit install -f --hook-type pre-push > /dev/null + # install gotestloghelper go install github.com/smartcontractkit/chainlink-testing-framework/tools/gotestloghelper@latest '';