From 70a531243abad2fe855dc343145eea215c84a75d Mon Sep 17 00:00:00 2001 From: Tate Exon Date: Wed, 31 Jul 2024 08:32:17 -0600 Subject: [PATCH] add start of github action --- .github/CODEOWNERS | 1 + .github/actions/go-change-delta/action.yaml | 61 +++++++++++++++++++++ .github/actions/load-nix/action.yaml | 13 +++++ .github/workflows/{ci.yaml => lint.yaml} | 9 +-- .github/workflows/test.yaml | 25 +++++++++ .gitignore | 2 +- 6 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/actions/go-change-delta/action.yaml create mode 100644 .github/actions/load-nix/action.yaml rename .github/workflows/{ci.yaml => lint.yaml} (82%) create mode 100644 .github/workflows/test.yaml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..4cc1eed --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @tateexon diff --git a/.github/actions/go-change-delta/action.yaml b/.github/actions/go-change-delta/action.yaml new file mode 100644 index 0000000..e37350b --- /dev/null +++ b/.github/actions/go-change-delta/action.yaml @@ -0,0 +1,61 @@ +name: 'Update Internal Mirrors Action' +inputs: + version: + description: The go-change-delta version you wish to use + required: false + default: latest + install: + description: Should we install go-change-delta + required: false + default: 'true' + use-nix: + description: Should nix be used under the hood, requires this projects load-nix action + required: false + default: 'false' + base-ref: + description: The base ref to compare results against, typically this is main + required: false + default: ${{ github.base_ref }} + depth: + description: The depth of recursion to check, 0 is default and infinite and will get all packages at any depth + required: false + default: '0' + path: + description: The path to the root of the go module, if this is a a go module not at the root this is helpful + required: false + default: "" + exclude: + description: A comma separated list of paths to exclude from the checks + required: false + default: "" + include-test: + description: Should include test only package changes + required: false + default: true +outputs: + packages: + description: Affected Packages + value: ${{ steps.delta.outputs.packages || '' }} +runs: + using: 'composite' + steps: + - name: Install go-change-delta + if: inputs.install == 'true' + shell: bash + run: | + if [ "${{ inputs.use-nix }}" == "false" ]; then + go install github.com/tateexon/go-change-delta@${{ inputs.version }} + else + nix develop -c sh -c "go install github.com/tateexon/go-change-delta@${{ inputs.version }}" + fi + - name: Get Packages Delta + id: delta + shell: bash + run: | + packages="" + if [ "${{ inputs.use-nix }}" == "false" ]; then + packages=$(go-change-delta -b=${{inputs.base-ref}} -l=${{inputs.depth}} -p=${{inputs.path}} -e=${{inputs.exclude}} -t=${{inputs.include-test}}) + else + packages=$(nix develop -c -sh "go-change-delta -b=${{inputs.base-ref}} -l=${{inputs.depth}} -p=${{inputs.path}} -e=${{inputs.exclude}} -t=${{inputs.include-test}}") + fi + echo "packages=${packages}" >> $GITHUB_OUTPUT diff --git a/.github/actions/load-nix/action.yaml b/.github/actions/load-nix/action.yaml new file mode 100644 index 0000000..dd63e6d --- /dev/null +++ b/.github/actions/load-nix/action.yaml @@ -0,0 +1,13 @@ +name: Load Nix +description: Load nix and setup a cleaner alias on `n` to run bash from within nix +runs: + using: 'composite' + steps: + - name: Install Nix + uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b # v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + - name: Pre-Load Nix + shell: bash + run: | + nix develop -c sh -c "echo \"load\"" diff --git a/.github/workflows/ci.yaml b/.github/workflows/lint.yaml similarity index 82% rename from .github/workflows/ci.yaml rename to .github/workflows/lint.yaml index d2c7e6b..e1d1474 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/lint.yaml @@ -14,10 +14,11 @@ jobs: 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: Load Nix + uses: ./.github/actions/load-nix + - name: Validate Pre-Commit Config + shell: bash + run: nix develop -c sh -c "pre-commit validate-config" - name: Run pre-commit checks env: BASE_REF: ${{ github.base_ref }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..98de9ce --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,25 @@ +name: Test +on: + push: + branches: + - main + pull_request: + +jobs: + pre-commit: + name: Run Go Tests + 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: Load Nix + uses: ./.github/actions/load-nix + - name: Get Affected Packages + uses: ./.github/actions/go-change-delta + id: delta + with: + use-nix: 'true' + - name: Run Tests + run: nix develop -c sh -c "go test -timeout 5m -cover -covermode=count ${{ steps.delta.outputs.packages }}" diff --git a/.gitignore b/.gitignore index a19e521..ed64e01 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -go-change-delta +/go-change-delta unit-test-coverage.out