From 54f3f99806e1d4b28ed2323e26dbd1a9dedeb4dc Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Thu, 2 Nov 2023 12:53:38 -0600 Subject: [PATCH 1/4] Run CI on a PR --- .github/development.env | 3 +++ .github/workflows/PR.yml | 17 ++++++++++++++ .github/workflows/{build.yaml => build.yml} | 4 +--- .github/workflows/unit.yml | 25 +++++++++++++++++++++ .github/workflows/vet.yml | 25 +++++++++++++++++++++ 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 .github/development.env create mode 100644 .github/workflows/PR.yml rename .github/workflows/{build.yaml => build.yml} (84%) create mode 100644 .github/workflows/unit.yml create mode 100644 .github/workflows/vet.yml diff --git a/.github/development.env b/.github/development.env new file mode 100644 index 00000000..f20dcf72 --- /dev/null +++ b/.github/development.env @@ -0,0 +1,3 @@ +GO_VERSION=1.21.3 + +UNIT_TEST_SCOPE=./cmd/... ./pkg/... diff --git a/.github/workflows/PR.yml b/.github/workflows/PR.yml new file mode 100644 index 00000000..13704de9 --- /dev/null +++ b/.github/workflows/PR.yml @@ -0,0 +1,17 @@ +name: PR + +on: + pull_request: + types: ['opened', 'reopened', 'synchronize'] + branches: [ "main" ] + paths: + - '**' # all files otherwise excludes wont work + - '!**/**/*.md' # ignore markdown files + +jobs: + vet: + uses: ./.github/workflows/vet.yml + unit-test: + uses: ./.github/workflows/unit.yml + build: + uses: ./.github/workflows/build.yml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yml similarity index 84% rename from .github/workflows/build.yaml rename to .github/workflows/build.yml index d5a6e5b7..767ba916 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yml @@ -1,9 +1,7 @@ name: Build Docker Image on: - pull_request: - types: [ opened, synchronize, reopened ] - branches: [ "main" ] + workflow_call: jobs: build: diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml new file mode 100644 index 00000000..9240edab --- /dev/null +++ b/.github/workflows/unit.yml @@ -0,0 +1,25 @@ +name: Run Unit Tests + +on: + workflow_call: + +jobs: + unit-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Load environment + uses: c-py/action-dotenv-to-setenv@v4 + with: + env-file: .github/development.env + + - name: Setup Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Run Unit Tests + working-directory: . + run: make test diff --git a/.github/workflows/vet.yml b/.github/workflows/vet.yml new file mode 100644 index 00000000..0bcb569c --- /dev/null +++ b/.github/workflows/vet.yml @@ -0,0 +1,25 @@ +name: Vet Go Code + +on: + workflow_call: + +jobs: + vet: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Load environment + uses: c-py/action-dotenv-to-setenv@v4 + with: + env-file: .github/development.env + + - name: Setup Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Vet Go Code + working-directory: . + run: make vet From 6cf7ef91e2283f43ba1e247e5ebd58a8a3844505 Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Thu, 2 Nov 2023 13:08:19 -0600 Subject: [PATCH 2/4] Add a readme --- .github/workflows/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/workflows/README.md diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 00000000..c9c3f5dc --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,11 @@ +# Workflows + +There are two types of workflows in this directory. I would put them in subfolders but GitHub doesn't support that. + +## Callers + +These are the high level workflows that can be associated with what triggers them. PRs, releases, nightlys, merges, etc. These are made up of jobs that are defined the the other workflows. These are the workflows that you will see in the Actions tab of the repo. By grouping these tasks into parent workflows, the jobs are grouped under one action in the actions tab. They share the smaller 'job' workflows so that they always run the same way. + +## Jobs + +These are the smaller individual tasks that are used to build up the larger parent workflows. They can be thought of as running unit tests, building the binaries, or linting the code. When you open one of the parent caller actions in the actions tab, they will show these individual jobs. From be477b4356f4211940bb0975c1b328ec12420e19 Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Thu, 2 Nov 2023 13:23:04 -0600 Subject: [PATCH 3/4] Additional ignores --- .github/workflows/PR.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/PR.yml b/.github/workflows/PR.yml index 13704de9..bd4b9b75 100644 --- a/.github/workflows/PR.yml +++ b/.github/workflows/PR.yml @@ -7,6 +7,9 @@ on: paths: - '**' # all files otherwise excludes wont work - '!**/**/*.md' # ignore markdown files + - '!demo/**' # ignore demos folder + - '!sample/**' # ignore samples folder + - '!example/**' # ignore examples folder jobs: vet: From b46c4db66e2b21e463932b7212a4b910166e7be7 Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Thu, 2 Nov 2023 13:45:42 -0600 Subject: [PATCH 4/4] Add to README --- .github/workflows/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index c9c3f5dc..ff9f4db3 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -4,8 +4,8 @@ There are two types of workflows in this directory. I would put them in subfolde ## Callers -These are the high level workflows that can be associated with what triggers them. PRs, releases, nightlys, merges, etc. These are made up of jobs that are defined the the other workflows. These are the workflows that you will see in the Actions tab of the repo. By grouping these tasks into parent workflows, the jobs are grouped under one action in the actions tab. They share the smaller 'job' workflows so that they always run the same way. +These are the high level workflows that can be associated with what triggers them. PRs, releases, nightlys, merges, etc. These are made up of jobs that are defined the the other workflows. These are the workflows that you will see in the Actions tab of the repo. By grouping these tasks into parent workflows, the jobs are grouped under one action in the actions tab. They share the smaller 'job' workflows so that they always run the same way. Convention has become to capitalize the first letter of these workflow's name. ## Jobs -These are the smaller individual tasks that are used to build up the larger parent workflows. They can be thought of as running unit tests, building the binaries, or linting the code. When you open one of the parent caller actions in the actions tab, they will show these individual jobs. +These are the smaller individual tasks that are used to build up the larger parent workflows. They can be thought of as running unit tests, building the binaries, or linting the code. When you open one of the parent caller actions in the actions tab, they will show these individual jobs. Convention has become to lowercase the first letter of these workflow's name.