Skip to content

Commit 93c6a9a

Browse files
lunnysilverwind
andauthored
Use file filters action instead of Github's files filter (#24877)
Inspired by #24530 (comment) This PR use a file filter action to do different CI jobs according changed files types. All types are defined in `.github/file-filters.yml`. Now there are 4 types, `docs`, `backend`, `frontend` and `build`. Then if a PR only changed docs files, those CI jobs which passed the conditions will run, and other types are also like this. --------- Co-authored-by: silverwind <[email protected]>
1 parent d7e669c commit 93c6a9a

12 files changed

+99
-122
lines changed

.github/file-filters.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
docs: &docs
2+
- "**/*.md"
3+
- "docs/**"
4+
5+
backend: &backend
6+
- "**/*.go"
7+
- "**/*.tmpl"
8+
- "go.mod"
9+
- "go.sum"
10+
11+
frontend: &frontend
12+
- "**/*.js"
13+
- "web_src/**"
14+
- "package.json"
15+
- "package-lock.json"

.github/workflows/files-changed.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: files changed
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
docs:
7+
description: "whether docs files changed"
8+
value: ${{ jobs.files-changed.outputs.docs }}
9+
backend:
10+
description: "whether backend files changed"
11+
value: ${{ jobs.files-changed.outputs.backend }}
12+
frontend:
13+
description: "whether frontend files changed"
14+
value: ${{ jobs.files-changed.outputs.frontend }}
15+
16+
jobs:
17+
files-changed:
18+
name: detect which files changed
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 3
21+
# Map a step output to a job output
22+
outputs:
23+
docs: ${{ steps.changes.outputs.docs }}
24+
backend: ${{ steps.changes.outputs.backend }}
25+
frontend: ${{ steps.changes.outputs.frontend }}
26+
steps:
27+
- uses: actions/checkout@v3
28+
- name: Check for backend file changes
29+
uses: dorny/paths-filter@v2
30+
id: changes
31+
with:
32+
filters: .github/file-filters.yml

.github/workflows/pull-compliance-docs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ name: compliance-docs
22

33
on:
44
pull_request:
5-
paths:
6-
- "docs/**"
7-
- "*.md"
85

96
concurrency:
107
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
118
cancel-in-progress: true
129

1310
jobs:
11+
files-changed:
12+
uses: ./.github/workflows/files-changed.yml
13+
1414
compliance-docs:
15+
if: needs.files-changed.outputs.docs == 'true'
16+
needs: files-changed
1517
runs-on: ubuntu-latest
1618
steps:
1719
- uses: actions/checkout@v3

.github/workflows/pull-compliance-docsignore.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/pull-compliance.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ name: compliance
22

33
on:
44
pull_request:
5-
paths-ignore:
6-
- "docs/**"
7-
- "*.md"
85

96
concurrency:
107
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
118
cancel-in-progress: true
129

1310
jobs:
11+
files-changed:
12+
uses: ./.github/workflows/files-changed.yml
13+
1414
lint-backend:
15+
if: needs.files-changed.outputs.backend == 'true'
16+
needs: files-changed
1517
runs-on: ubuntu-latest
1618
steps:
1719
- uses: actions/checkout@v3
@@ -24,6 +26,8 @@ jobs:
2426
env:
2527
TAGS: bindata sqlite sqlite_unlock_notify
2628
lint-go-windows:
29+
if: needs.files-changed.outputs.backend == 'true'
30+
needs: files-changed
2731
runs-on: ubuntu-latest
2832
steps:
2933
- uses: actions/checkout@v3
@@ -38,6 +42,8 @@ jobs:
3842
GOOS: windows
3943
GOARCH: amd64
4044
lint-go-gogit:
45+
if: needs.files-changed.outputs.backend == 'true'
46+
needs: files-changed
4147
runs-on: ubuntu-latest
4248
steps:
4349
- uses: actions/checkout@v3
@@ -50,6 +56,8 @@ jobs:
5056
env:
5157
TAGS: bindata gogit sqlite sqlite_unlock_notify
5258
checks-backend:
59+
if: needs.files-changed.outputs.backend == 'true'
60+
needs: files-changed
5361
runs-on: ubuntu-latest
5462
steps:
5563
- uses: actions/checkout@v3
@@ -60,6 +68,8 @@ jobs:
6068
- run: make deps-backend deps-tools
6169
- run: make --always-make checks-backend # ensure the "go-licenses" make target runs
6270
frontend:
71+
if: needs.files-changed.outputs.frontend == 'true'
72+
needs: files-changed
6373
runs-on: ubuntu-latest
6474
steps:
6575
- uses: actions/checkout@v3
@@ -70,6 +80,8 @@ jobs:
7080
- run: make lint-frontend
7181
- run: make checks-frontend
7282
backend:
83+
if: needs.files-changed.outputs.backend == 'true'
84+
needs: files-changed
7385
runs-on: ubuntu-latest
7486
steps:
7587
- uses: actions/checkout@v3

.github/workflows/pull-db-tests-docsignore.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/pull-db-tests.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ name: db-tests
22

33
on:
44
pull_request:
5-
paths-ignore:
6-
- "docs/**"
7-
- "*.md"
85

96
concurrency:
107
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
118
cancel-in-progress: true
129

1310
jobs:
11+
files-changed:
12+
uses: ./.github/workflows/files-changed.yml
13+
1414
test-pgsql:
15+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
16+
needs: files-changed
1517
runs-on: ubuntu-latest
1618
services:
1719
pgsql:
@@ -56,6 +58,8 @@ jobs:
5658
USE_REPO_TEST_DIR: 1
5759

5860
test-sqlite:
61+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
62+
needs: files-changed
5963
runs-on: ubuntu-latest
6064
steps:
6165
- uses: actions/checkout@v3
@@ -75,6 +79,8 @@ jobs:
7579
USE_REPO_TEST_DIR: 1
7680

7781
test-unit:
82+
if: needs.files-changed.outputs.backend == 'true'
83+
needs: files-changed
7884
runs-on: ubuntu-latest
7985
services:
8086
mysql:
@@ -138,6 +144,8 @@ jobs:
138144
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
139145

140146
test-mysql5:
147+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
148+
needs: files-changed
141149
runs-on: ubuntu-latest
142150
services:
143151
mysql:
@@ -180,6 +188,8 @@ jobs:
180188
TEST_INDEXER_CODE_ES_URL: "http://elastic:changeme@elasticsearch:9200"
181189

182190
test-mysql8:
191+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
192+
needs: files-changed
183193
runs-on: ubuntu-latest
184194
services:
185195
mysql8:
@@ -207,6 +217,8 @@ jobs:
207217
USE_REPO_TEST_DIR: 1
208218

209219
test-mssql:
220+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
221+
needs: files-changed
210222
runs-on: ubuntu-latest
211223
services:
212224
mssql:

.github/workflows/pull-docker-dryrun-docsignore.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/pull-docker-dryrun.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ name: docker-dryrun
22

33
on:
44
pull_request:
5-
paths-ignore:
6-
- "docs/**"
7-
- "*.md"
85

96
concurrency:
107
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
118
cancel-in-progress: true
129

1310
jobs:
11+
files-changed:
12+
uses: ./.github/workflows/files-changed.yml
13+
1414
docker-dryrun:
15+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
16+
needs: files-changed
1517
runs-on: ubuntu-latest
1618
steps:
1719
- uses: docker/setup-buildx-action@v2

.github/workflows/pull-e2e-tests-docsignore.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/pull-e2e-tests.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ name: e2e-tests
22

33
on:
44
pull_request:
5-
paths-ignore:
6-
- "docs/**"
7-
- "*.md"
85

96
concurrency:
107
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
118
cancel-in-progress: true
129

1310
jobs:
11+
files-changed:
12+
uses: ./.github/workflows/files-changed.yml
13+
1414
test-e2e:
15+
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
16+
needs: files-changed
1517
runs-on: ubuntu-latest
1618
steps:
1719
- uses: actions/checkout@v3

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
3535
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/[email protected]
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@latest
38+
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@latest
3839

3940
DOCKER_IMAGE ?= gitea/gitea
4041
DOCKER_TAG ?= latest
@@ -199,6 +200,7 @@ help:
199200
@echo " - deps-tools install tool dependencies"
200201
@echo " - lint lint everything"
201202
@echo " - lint-fix lint everything and fix issues"
203+
@echo " - lint-actions lint action workflow files"
202204
@echo " - lint-frontend lint frontend files"
203205
@echo " - lint-frontend-fix lint frontend files and fix issues"
204206
@echo " - lint-backend lint backend files"
@@ -411,6 +413,10 @@ lint-go-vet:
411413
lint-editorconfig:
412414
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .github/workflows
413415

416+
.PHONY: lint-actions
417+
lint-actions:
418+
$(GO) run $(ACTIONLINT_PACKAGE)
419+
414420
.PHONY: watch
415421
watch:
416422
@bash build/watch.sh
@@ -908,6 +914,7 @@ deps-tools:
908914
$(GO) install $(XGO_PACKAGE)
909915
$(GO) install $(GO_LICENSES_PACKAGE)
910916
$(GO) install $(GOVULNCHECK_PACKAGE)
917+
$(GO) install $(ACTIONLINT_PACKAGE)
911918

912919
node_modules: package-lock.json
913920
npm install --no-save

0 commit comments

Comments
 (0)