-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[CI/CD;DevEx]: Scope sample and source-change workflows to skip unnecessary jobs #23964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Picazsoo
wants to merge
15
commits into
OpenAPITools:master
Choose a base branch
from
Picazsoo:feature/prevent-sample-compilation-on-no-changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
76aa593
feat: update workflow triggers and setup for various sample projects …
Picazsoo eab54b1
fix: remove ${{ }} template expressions from action.yaml output descr…
Picazsoo 8117135
skip unit tests and doc check for sample-only changes in openapi-gene…
Picazsoo 3f84a08
skip unit tests for bin/ changes
Picazsoo 67ae687
implement fixes
Picazsoo 3a5fa1b
fix: run all samples when base SHA is unreachable after force-push
Picazsoo 94a37e7
ci: tighten paths: trigger in echo-api java workflows to per-sample g…
Picazsoo 7e2dc7c
fix: use merge-base diff for pull_request events to avoid stale base …
Picazsoo d86b3c1
fix: remove literal quotes from ruby all_samples and restore nestjs n…
Picazsoo 39bfcef
ci: skip linux/windows tests for non-source changes
Picazsoo 646cd3f
ci: add smart change detection to CircleCI nodes to skip unnecessary …
Picazsoo fcbc9a4
ci: enhance test execution strategy for feature branches to skip unne…
Picazsoo b926c28
fix: correct 11 workflow conversion bugs in compute-matrix refactor
Picazsoo 8ff22d1
fix: restore node-version matrix dimension in 3 TypeScript workflows
Picazsoo b8d8fb0
fix: hardcode java-version '17' in samples-java-helidon-v3.yaml
Picazsoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| name: 'Compute changed samples matrix' | ||
| description: > | ||
| Determines which sample directories from a given list have changed files | ||
| in the current push or pull_request event, and outputs a filtered JSON matrix. | ||
| Requires the calling job to have checked out the repository with fetch-depth: 0. | ||
|
|
||
| inputs: | ||
| all_samples: | ||
| description: > | ||
| Newline-separated list of sample directory paths to consider (the full matrix). | ||
| Paths should NOT include a trailing /** glob — the action matches by directory prefix. | ||
| Comment lines (starting with #) and blank lines are ignored. | ||
| required: true | ||
|
|
||
| outputs: | ||
| matrix: | ||
| description: > | ||
| Use this for single-dimension sample matrices. | ||
| JSON object {"sample":["path/a","path/b"]} - assign directly to the matrix: key using fromJson(). | ||
| Returns the string "[]" when no samples changed (use in an if: guard to skip the job). | ||
| value: ${{ steps.filter.outputs.matrix }} | ||
| samples: | ||
| description: > | ||
| Use this for multi-dimensional matrices (e.g. os + sample, php-version + sample). | ||
| Plain JSON array ["path/a","path/b"] - assign to the sample: dimension only using fromJson(). | ||
| Returns the string "[]" when no samples changed (use in an if: guard to skip the job). | ||
| value: ${{ steps.filter.outputs.samples }} | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - id: filter | ||
| shell: bash | ||
| env: | ||
| # For pull_request events, base.sha is the target branch tip (may be stale if base advanced). | ||
| # For push events, event.before is the previous HEAD (all-zeros for new branches). | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }} | ||
| HEAD_SHA: ${{ github.sha }} | ||
| # PR head SHA (only set for pull_request events). Used to isolate just the PR's changes | ||
| # via merge-base, avoiding false positives from unrelated base-branch advances. | ||
| PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
| ALL_SAMPLES: ${{ inputs.all_samples }} | ||
| run: | | ||
| RUN_ALL=false | ||
|
|
||
| # Resolve the base SHA — github.event.before is all zeros for brand-new branches | ||
| if [[ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]] || [[ -z "$BASE_SHA" ]]; then | ||
| BASE_SHA=$(git rev-parse HEAD~1 2>/dev/null || echo "") | ||
| elif ! git cat-file -e "$BASE_SHA^{commit}" 2>/dev/null; then | ||
| # BASE_SHA is set but unreachable locally — happens after a force-push that rewrites | ||
| # history. git diff would fail and fall back to HEAD~1, which only sees the latest | ||
| # commit and can miss changes in earlier commits. Run all samples to be safe. | ||
| RUN_ALL=true | ||
| fi | ||
|
|
||
| # Get list of changed files relative to the base commit | ||
| if [[ "$RUN_ALL" == "false" ]]; then | ||
| if [[ -n "$PR_HEAD_SHA" ]]; then | ||
| # pull_request event: use merge-base to isolate only the PR's own changes. | ||
| # Diffing base.sha..merge_commit would include unrelated changes from the base | ||
| # branch that landed after the PR was last synchronised. Using merge-base gives | ||
| # only the commits that are in the PR branch but not in the base branch. | ||
| MERGE_BASE=$(git merge-base "$PR_HEAD_SHA" "$BASE_SHA" 2>/dev/null || echo "") | ||
| if [[ -n "$MERGE_BASE" ]]; then | ||
| CHANGED=$(git diff --name-only "$MERGE_BASE" "$PR_HEAD_SHA") | ||
| else | ||
| CHANGED=$(git diff --name-only "$BASE_SHA" "$PR_HEAD_SHA" 2>/dev/null || git diff --name-only HEAD~1 HEAD) | ||
| fi | ||
| elif [[ -n "$BASE_SHA" ]]; then | ||
| # push event: diff from the previous HEAD | ||
| CHANGED=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" 2>/dev/null || git diff --name-only HEAD~1 HEAD) | ||
| else | ||
| CHANGED=$(git diff --name-only HEAD~1 HEAD) | ||
| fi | ||
| fi | ||
|
|
||
| # Filter: keep only sample dirs where at least one changed file lives inside them | ||
| RESULT=() | ||
| while IFS= read -r sample; do | ||
| # Strip leading/trailing whitespace | ||
| sample="${sample#"${sample%%[![:space:]]*}"}" | ||
| sample="${sample%"${sample##*[![:space:]]}"}" | ||
| # Skip blank lines and comment lines | ||
| if [[ -z "$sample" ]] || [[ "$sample" == \#* ]]; then continue; fi | ||
| # Normalise: strip any accidental trailing slash (paths: uses /**, all_samples: should not) | ||
| sample="${sample%/}" | ||
|
|
||
| # A file belongs to a sample dir if its path starts with "<sample>/" | ||
| if [[ "$RUN_ALL" == "true" ]] || echo "$CHANGED" | grep -q "^${sample}/"; then | ||
| RESULT+=("$sample") | ||
| fi | ||
| done <<< "$ALL_SAMPLES" | ||
|
|
||
| # Emit both output formats | ||
| if [[ ${#RESULT[@]} -eq 0 ]]; then | ||
| echo 'matrix=[]' >> "$GITHUB_OUTPUT" | ||
| echo 'samples=[]' >> "$GITHUB_OUTPUT" | ||
| else | ||
| SAMPLES_ARRAY=$(printf '%s\n' "${RESULT[@]}" | jq -R . | jq -sc .) | ||
| echo "matrix={\"sample\":${SAMPLES_ARRAY}}" >> "$GITHUB_OUTPUT" | ||
| echo "samples=${SAMPLES_ARRAY}" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.