From 25accf4d23324eedd2cb6cf24c4aa367b58c811b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Oct 2023 08:48:57 +0200 Subject: [PATCH] Always use the normal action and just make the execution dependent on the changed files Signed-off-by: Joas Schilling --- ...lint-eslint-when-unrelated.properties.json | 14 -- .../lint-eslint-when-unrelated.yml | 102 ------------- workflow-templates/lint-eslint.yml | 50 ++++-- .../node-when-unrelated.properties.json | 11 -- workflow-templates/node-when-unrelated.yml | 107 ------------- workflow-templates/node.yml | 48 ++++-- workflow-templates/phpunit-mysql.yml | 38 +++-- workflow-templates/phpunit-oci.yml | 38 +++-- workflow-templates/phpunit-pgsql.yml | 36 +++-- workflow-templates/phpunit-sqlite.yml | 36 +++-- ...nit-summary-when-unrelated.properties.json | 11 -- .../phpunit-summary-when-unrelated.yml | 143 ------------------ 12 files changed, 168 insertions(+), 466 deletions(-) delete mode 100644 workflow-templates/lint-eslint-when-unrelated.properties.json delete mode 100644 workflow-templates/lint-eslint-when-unrelated.yml delete mode 100644 workflow-templates/node-when-unrelated.properties.json delete mode 100644 workflow-templates/node-when-unrelated.yml delete mode 100644 workflow-templates/phpunit-summary-when-unrelated.properties.json delete mode 100644 workflow-templates/phpunit-summary-when-unrelated.yml diff --git a/workflow-templates/lint-eslint-when-unrelated.properties.json b/workflow-templates/lint-eslint-when-unrelated.properties.json deleted file mode 100644 index 12aa11a1..00000000 --- a/workflow-templates/lint-eslint-when-unrelated.properties.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "Linting JavaScript when unrelated", - "description": "Marks eslint as passed when no JavaScript related files were changed", - "iconName": "lint-eslint", - "categories": [ - "JavaScript", - "Vue", - "TypeScript", - "TSX" - ], - "filePatterns": [ - "^package.json$" - ] -} \ No newline at end of file diff --git a/workflow-templates/lint-eslint-when-unrelated.yml b/workflow-templates/lint-eslint-when-unrelated.yml deleted file mode 100644 index 2bd6c921..00000000 --- a/workflow-templates/lint-eslint-when-unrelated.yml +++ /dev/null @@ -1,102 +0,0 @@ -# This workflow is provided via the organization template repository -# -# https://github.com/nextcloud/.github -# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization -# -# Use lint-eslint together with lint-eslint-when-unrelated to make eslint a required check for GitHub actions -# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks - -name: Lint eslint - -on: - pull_request: - paths-ignore: - - '.github/workflows/**' - - 'src/**' - - 'appinfo/info.xml' - - 'package.json' - - 'package-lock.json' - - 'tsconfig.json' - - '.eslintrc.*' - - '.eslintignore' - - '**.js' - - '**.ts' - - '**.vue' - -env: - PATHS_IGNORE: '.github/workflows/**;src/**;appinfo/info.xml;package.json;package-lock.json;tsconfig.json;.eslintrc.*;.eslintignore;**.js;**.ts;**.vue' - -permissions: - contents: read - -jobs: - action-no-eslint: - permissions: - contents: none - runs-on: ubuntu-latest - - name: action-not-src - outputs: - found_file: ${{ steps.confirm-negative-list.outputs.result }} - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} - - - name: Get changed files from diff - id: changed-files - run: | - if ${{ github.event_name == 'pull_request' }}; then - echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT - else - echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT - fi - - - name: Set up node 20 - uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3 - with: - node-version: 20 - - - name: Install minimatch - run: npm i minimatch - - - name: Check if a file is in paths-ignored - id: confirm-negative-list - uses: actions/github-script@v5 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - result-encoding: string - script: | - const { minimatch } = require('minimatch') - const changedPaths = "${{ steps.changed-files.outputs.changed_files }}".split(' ') - - let matched = '' - process.env.PATHS_IGNORE.split(';').every(pattern => { - changedPaths.every(path => { - console.info('Testing ' + path + ' for pattern ' + pattern) - if (minimatch(path, pattern)) { - console.info(path + ' matched, aborting "unrelated summary"') - matched = '1' - return false - } - return true - }) - return !matched - }) - return matched - - lint: - permissions: - contents: none - - runs-on: ubuntu-latest - - needs: action-no-eslint - - name: eslint - - if: needs.action-no-eslint.outputs.found_file == '' - - steps: - - run: 'echo "No eslint required"' diff --git a/workflow-templates/lint-eslint.yml b/workflow-templates/lint-eslint.yml index 35bd4404..079eed1f 100644 --- a/workflow-templates/lint-eslint.yml +++ b/workflow-templates/lint-eslint.yml @@ -10,18 +10,6 @@ name: Lint eslint on: pull_request: - paths: - - '.github/workflows/**' - - 'src/**' - - 'appinfo/info.xml' - - 'package.json' - - 'package-lock.json' - - 'tsconfig.json' - - '.eslintrc.*' - - '.eslintignore' - - '**.js' - - '**.ts' - - '**.vue' permissions: contents: read @@ -31,10 +19,31 @@ concurrency: cancel-in-progress: true jobs: + changes: + runs-on: ubuntu-latest + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + with: + filters: | + src: + - '.github/workflows/**' + - 'src/**' + - 'appinfo/info.xml' + - 'package.json' + - 'package-lock.json' + - 'tsconfig.json' + - '.eslintrc.*' + - '.eslintignore' + - '**.js' + - '**.ts' + - '**.vue' + lint: runs-on: ubuntu-latest - name: eslint + name: NPM lint steps: - name: Checkout @@ -62,3 +71,18 @@ jobs: - name: Lint run: npm run lint + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: build + + if: always() + + # This is the summary, we just avoid to rename it so that branch protection rules still match + name: eslint + + steps: + - name: Summary status + run: if ${{ steps.changes.outputs.src == 'true' && needs.lint.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/node-when-unrelated.properties.json b/workflow-templates/node-when-unrelated.properties.json deleted file mode 100644 index 0a2c75d4..00000000 --- a/workflow-templates/node-when-unrelated.properties.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "Node checkout and build workflow when unrelated", - "description": "Marks node as passed when no JavaScript related files were changed", - "iconName": "node", - "categories": [ - "JavaScript" - ], - "filePatterns": [ - "^package.json$" - ] -} diff --git a/workflow-templates/node-when-unrelated.yml b/workflow-templates/node-when-unrelated.yml deleted file mode 100644 index f4195299..00000000 --- a/workflow-templates/node-when-unrelated.yml +++ /dev/null @@ -1,107 +0,0 @@ -# This workflow is provided via the organization template repository -# -# https://github.com/nextcloud/.github -# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization -# -# Use node together with node-when-unrelated to make eslint a required check for GitHub actions -# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks - -name: Node - -on: - pull_request: - paths-ignore: - - '.github/workflows/**' - - 'src/**' - - 'appinfo/info.xml' - - 'package.json' - - 'package-lock.json' - - 'tsconfig.json' - - '**.js' - - '**.ts' - - '**.vue' - push: - branches: - - main - - master - - stable* - -env: - PATHS_IGNORE: '.github/workflows/**;src/**;appinfo/info.xml;package.json;package-lock.json;tsconfig.json;**.js;**.ts;**.vue' - -concurrency: - group: node-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - action-no-build: - permissions: - contents: none - runs-on: ubuntu-latest - - name: action-not-src - outputs: - found_file: ${{ steps.confirm-negative-list.outputs.result }} - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} - - - name: Get changed files from diff - id: changed-files - run: | - if ${{ github.event_name == 'pull_request' }}; then - echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT - else - echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT - fi - - - name: Set up node 20 - uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3 - with: - node-version: 20 - - - name: Install minimatch - run: npm i minimatch - - - name: Check if a file is in paths-ignored - id: confirm-negative-list - uses: actions/github-script@v5 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - result-encoding: string - script: | - const { minimatch } = require('minimatch') - const changedPaths = "${{ steps.changed-files.outputs.changed_files }}".split(' ') - - let matched = '' - process.env.PATHS_IGNORE.split(';').every(pattern => { - changedPaths.every(path => { - console.info('Testing ' + path + ' for pattern ' + pattern) - if (minimatch(path, pattern)) { - console.info(path + ' matched, aborting "unrelated summary"') - matched = '1' - return false - } - return true - }) - return !matched - }) - return matched - - build: - permissions: - contents: none - - runs-on: ubuntu-latest - - needs: action-no-build - - name: node - - if: needs.action-no-build.outputs.found_file == '' - - steps: - - name: Skip - run: 'echo "No JS/TS files changed, skipped Node"' diff --git a/workflow-templates/node.yml b/workflow-templates/node.yml index 9d3f120d..059bdc1d 100644 --- a/workflow-templates/node.yml +++ b/workflow-templates/node.yml @@ -7,16 +7,6 @@ name: Node on: pull_request: - paths: - - '.github/workflows/**' - - 'src/**' - - 'appinfo/info.xml' - - 'package.json' - - 'package-lock.json' - - 'tsconfig.json' - - '**.js' - - '**.ts' - - '**.vue' push: branches: - main @@ -31,10 +21,31 @@ concurrency: cancel-in-progress: true jobs: + changes: + runs-on: ubuntu-latest + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + with: + filters: | + src: + - '.github/workflows/**' + - 'src/**' + - 'appinfo/info.xml' + - 'package.json' + - 'package-lock.json' + - 'tsconfig.json' + - '**.js' + - '**.ts' + - '**.vue' + build: runs-on: ubuntu-latest - name: node + if: steps.changes.outputs.src == 'true' + + name: NPM build steps: - name: Checkout uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 @@ -71,3 +82,18 @@ jobs: git status git --no-pager diff exit 1 # make it red to grab attention + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: build + + if: always() + + # This is the summary, we just avoid to rename it so that branch protection rules still match + name: node + + steps: + - name: Summary status + run: if ${{ steps.changes.outputs.src == 'true' && needs.build.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpunit-mysql.yml b/workflow-templates/phpunit-mysql.yml index 397e9d2e..66794b2d 100644 --- a/workflow-templates/phpunit-mysql.yml +++ b/workflow-templates/phpunit-mysql.yml @@ -7,18 +7,6 @@ name: PHPUnit mysql on: pull_request: - paths: - - '.github/workflows/**' - - 'appinfo/**' - - 'lib/**' - - 'templates/**' - - 'tests/**' - - 'vendor/**' - - 'vendor-bin/**' - - '.php-cs-fixer.dist.php' - - 'composer.json' - - 'composer.lock' - push: branches: - main @@ -33,12 +21,34 @@ concurrency: cancel-in-progress: true jobs: + changes: + runs-on: ubuntu-latest + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + phpunit-mysql: runs-on: ubuntu-latest + if: steps.changes.outputs.src == 'true' + strategy: matrix: - php-versions: ['8.0', '8.1', '8.2'] + php-versions: ['8.0', '8.1', '8.2', '8.3'] server-versions: ['master'] services: @@ -159,4 +169,4 @@ jobs: steps: - name: Summary status - run: if ${{ needs.phpunit-mysql.result != 'success' }}; then exit 1; fi + run: if ${{ steps.changes.outputs.src == 'true' && needs.phpunit-mysql.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpunit-oci.yml b/workflow-templates/phpunit-oci.yml index abe33cb6..5ad5b108 100644 --- a/workflow-templates/phpunit-oci.yml +++ b/workflow-templates/phpunit-oci.yml @@ -7,18 +7,6 @@ name: PHPUnit OCI on: pull_request: - paths: - - '.github/workflows/**' - - 'appinfo/**' - - 'lib/**' - - 'templates/**' - - 'tests/**' - - 'vendor/**' - - 'vendor-bin/**' - - '.php-cs-fixer.dist.php' - - 'composer.json' - - 'composer.lock' - push: branches: - main @@ -33,9 +21,31 @@ concurrency: cancel-in-progress: true jobs: - phpunit-oci: + changes: runs-on: ubuntu-latest + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + phpunit-oci: + runs-on: ubuntu-22.04 + + if: steps.changes.outputs.src == 'true' + strategy: matrix: php-versions: ['8.0'] @@ -166,4 +176,4 @@ jobs: steps: - name: Summary status - run: if ${{ needs.phpunit-oci.result != 'success' }}; then exit 1; fi + run: if ${{ steps.changes.outputs.src == 'true' && needs.phpunit-oci.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpunit-pgsql.yml b/workflow-templates/phpunit-pgsql.yml index 2d828135..55ed82cd 100644 --- a/workflow-templates/phpunit-pgsql.yml +++ b/workflow-templates/phpunit-pgsql.yml @@ -7,18 +7,6 @@ name: PHPUnit pgsql on: pull_request: - paths: - - '.github/workflows/**' - - 'appinfo/**' - - 'lib/**' - - 'templates/**' - - 'tests/**' - - 'vendor/**' - - 'vendor-bin/**' - - '.php-cs-fixer.dist.php' - - 'composer.json' - - 'composer.lock' - push: branches: - main @@ -33,9 +21,31 @@ concurrency: cancel-in-progress: true jobs: + changes: + runs-on: ubuntu-latest + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + phpunit-pgsql: runs-on: ubuntu-latest + if: steps.changes.outputs.src == 'true' + strategy: matrix: php-versions: ['8.0'] @@ -156,4 +166,4 @@ jobs: steps: - name: Summary status - run: if ${{ needs.phpunit-pgsql.result != 'success' }}; then exit 1; fi + run: if ${{ steps.changes.outputs.src == 'true' && needs.phpunit-pgsql.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpunit-sqlite.yml b/workflow-templates/phpunit-sqlite.yml index c0c0da9e..658c0124 100644 --- a/workflow-templates/phpunit-sqlite.yml +++ b/workflow-templates/phpunit-sqlite.yml @@ -7,18 +7,6 @@ name: PHPUnit sqlite on: pull_request: - paths: - - '.github/workflows/**' - - 'appinfo/**' - - 'lib/**' - - 'templates/**' - - 'tests/**' - - 'vendor/**' - - 'vendor-bin/**' - - '.php-cs-fixer.dist.php' - - 'composer.json' - - 'composer.lock' - push: branches: - main @@ -33,9 +21,31 @@ concurrency: cancel-in-progress: true jobs: + changes: + runs-on: ubuntu-latest + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + phpunit-sqlite: runs-on: ubuntu-latest + if: steps.changes.outputs.src == 'true' + strategy: matrix: php-versions: ['8.0'] @@ -145,4 +155,4 @@ jobs: steps: - name: Summary status - run: if ${{ needs.phpunit-sqlite.result != 'success' }}; then exit 1; fi + run: if ${{ steps.changes.outputs.src == 'true' && needs.phpunit-sqlite.result != 'success' }}; then exit 1; fi diff --git a/workflow-templates/phpunit-summary-when-unrelated.properties.json b/workflow-templates/phpunit-summary-when-unrelated.properties.json deleted file mode 100644 index 4566801e..00000000 --- a/workflow-templates/phpunit-summary-when-unrelated.properties.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "PHPUnit summary when unrelated", - "description": "Marks PHPUnit tests as passed when no PHP related files where changed", - "iconName": "phpunit", - "categories": [ - "PHP" - ], - "filePatterns": [ - "^tests/phpunit.xml$" - ] -} diff --git a/workflow-templates/phpunit-summary-when-unrelated.yml b/workflow-templates/phpunit-summary-when-unrelated.yml deleted file mode 100644 index 24c35d34..00000000 --- a/workflow-templates/phpunit-summary-when-unrelated.yml +++ /dev/null @@ -1,143 +0,0 @@ -# This workflow is provided via the organization template repository -# -# https://github.com/nextcloud/.github -# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization - -name: PHPUnit summary - -on: - pull_request: - paths-ignore: - - '.github/workflows/**' - - 'appinfo/**' - - 'lib/**' - - 'templates/**' - - 'tests/**' - - 'vendor/**' - - 'vendor-bin/**' - - '.php-cs-fixer.dist.php' - - 'composer.json' - - 'composer.lock' - -env: - PATHS_IGNORE: '.github/workflows/**;appinfo/**;lib/**;templates/**;tests/**;vendor/**;vendor-bin/**;.php-cs-fixer.dist.php;composer.json;composer.lock' - -permissions: - contents: read - -jobs: - action-no-summary: - permissions: - contents: none - runs-on: ubuntu-latest - - name: action-not-src - outputs: - found_file: ${{ steps.confirm-negative-list.outputs.result }} - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} - - - name: Get changed files from diff - id: changed-files - run: | - if ${{ github.event_name == 'pull_request' }}; then - echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT - else - echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT - fi - - - name: Set up node 20 - uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3 - with: - node-version: 20 - - - name: Install minimatch - run: npm i minimatch - - - name: Check if a file is in paths-ignored - id: confirm-negative-list - uses: actions/github-script@v5 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - result-encoding: string - script: | - const { minimatch } = require('minimatch') - const changedPaths = "${{ steps.changed-files.outputs.changed_files }}".split(' ') - - let matched = '' - process.env.PATHS_IGNORE.split(';').every(pattern => { - changedPaths.every(path => { - console.info('Testing ' + path + ' for pattern ' + pattern) - if (minimatch(path, pattern)) { - console.info(path + ' matched, aborting "unrelated summary"') - matched = '1' - return false - } - return true - }) - return !matched - }) - return matched - - summary-mysql: - permissions: - contents: none - runs-on: ubuntu-latest - - needs: action-no-summary - - name: phpunit-mysql-summary - - if: needs.action-no-summary.outputs.found_file == '' - - steps: - - name: Summary status - run: 'echo "No PHP files changed, skipped PHPUnit"' - - summary-oci: - permissions: - contents: none - runs-on: ubuntu-latest - - needs: action-no-summary - - name: phpunit-oci-summary - - if: needs.action-no-summary.outputs.found_file == '' - - steps: - - name: Summary status - run: 'echo "No PHP files changed, skipped PHPUnit"' - - summary-pgsql: - permissions: - contents: none - runs-on: ubuntu-latest - - needs: action-no-summary - - name: phpunit-pgsql-summary - - if: needs.action-no-summary.outputs.found_file == '' - - steps: - - name: Summary status - run: 'echo "No PHP files changed, skipped PHPUnit"' - - summary-sqlite: - permissions: - contents: none - runs-on: ubuntu-latest - - needs: action-no-summary - - name: phpunit-sqlite-summary - - if: needs.action-no-summary.outputs.found_file == '' - - steps: - - name: Summary status - run: 'echo "No PHP files changed, skipped PHPUnit"'