1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-29 20:53:10 +00:00

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:
pull_request:
paths:
- "docs/**"
- "*.md"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
compliance-docs:
if: needs.files-changed.outputs.docs == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- 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:
pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
lint-backend:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -24,6 +26,8 @@ jobs:
env:
TAGS: bindata sqlite sqlite_unlock_notify
lint-go-windows:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -38,6 +42,8 @@ jobs:
GOOS: windows
GOARCH: amd64
lint-go-gogit:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -50,6 +56,8 @@ jobs:
env:
TAGS: bindata gogit sqlite sqlite_unlock_notify
checks-backend:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -60,6 +68,8 @@ jobs:
- run: make deps-backend deps-tools
- run: make --always-make checks-backend # ensure the "go-licenses" make target runs
frontend:
if: needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -70,6 +80,8 @@ jobs:
- run: make lint-frontend
- run: make checks-frontend
backend:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- 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:
pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
test-pgsql:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
services:
pgsql:
@ -56,6 +58,8 @@ jobs:
USE_REPO_TEST_DIR: 1
test-sqlite:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -75,6 +79,8 @@ jobs:
USE_REPO_TEST_DIR: 1
test-unit:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
runs-on: ubuntu-latest
services:
mysql:
@ -138,6 +144,8 @@ jobs:
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
test-mysql5:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
services:
mysql:
@ -180,6 +188,8 @@ jobs:
TEST_INDEXER_CODE_ES_URL: "http://elastic:changeme@elasticsearch:9200"
test-mysql8:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
services:
mysql8:
@ -207,6 +217,8 @@ jobs:
USE_REPO_TEST_DIR: 1
test-mssql:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
services:
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:
pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
docker-dryrun:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- 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:
pull_request:
paths-ignore:
- "docs/**"
- "*.md"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
files-changed:
uses: ./.github/workflows/files-changed.yml
test-e2e:
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- 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
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@latest
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@latest
DOCKER_IMAGE ?= gitea/gitea
DOCKER_TAG ?= latest
@ -199,6 +200,7 @@ help:
@echo " - deps-tools install tool dependencies"
@echo " - lint lint everything"
@echo " - lint-fix lint everything and fix issues"
@echo " - lint-actions lint action workflow files"
@echo " - lint-frontend lint frontend files"
@echo " - lint-frontend-fix lint frontend files and fix issues"
@echo " - lint-backend lint backend files"
@ -411,6 +413,10 @@ lint-go-vet:
lint-editorconfig:
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .github/workflows
.PHONY: lint-actions
lint-actions:
$(GO) run $(ACTIONLINT_PACKAGE)
.PHONY: watch
watch:
@bash build/watch.sh
@ -908,6 +914,7 @@ deps-tools:
$(GO) install $(XGO_PACKAGE)
$(GO) install $(GO_LICENSES_PACKAGE)
$(GO) install $(GOVULNCHECK_PACKAGE)
$(GO) install $(ACTIONLINT_PACKAGE)
node_modules: package-lock.json
npm install --no-save