From 93c6a9a652460f89fc719024c435cacbb235d302 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 25 May 2023 09:33:31 +0800 Subject: [PATCH] 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 --- .github/file-filters.yml | 15 +++++++ .github/workflows/files-changed.yml | 32 ++++++++++++++ .github/workflows/pull-compliance-docs.yml | 8 ++-- .../workflows/pull-compliance-docsignore.yml | 43 ------------------- .github/workflows/pull-compliance.yml | 18 ++++++-- .../workflows/pull-db-tests-docsignore.yml | 38 ---------------- .github/workflows/pull-db-tests.yml | 18 ++++++-- .../pull-docker-dryrun-docsignore.yml | 13 ------ .github/workflows/pull-docker-dryrun.yml | 8 ++-- .../workflows/pull-e2e-tests-docsignore.yml | 13 ------ .github/workflows/pull-e2e-tests.yml | 8 ++-- Makefile | 7 +++ 12 files changed, 99 insertions(+), 122 deletions(-) create mode 100644 .github/file-filters.yml create mode 100644 .github/workflows/files-changed.yml delete mode 100644 .github/workflows/pull-compliance-docsignore.yml delete mode 100644 .github/workflows/pull-db-tests-docsignore.yml delete mode 100644 .github/workflows/pull-docker-dryrun-docsignore.yml delete mode 100644 .github/workflows/pull-e2e-tests-docsignore.yml diff --git a/.github/file-filters.yml b/.github/file-filters.yml new file mode 100644 index 000000000000..26231c936423 --- /dev/null +++ b/.github/file-filters.yml @@ -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" diff --git a/.github/workflows/files-changed.yml b/.github/workflows/files-changed.yml new file mode 100644 index 000000000000..2efd6767197d --- /dev/null +++ b/.github/workflows/files-changed.yml @@ -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 diff --git a/.github/workflows/pull-compliance-docs.yml b/.github/workflows/pull-compliance-docs.yml index 44db6d67af10..be0ecc322064 100644 --- a/.github/workflows/pull-compliance-docs.yml +++ b/.github/workflows/pull-compliance-docs.yml @@ -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 diff --git a/.github/workflows/pull-compliance-docsignore.yml b/.github/workflows/pull-compliance-docsignore.yml deleted file mode 100644 index ea0619e122eb..000000000000 --- a/.github/workflows/pull-compliance-docsignore.yml +++ /dev/null @@ -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" diff --git a/.github/workflows/pull-compliance.yml b/.github/workflows/pull-compliance.yml index ace2b15a9b5f..e108379b3096 100644 --- a/.github/workflows/pull-compliance.yml +++ b/.github/workflows/pull-compliance.yml @@ -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 diff --git a/.github/workflows/pull-db-tests-docsignore.yml b/.github/workflows/pull-db-tests-docsignore.yml deleted file mode 100644 index c04f763c3e93..000000000000 --- a/.github/workflows/pull-db-tests-docsignore.yml +++ /dev/null @@ -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" diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index b3b02f15caf2..cf08da151246 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -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: diff --git a/.github/workflows/pull-docker-dryrun-docsignore.yml b/.github/workflows/pull-docker-dryrun-docsignore.yml deleted file mode 100644 index 7c74efb34a9d..000000000000 --- a/.github/workflows/pull-docker-dryrun-docsignore.yml +++ /dev/null @@ -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" diff --git a/.github/workflows/pull-docker-dryrun.yml b/.github/workflows/pull-docker-dryrun.yml index c3cdefc7a7dc..89b0c5253c37 100644 --- a/.github/workflows/pull-docker-dryrun.yml +++ b/.github/workflows/pull-docker-dryrun.yml @@ -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 diff --git a/.github/workflows/pull-e2e-tests-docsignore.yml b/.github/workflows/pull-e2e-tests-docsignore.yml deleted file mode 100644 index e809af7216b1..000000000000 --- a/.github/workflows/pull-e2e-tests-docsignore.yml +++ /dev/null @@ -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" diff --git a/.github/workflows/pull-e2e-tests.yml b/.github/workflows/pull-e2e-tests.yml index 611a6b07417f..cf6af401f5ea 100644 --- a/.github/workflows/pull-e2e-tests.yml +++ b/.github/workflows/pull-e2e-tests.yml @@ -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 diff --git a/Makefile b/Makefile index 6873cac81175..16841796b78e 100644 --- a/Makefile +++ b/Makefile @@ -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