Skip to content

Commit

Permalink
Add Start Of CI (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon authored Jul 30, 2024
1 parent 79f7892 commit ed556dc
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .githooks/run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

make test
31 changes: 31 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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}"
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 4 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
typos
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
27 changes: 23 additions & 4 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';
Expand Down

0 comments on commit ed556dc

Please sign in to comment.