Skip to content

Commit 10179d2

Browse files
authored
Skip dry runs in PRs based on diff (#10)
Skip workflow dry run jobs in PRs based on whether diff contains files relevant to that workflow.
1 parent 891d796 commit 10179d2

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

.github/workflows/check-new-api-spec.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ on:
1010
type: boolean
1111
required: false
1212
workflow_call:
13+
inputs:
14+
dry_run:
15+
description: 'Dry run'
16+
type: boolean
17+
required: true
1318

1419
defaults:
1520
run:
1621
shell: bash
1722

18-
env:
19-
DRY_RUN: ${{ github.event.inputs.dry_run || github.event_name == 'pull_request' }}
20-
2123
jobs:
2224

2325
check-new-api-spec:
@@ -33,7 +35,7 @@ jobs:
3335
[[ -n "$version" ]]
3436
echo "SPEC_VERSION=$version" | tee -a "$GITHUB_ENV"
3537
- name: 'Create PR'
36-
if: ${{ env.DRY_RUN == 'false' }}
38+
if: ${{ !inputs.dry_run }}
3739
uses: peter-evans/create-pull-request@v4
3840
with:
3941
branch: "feature/api-spec-${{ env.SPEC_VERSION }}"

.github/workflows/pr.yml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,43 @@ jobs:
4545
if: ${{ steps.diff.outputs.all_modified_files }}
4646
run: python3 -m unittest discover -bs .github/scripts
4747

48-
publish-javadoc-dry-run:
48+
choose-dry-runs:
49+
runs-on: ubuntu-latest
50+
outputs:
51+
dry-run-publish-javadoc: ${{ steps.diff-publish-javadoc.outputs.all_modified_files }}
52+
dry-run-check-new-api-spec: ${{ steps.diff-check-new-api-spec.outputs.all_modified_files }}
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v3
56+
- name: Diff publish-javadoc.yml
57+
id: diff-publish-javadoc
58+
uses: tj-actions/changed-files@v24
59+
with:
60+
files: |
61+
.github/workflows/publish-javadoc.yml
62+
.github/scripts/*
63+
**/src/**
64+
**/*.gradle*
65+
./gradle/*
66+
- name: Diff check-new-api-spec.yml
67+
id: diff-check-new-api-spec
68+
uses: tj-actions/changed-files@v24
69+
with:
70+
files: |
71+
.github/workflows/check-new-api-spec.yml
72+
.github/scripts/*
73+
gradle.properties
74+
75+
dry-run-publish-javadoc:
76+
needs: [choose-dry-runs]
77+
if: ${{ needs.choose-dry-runs.outputs.dry-run-publish-javadoc }}
4978
uses: ./.github/workflows/publish-javadoc.yml
79+
with:
80+
dry_run: true
5081

51-
check-new-api-spec-dry-run:
82+
dry-run-check-new-api-spec:
83+
needs: [choose-dry-runs]
84+
if: ${{ needs.choose-dry-runs.outputs.dry-run-check-new-api-spec }}
5285
uses: ./.github/workflows/check-new-api-spec.yml
86+
with:
87+
dry_run: true

.github/workflows/publish-javadoc.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ on:
1010
type: boolean
1111
required: false
1212
workflow_call:
13+
inputs:
14+
dry_run:
15+
description: 'Dry run'
16+
type: boolean
17+
required: true
1318

1419
defaults:
1520
run:
1621
shell: bash
1722

1823
env:
19-
DRY_RUN: ${{ github.event.inputs.dry_run || github.event_name == 'pull_request' }}
2024
JAR_NAME: gradle-enterprise-api-kotlin-SNAPSHOT-javadoc.jar
2125

2226
jobs:
@@ -39,21 +43,24 @@ jobs:
3943
steps:
4044
- name: Checkout
4145
uses: actions/checkout@v3
42-
- name: Fetch branch
43-
run: git fetch origin gh-pages && git checkout FETCH_HEAD
46+
with:
47+
ref: gh-pages
4448
- name: Download javadoc
4549
uses: actions/download-artifact@v3
4650
- name: Unzip javadoc
47-
run: rm -rf docs && unzip "javadoc/$JAR_NAME" -d docs
51+
run: |
52+
rm -rf docs
53+
unzip "javadoc/$JAR_NAME" -d docs
54+
rm -rf javadoc
4855
- name: Commit
4956
run: |
5057
git config user.name github-actions
5158
git config user.email github-actions@github.com
5259
git add docs
53-
git commit -m "Add ${{ github.ref_name }} javadoc"
60+
git commit --allow-empty -m "Add ${{ github.ref_name }} javadoc"
5461
- name: Push
5562
run: |
56-
if [[ "$DRY_RUN" == 'true' ]]; then
63+
if [[ "${{ inputs.dry_run }}" == 'true' ]]; then
5764
args=' --dry-run'
5865
fi
59-
git push origin HEAD:gh-pages $args
66+
git push $args

0 commit comments

Comments
 (0)