Skip to content

Commit 2c56a05

Browse files
committed
Skip build and test on OSes that have no changes
Many of the PRs on SWT are OS specific, this change only runs the build on OSes if there are changes that can affect that OS. This is going to be more important with #2714 because potentially a number of new jobs will be run per PR and avoiding some of the extra time waiting will be a benefit to all. The junit.yml has been updated to record tests per platform in addition to all tests. When not all platforms are run in a PR, only the respective platform results are reported as a comment. If all platforms are run, the cumulative results are reported as a comment. Part of #2714
1 parent 13d7370 commit 2c56a05

File tree

2 files changed

+144
-11
lines changed

2 files changed

+144
-11
lines changed

.github/workflows/junit.yml

Lines changed: 93 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# This is the workflow for SWT that collects and reports junit results
2+
3+
# This script runs from the master branch all the time. This means if you update it in a
4+
# Pull Request, the update won't take effect until after you merge the PR, the PR itself
5+
# will *not* use the edits.
6+
# Therefore to really test a change to this script, push it to your fork's master branch
7+
# and then create a PR against your own master branch.
8+
9+
# You can run this locally to test changes with the act command https://nektosact.com/
10+
# Steps:
11+
# 1. Get a PAT (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
12+
# Use fine grained one, needs Read access to artifact metadata, and metadata
13+
# 2. Get the URL of some artifacts to test against from a previous run of the build
14+
# script (such as your last run on your fork's master branch). It looks like:
15+
# https://api.github.com/repos/jonahgraham/eclipse.platform.swt/actions/runs/19980765555/artifacts
16+
# 3. Run the act command:
17+
# act -W '.github/workflows/junit.yml' -s GITHUB_TOKEN=your_token --input artifacts_url=your_url
18+
119
name: Publish Unit Test Results
220

321
on:
@@ -10,37 +28,101 @@ permissions:
1028
contents: read
1129

1230
jobs:
13-
unit-test-results:
14-
name: Unit Test Results
31+
discover-results:
1532
runs-on: ubuntu-latest
1633
if: github.event.workflow_run.conclusion != 'skipped'
34+
outputs:
35+
matrix: ${{ steps.build-matrix.outputs.matrix }}
36+
isall: ${{ steps.build-matrix.outputs.all }}
37+
steps:
38+
- name: Find test-results from artifacts_url and build dynamic matrix
39+
id: build-matrix
40+
env:
41+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
42+
run: |
43+
set -x
44+
# Get the URL from the event, or the act command line
45+
artifacts_url=${{ github.event.workflow_run.artifacts_url || github.event.inputs.artifacts_url }}
46+
results=$(gh api "$artifacts_url" -q '.artifacts[] | [.name] | @tsv' | grep 'test-results-')
47+
48+
platforms=""
49+
if [[ "$results" == *macos* ]]; then
50+
platforms="macos"
51+
fi
52+
if [[ "$results" == *linux* ]]; then
53+
if [[ -n "$platforms" ]]; then
54+
platforms+=" "
55+
fi
56+
platforms+="linux"
57+
fi
58+
if [[ "$results" == *win32* ]]; then
59+
if [[ -n "$platforms" ]]; then
60+
platforms+=" "
61+
fi
62+
platforms+="win32"
63+
fi
64+
65+
if [[ "$platforms" == "macos linux win32" ]]; then
66+
platforms+=" all"
67+
echo "isall=1" >> "$GITHUB_OUTPUT"
68+
else
69+
echo "isall=0" >> "$GITHUB_OUTPUT"
70+
fi
71+
72+
json=$(jq -R --arg key "platform" 'split(" ") | {($key): .}' <<< "$platforms")
73+
74+
echo "Matrix JSON (pretty): ${json}"
75+
{
76+
echo 'matrix<<EOF'
77+
printf '%s\n' "$json"
78+
echo 'EOF'
79+
} >> "$GITHUB_OUTPUT"
80+
81+
results:
82+
needs: discover-results
83+
runs-on: ubuntu-latest
1784
permissions:
1885
checks: write
1986
pull-requests: write
2087
contents: read
2188
issues: read
2289
actions: read
90+
strategy:
91+
# Use the dynamic matrix from the previous job
92+
matrix: ${{ fromJson(needs.discover-results.outputs.matrix) }}
93+
fail-fast: false
2394

2495
steps:
25-
- name: Download and Extract Artifacts
96+
- name: Downloading rest results for ${{ matrix.platform }}
2697
env:
2798
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2899
run: |
29-
mkdir -p artifacts && cd artifacts
100+
set -x
101+
mkdir -p artifacts && cd artifacts
30102
31-
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
103+
# Get the URL from the event, or the act command line
104+
artifacts_url=${{ github.event.workflow_run.artifacts_url || github.event.inputs.artifacts_url }}
32105
33-
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
34-
do
35-
IFS=$'\t' read name url <<< "$artifact"
36-
gh api $url > "$name.zip"
37-
unzip -d "$name" "$name.zip"
38-
done
106+
if [[ "${{ matrix.platform }}" == "all" ]]; then
107+
# allow everything through
108+
grep="."
109+
else
110+
# only download event file and tests for this platform
111+
grep="Event File|${{ matrix.platform }}"
112+
fi
113+
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | grep -E "$grep" | while read artifact
114+
do
115+
IFS=$'\t' read name url <<< "$artifact"
116+
gh api $url > "$name.zip"
117+
unzip -d "$name" "$name.zip"
118+
done
39119
40120
- name: Publish Unit Test Results
41121
uses: EnricoMi/publish-unit-test-result-action@34d7c956a59aed1bfebf31df77b8de55db9bbaaf # v2.21.0
42122
id: test-results
43123
with:
124+
check_name: ${{ matrix.platform == 'all' && 'Test Results' || format('Test Results ({0})', matrix.platform) }}
125+
comment_mode: ${{ (matrix.platform == 'all') == (needs.discover-results.outputs.isall == '1') && 'always' || 'off' }}
44126
commit: ${{ github.event.workflow_run.head_sha }}
45127
event_file: artifacts/Event File/event.json
46128
event_name: ${{ github.event.workflow_run.event }}

.github/workflows/maven.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,53 @@ jobs:
3131
name: Event File
3232
path: ${{ github.event_path }}
3333

34+
changes:
35+
name: Detect changed paths
36+
runs-on: ubuntu-latest
37+
outputs:
38+
# Lint warnings are expected in this block
39+
# https://github.com/dorny/paths-filter/issues/223#issuecomment-2463309889
40+
win32: ${{ steps.filter.outputs.win32 || 'false' }}
41+
gtk: ${{ steps.filter.outputs.gtk || 'false' }}
42+
cocoa: ${{ steps.filter.outputs.cocoa || 'false' }}
43+
md: ${{ steps.filter.outputs.md || 'false' }}
44+
other: ${{ steps.filter.outputs.other || 'false' }}
45+
steps:
46+
- name: Paths filter (PRs only)
47+
if: github.event.pull_request.base
48+
# dorney/paths-filter is out of date, so use this fork with
49+
# a specific fix for missing predicate-quantifier in action's
50+
# inputs
51+
# https://github.com/dorny/paths-filter/pull/226#issuecomment-2805358761
52+
uses: petermetz/paths-filter@5ee2f5d4cf5d7bdd998a314a42da307e2ae1639d
53+
id: filter
54+
with:
55+
predicate-quantifier: 'every'
56+
filters: |
57+
win32:
58+
- '**/win32/**'
59+
gtk:
60+
- '**/gtk/**'
61+
cocoa:
62+
- '**/cocoa/**'
63+
md:
64+
- '**/*.md'
65+
jenkins:
66+
- 'Jenkinsfile'
67+
# "other" = anything not matching the above buckets
68+
other:
69+
- '**'
70+
- '!**/win32/**'
71+
- '!**/gtk/**'
72+
- '!**/cocoa/**'
73+
- '!**/*.md'
74+
- '!Jenkinsfile'
75+
3476
build-linux:
3577
name: Build (Linux)
78+
needs: changes
79+
# push => always; PR => run if gtk changed OR "other" changed (run-everything case)
80+
if: ${{ github.event_name != 'pull_request' || needs.changes.outputs.gtk == 'true' || needs.changes.outputs.other == 'true' }}
3681
strategy:
3782
fail-fast: false
3883
matrix:
@@ -49,6 +94,9 @@ jobs:
4994

5095
build-windows:
5196
name: Build (Windows)
97+
needs: changes
98+
# push => always; PR => run if win32 changed OR "other" changed (run-everything case)
99+
if: ${{ github.event_name != 'pull_request' || needs.changes.outputs.win32 == 'true' || needs.changes.outputs.other == 'true' }}
52100
strategy:
53101
fail-fast: false
54102
matrix:
@@ -63,6 +111,9 @@ jobs:
63111

64112
build-macos:
65113
name: Build (macOS)
114+
needs: changes
115+
# push => always; PR => run if cocoa changed OR "other" changed (run-everything case)
116+
if: ${{ github.event_name != 'pull_request' || needs.changes.outputs.cocoa == 'true' || needs.changes.outputs.other == 'true' }}
66117
strategy:
67118
fail-fast: false
68119
matrix:

0 commit comments

Comments
 (0)