Skip to content

Commit 86e9d52

Browse files
CICD: Split pr_check_git_status into separate jobs for better PR feedback (#4079)
A change I've been wanting to make for a while! Now each check shows up individually in the PR checks UI. * Split the single `check-git-status` job into 6 parallel jobs (`go fmt`, `prettier`, `fmtjson`, `go mod tidy`, `go generate`, `go fix`) so each check appears individually in the PR checks UI * Add two new checks that were missing from CI: `prettier` for `pkg/js/helpers.js` and `go fix` * https://github.com/StackExchange/dnscontrol/pull/4078/changes#diff-f990c542c14104da05b90b1655e36d22706ee86587f58ef26f1bdd1144f29d9dR25 * Add developer documentation describing all PR checks and how to fix failures locally * [PR Checks Overview](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#pr-checks-overview) * [Check: git status](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#check-git-status) * [Check: go fmt](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#check-go-fmt) * [Check: prettier](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#check-prettier) * [Check: fmtjson](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#check-fmtjson) * [Check: go mod tidy](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#check-go-mod-tidy) * [Check: go generate](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#check-go-generate) * [Check: go fix](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#check-go-fix) * [Lint](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#lint) * [Build & Test](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#build-and-test) * [Running all checks at once](https://docs.dnscontrol.org/\~/revisions/uJ7w3kuQrJefuU6PEbc6/developer-info/github-actions#running-all-checks-at-once) --------- Co-authored-by: Tom Limoncelli <[email protected]>
1 parent d70cbe8 commit 86e9d52

File tree

3 files changed

+208
-2
lines changed

3 files changed

+208
-2
lines changed

.github/workflows/pr_check_git_status.yml

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
check-git-status:
10+
go-fmt:
11+
name: "Check: go fmt"
1112
runs-on: ubuntu-latest
1213
steps:
1314
- uses: actions/checkout@v6
@@ -17,11 +18,91 @@ jobs:
1718
- uses: actions/setup-go@v6
1819
with:
1920
go-version: stable
20-
- run: go install golang.org/x/tools/cmd/stringer@latest
2121
- run: go fmt ./...
22+
- uses: CatChen/check-git-status-action@v1
23+
with:
24+
fail-if-not-clean: true
25+
26+
prettier:
27+
name: "Check: prettier"
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v6
31+
with:
32+
repository: ${{ github.event.pull_request.head.repo.full_name }}
33+
ref: ${{ github.event.pull_request.head.ref }}
34+
- uses: actions/setup-node@v4
35+
with:
36+
node-version: lts/*
37+
- run: npm install
38+
- run: node_modules/.bin/prettier --write pkg/js/helpers.js
39+
- run: git checkout -- package-lock.json
40+
- uses: CatChen/check-git-status-action@v1
41+
with:
42+
fail-if-not-clean: true
43+
44+
fmtjson:
45+
name: "Check: fmtjson"
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v6
49+
with:
50+
repository: ${{ github.event.pull_request.head.repo.full_name }}
51+
ref: ${{ github.event.pull_request.head.ref }}
52+
- uses: actions/setup-go@v6
53+
with:
54+
go-version: stable
55+
- run: go build -o dnscontrol .
2256
- run: bin/fmtjson $(find . -type f -name "*.json" ! -name "package-lock.json" -print)
57+
- uses: CatChen/check-git-status-action@v1
58+
with:
59+
fail-if-not-clean: true
60+
61+
go-mod-tidy:
62+
name: "Check: go mod tidy"
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v6
66+
with:
67+
repository: ${{ github.event.pull_request.head.repo.full_name }}
68+
ref: ${{ github.event.pull_request.head.ref }}
69+
- uses: actions/setup-go@v6
70+
with:
71+
go-version: stable
2372
- run: go mod tidy
73+
- uses: CatChen/check-git-status-action@v1
74+
with:
75+
fail-if-not-clean: true
76+
77+
go-generate:
78+
name: "Check: go generate"
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v6
82+
with:
83+
repository: ${{ github.event.pull_request.head.repo.full_name }}
84+
ref: ${{ github.event.pull_request.head.ref }}
85+
- uses: actions/setup-go@v6
86+
with:
87+
go-version: stable
88+
- run: go install golang.org/x/tools/cmd/stringer@latest
2489
- run: go generate ./...
2590
- uses: CatChen/check-git-status-action@v1
2691
with:
2792
fail-if-not-clean: true
93+
94+
go-fix:
95+
name: "Check: go fix"
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@v6
99+
with:
100+
repository: ${{ github.event.pull_request.head.repo.full_name }}
101+
ref: ${{ github.event.pull_request.head.ref }}
102+
- uses: actions/setup-go@v6
103+
with:
104+
go-version: stable
105+
- run: go fix ./...
106+
- uses: CatChen/check-git-status-action@v1
107+
with:
108+
fail-if-not-clean: true

documentation/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
* [Code Style Guide](advanced-features/styleguide-code.md)
202202
* [Documentation Style Guide](advanced-features/styleguide-doc.md)
203203
* [DNSControl is an opinionated system](advanced-features/opinions.md)
204+
* [GitHub actions](developer-info/github-actions.md)
204205
* [Writing new DNS providers](advanced-features/writing-providers.md)
205206
* [Creating new DNS Resource Types (rtypes)](advanced-features/adding-new-rtypes.md)
206207
* [Integration Tests](advanced-features/integration-tests.md)
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# GitHub Actions
2+
3+
## PR Checks Overview
4+
5+
Every pull request runs the following GitHub Actions workflows. All checks must pass before a PR can be merged.
6+
7+
| Workflow | File | Description |
8+
|---|---|---|
9+
| **Check git status** | `pr_check_git_status.yml` | Ensures all generated/formatted files are committed |
10+
| **Lint** | `pr_lint.yml` | Runs `golangci-lint` |
11+
| **Build & Test** | `pr_build.yml` | Runs unit tests and builds binaries via GoReleaser |
12+
13+
## Check: git status
14+
15+
The git status workflow runs formatting and code generation commands, then verifies no files were modified. If any command produces uncommitted changes, that specific check fails.
16+
17+
Each check runs as a **separate job**, so you can immediately see which one failed in the PR checks UI.
18+
19+
### Check: go fmt
20+
21+
**What it does:** Formats all Go source files using `go fmt`.
22+
23+
**How to fix locally:**
24+
25+
```bash
26+
go fmt ./...
27+
```
28+
29+
Commit the resulting changes.
30+
31+
### Check: prettier
32+
33+
**What it does:** Formats `pkg/js/helpers.js` using [Prettier](https://prettier.io/).
34+
35+
**How to fix locally:**
36+
37+
```bash
38+
npm install
39+
node_modules/.bin/prettier --write pkg/js/helpers.js
40+
```
41+
42+
Commit the resulting changes. Prettier configuration is in `.prettierrc`.
43+
44+
### Check: fmtjson
45+
46+
**What it does:** Formats all JSON files in the repository (except `package-lock.json`) using `bin/fmtjson`.
47+
48+
**How to fix locally:**
49+
50+
```bash
51+
bin/fmtjson $(find . -path ./.vscode -prune -o -type f -name "*.json" ! -name "package-lock.json" -print)
52+
```
53+
54+
Commit the resulting changes.
55+
56+
### Check: go mod tidy
57+
58+
**What it does:** Cleans up `go.mod` and `go.sum` by removing unused dependencies and adding missing ones.
59+
60+
**How to fix locally:**
61+
62+
```bash
63+
go mod tidy
64+
```
65+
66+
Commit the resulting changes to `go.mod` and `go.sum`.
67+
68+
### Check: go generate
69+
70+
**What it does:** Runs all `//go:generate` directives in the codebase. This generates TypeScript type definitions, the feature matrix, and the OWNERS file. Requires `stringer` to be installed.
71+
72+
**How to fix locally:**
73+
74+
```bash
75+
go install golang.org/x/tools/cmd/stringer@latest
76+
go generate ./...
77+
```
78+
79+
Commit the resulting changes.
80+
81+
### Check: go fix
82+
83+
**What it does:** Runs `go fix` to update packages to use newer APIs when Go introduces changes.
84+
85+
**How to fix locally:**
86+
87+
```bash
88+
go fix ./...
89+
```
90+
91+
Commit the resulting changes.
92+
93+
## Lint
94+
95+
Runs [`golangci-lint`](https://golangci-lint.run/) with the configuration in `.golangci.yml`.
96+
97+
**How to fix locally:**
98+
99+
```bash
100+
golangci-lint run ./...
101+
```
102+
103+
See `.golangci.yml` for the list of enabled linters and their settings.
104+
105+
## Build & Test
106+
107+
Runs all unit tests with `gotestsum` and builds binaries for all platforms using GoReleaser.
108+
109+
**How to run locally:**
110+
111+
```bash
112+
go test ./...
113+
go build .
114+
```
115+
116+
## Running all checks at once
117+
118+
The `bin/generate-all.sh` script runs most of the above checks in sequence:
119+
120+
```bash
121+
bin/generate-all.sh
122+
```
123+
124+
This is useful before committing to catch all formatting and generation issues at once.

0 commit comments

Comments
 (0)