Skip to content

Commit

Permalink
fix(CI): Make sure the "when unrelated" fake summaries work correctly
Browse files Browse the repository at this point in the history
Before they executed when any file outside the defined scope matched.
However that means: When a PR touches PHP and JS, both the real and
the fake summaries for node, eslint and phpunit got triggered.
Since the fake summary is always green it meant one could merge a PR
that in the end had red CI on the non-fake summary.

Now the fake summaries are skipped, if any of the files still matches
the pattern, instead of being executed whenever a single file did not
match it.

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Sep 28, 2023
1 parent b369b24 commit b41c534
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
63 changes: 63 additions & 0 deletions workflow-templates/lint-eslint-when-unrelated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,80 @@ on:
- '**.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"'
64 changes: 64 additions & 0 deletions workflow-templates/node-when-unrelated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,82 @@ on:
- 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"'
75 changes: 75 additions & 0 deletions workflow-templates/phpunit-summary-when-unrelated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,80 @@ on:
- '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"'
Expand All @@ -39,8 +102,12 @@ jobs:
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"'
Expand All @@ -50,8 +117,12 @@ jobs:
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"'
Expand All @@ -61,8 +132,12 @@ jobs:
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"'

0 comments on commit b41c534

Please sign in to comment.