forked from gitea/gitea
1
0
Fork 0

Use file filters action instead of Github's files filter (#24877)

Inspired by
https://github.com/go-gitea/gitea/pull/24530#issuecomment-1558815301

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 <me@silverwind.io>
This commit is contained in:
Lunny Xiao 2023-05-25 09:33:31 +08:00 committed by GitHub
parent d7e669c371
commit 93c6a9a652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 99 additions and 122 deletions

15
.github/file-filters.yml vendored Normal file
View File

@ -0,0 +1,15 @@
docs: &docs
- "**/*.md"
- "docs/**"
backend: &backend
- "**/*.go"
- "**/*.tmpl"
- "go.mod"
- "go.sum"
frontend: &frontend
- "**/*.js"
- "web_src/**"
- "package.json"
- "package-lock.json"

32
.github/workflows/files-changed.yml vendored Normal file
View File

@ -0,0 +1,32 @@
name: files changed
on:
workflow_call:
outputs:
docs:
description: "whether docs files changed"
value: ${{ jobs.files-changed.outputs.docs }}
backend:
description: "whether backend files changed"
value: ${{ jobs.files-changed.outputs.backend }}
frontend:
description: "whether frontend files changed"
value: ${{ jobs.files-changed.outputs.frontend }}
jobs:
files-changed:
name: detect which files changed
runs-on: ubuntu-latest
timeout-minutes: 3
# Map a step output to a job output
outputs:
docs: ${{ steps.changes.outputs.docs }}
backend: ${{ steps.changes.outputs.backend }}
frontend: ${{ steps.changes.outputs.frontend }}
steps:
- uses: actions/checkout@v3
- name: Check for backend file changes
uses: dorny/paths-filter@v2
id: changes
with:
filters: .github/file-filters.yml

View File

@ -2,16 +2,18 @@ name: compliance-docs
on: on:
pull_request: pull_request:
paths:
- "docs/**"
- "*.md"
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
compliance-docs: compliance-docs:
if: needs.files-changed.outputs.docs == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@ -1,43 +0,0 @@
name: compliance
on:
pull_request:
paths:
- "docs/**"
- "*.md"
jobs:
compliance-docs:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
lint-backend:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
lint-go-windows:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
lint-go-gogit:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
checks-backend:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
frontend:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
backend:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"

View File

@ -2,16 +2,18 @@ name: compliance
on: on:
pull_request: pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
lint-backend: lint-backend:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -24,6 +26,8 @@ jobs:
env: env:
TAGS: bindata sqlite sqlite_unlock_notify TAGS: bindata sqlite sqlite_unlock_notify
lint-go-windows: lint-go-windows:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -38,6 +42,8 @@ jobs:
GOOS: windows GOOS: windows
GOARCH: amd64 GOARCH: amd64
lint-go-gogit: lint-go-gogit:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -50,6 +56,8 @@ jobs:
env: env:
TAGS: bindata gogit sqlite sqlite_unlock_notify TAGS: bindata gogit sqlite sqlite_unlock_notify
checks-backend: checks-backend:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -60,6 +68,8 @@ jobs:
- run: make deps-backend deps-tools - run: make deps-backend deps-tools
- run: make --always-make checks-backend # ensure the "go-licenses" make target runs - run: make --always-make checks-backend # ensure the "go-licenses" make target runs
frontend: frontend:
if: needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -70,6 +80,8 @@ jobs:
- run: make lint-frontend - run: make lint-frontend
- run: make checks-frontend - run: make checks-frontend
backend: backend:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@ -1,38 +0,0 @@
name: db-tests
on:
pull_request:
paths:
- "docs/**"
- "*.md"
jobs:
test-pgsql:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
test-sqlite:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
test-unit:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
test-mysql5:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
test-mysql8:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"
test-mssql:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"

View File

@ -2,16 +2,18 @@ name: db-tests
on: on:
pull_request: pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
test-pgsql: test-pgsql:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
services: services:
pgsql: pgsql:
@ -56,6 +58,8 @@ jobs:
USE_REPO_TEST_DIR: 1 USE_REPO_TEST_DIR: 1
test-sqlite: test-sqlite:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -75,6 +79,8 @@ jobs:
USE_REPO_TEST_DIR: 1 USE_REPO_TEST_DIR: 1
test-unit: test-unit:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
services: services:
mysql: mysql:
@ -138,6 +144,8 @@ jobs:
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }} GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
test-mysql5: test-mysql5:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
services: services:
mysql: mysql:
@ -180,6 +188,8 @@ jobs:
TEST_INDEXER_CODE_ES_URL: "http://elastic:changeme@elasticsearch:9200" TEST_INDEXER_CODE_ES_URL: "http://elastic:changeme@elasticsearch:9200"
test-mysql8: test-mysql8:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
services: services:
mysql8: mysql8:
@ -207,6 +217,8 @@ jobs:
USE_REPO_TEST_DIR: 1 USE_REPO_TEST_DIR: 1
test-mssql: test-mssql:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
services: services:
mssql: mssql:

View File

@ -1,13 +0,0 @@
name: docker-dryrun
on:
pull_request:
paths:
- "docs/**"
- "*.md"
jobs:
docker-dryrun:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"

View File

@ -2,16 +2,18 @@ name: docker-dryrun
on: on:
pull_request: pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
docker-dryrun: docker-dryrun:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: docker/setup-buildx-action@v2 - uses: docker/setup-buildx-action@v2

View File

@ -1,13 +0,0 @@
name: e2e-tests
on:
pull_request:
paths:
- "docs/**"
- "*.md"
jobs:
test-e2e:
runs-on: ubuntu-latest
steps:
- run: echo "No build required"

View File

@ -2,16 +2,18 @@ name: e2e-tests
on: on:
pull_request: pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
test-e2e: test-e2e:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@ -35,6 +35,7 @@ SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.4
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0 GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@latest GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@latest
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@latest
DOCKER_IMAGE ?= gitea/gitea DOCKER_IMAGE ?= gitea/gitea
DOCKER_TAG ?= latest DOCKER_TAG ?= latest
@ -199,6 +200,7 @@ help:
@echo " - deps-tools install tool dependencies" @echo " - deps-tools install tool dependencies"
@echo " - lint lint everything" @echo " - lint lint everything"
@echo " - lint-fix lint everything and fix issues" @echo " - lint-fix lint everything and fix issues"
@echo " - lint-actions lint action workflow files"
@echo " - lint-frontend lint frontend files" @echo " - lint-frontend lint frontend files"
@echo " - lint-frontend-fix lint frontend files and fix issues" @echo " - lint-frontend-fix lint frontend files and fix issues"
@echo " - lint-backend lint backend files" @echo " - lint-backend lint backend files"
@ -411,6 +413,10 @@ lint-go-vet:
lint-editorconfig: lint-editorconfig:
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .github/workflows $(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .github/workflows
.PHONY: lint-actions
lint-actions:
$(GO) run $(ACTIONLINT_PACKAGE)
.PHONY: watch .PHONY: watch
watch: watch:
@bash build/watch.sh @bash build/watch.sh
@ -908,6 +914,7 @@ deps-tools:
$(GO) install $(XGO_PACKAGE) $(GO) install $(XGO_PACKAGE)
$(GO) install $(GO_LICENSES_PACKAGE) $(GO) install $(GO_LICENSES_PACKAGE)
$(GO) install $(GOVULNCHECK_PACKAGE) $(GO) install $(GOVULNCHECK_PACKAGE)
$(GO) install $(ACTIONLINT_PACKAGE)
node_modules: package-lock.json node_modules: package-lock.json
npm install --no-save npm install --no-save