Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit a3d8a52

Browse files
committed
ci: only run tests if files changed or previous run failed
1 parent 3eb6854 commit a3d8a52

File tree

5 files changed

+69
-22
lines changed

5 files changed

+69
-22
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Get last run status for workflow
2+
description: Get last run status for workflow
3+
inputs:
4+
workflow:
5+
description: Workflow id to check status of
6+
required: false
7+
default: main.yml
8+
files:
9+
description: Check if the files changed
10+
required: true
11+
outputs:
12+
proceed:
13+
description: Should proceed running steps
14+
value: ${{ steps.changed_files.outputs.any_changed == 'true' || steps.last_status.outputs.result != 'true' }}
15+
runs:
16+
using: composite
17+
steps:
18+
- name: Check change in files
19+
id: changed_files
20+
uses: tj-actions/[email protected]
21+
with:
22+
files: ${{ inputs.files }}
23+
24+
- name: Get last run
25+
if: steps.changed_files.outputs.any_changed != 'true'
26+
id: last_status
27+
uses: actions/[email protected]
28+
with:
29+
result-encoding: json
30+
script: |
31+
const { GITHUB_REF_NAME, WORKFLOW } = process.env;
32+
core.startGroup(`Checking last status for workflow \`${WORKFLOW}\` for branch \`${GITHUB_REF_NAME}\``);
33+
const result = await github.rest.actions.listWorkflowRuns({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
workflow_id: WORKFLOW,
37+
branch: GITHUB_REF_NAME,
38+
per_page: 2,
39+
page: 1
40+
});
41+
core.info(JSON.stringify(result));
42+
core.endGroup();
43+
const success = (result.data.workflow_runs[0]?.status === 'completed') ||
44+
(result.data.workflow_runs[1]?.status === 'completed');
45+
return success;
46+
env:
47+
WORKFLOW: ${{ inputs.workflow }}

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@ jobs:
2626
default_bump: false
2727
dry_run: true
2828

29-
- name: Check change in documentation
30-
id: changed_doc
29+
- name: Check should proceed running steps
3130
if: steps.check_version_bump.outputs.release_type == ''
32-
uses: tj-actions/[email protected]
31+
id: precondition
32+
uses: ./.github/actions/condition
3333
with:
3434
files: |
3535
Sources/**/*
3636
Package*.swift
3737
.github/workflows/ci.yml
3838
3939
- name: Setup repository
40-
if: steps.changed_doc.outputs.any_changed == 'true'
40+
if: steps.precondition.outputs.proceed == 'true'
4141
uses: ./.github/actions/setup
4242

4343
- name: Build package documentation
44-
if: steps.changed_doc.outputs.any_changed == 'true'
44+
if: steps.precondition.outputs.proceed == 'true'
4545
run: |
4646
npm run build
4747
npm run serve-doc
4848
4949
- name: Update GitHub Pages
50-
if: steps.changed_doc.outputs.any_changed == 'true'
50+
if: steps.precondition.outputs.proceed == 'true'
5151
uses: JamesIves/[email protected]
5252
with:
5353
branch: gh-pages

.github/workflows/cocoapods.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
- name: Checkout repository
1414
uses: actions/checkout@v3
1515

16-
- name: Check change in source files
17-
id: changed_source
18-
uses: tj-actions/[email protected]
16+
- name: Check should proceed running steps
17+
id: precondition
18+
uses: ./.github/actions/condition
1919
with:
2020
files: |
2121
Sources/**/*.swift
@@ -25,9 +25,9 @@ jobs:
2525
.github/workflows/cocoapods.yml
2626
2727
- name: Setup repository
28-
if: steps.changed_source.outputs.any_changed == 'true'
28+
if: steps.precondition.outputs.proceed == 'true'
2929
uses: ./.github/actions/setup
3030

3131
- name: Run tests
32-
if: steps.changed_source.outputs.any_changed == 'true'
32+
if: steps.precondition.outputs.proceed == 'true'
3333
run: npm run pod-lint

.github/workflows/swift-package.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v3
2121

22-
- name: Check change in source files
23-
id: changed_source
24-
uses: tj-actions/[email protected]
22+
- name: Check should proceed running steps
23+
id: precondition
24+
uses: ./.github/actions/condition
2525
with:
2626
files: |
2727
Sources/**/*.swift
@@ -31,18 +31,18 @@ jobs:
3131
.github/workflows/swift-package.yml
3232
3333
- name: Setup repository
34-
if: steps.changed_source.outputs.any_changed == 'true'
34+
if: steps.precondition.outputs.proceed == 'true'
3535
uses: ./.github/actions/setup
3636
with:
3737
swift: ${{ matrix.swift }}
3838

3939
- name: Run tests
40-
if: steps.changed_source.outputs.any_changed == 'true'
40+
if: steps.precondition.outputs.proceed == 'true'
4141
run: npm run test
4242

4343
- name: Swift Coverage Report
4444
if: |
45-
steps.changed_source.outputs.any_changed == 'true' &&
45+
steps.precondition.outputs.proceed == 'true' &&
4646
matrix.swift == '5.6' &&
4747
github.event_name == 'push'
4848
uses: maxep/[email protected]
@@ -52,7 +52,7 @@ jobs:
5252

5353
- name: Codecov upload
5454
if: |
55-
steps.changed_source.outputs.any_changed == 'true' &&
55+
steps.precondition.outputs.proceed == 'true' &&
5656
matrix.swift == '5.6' &&
5757
github.event_name == 'push'
5858
uses: codecov/[email protected]

.github/workflows/xcode.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v3
1818

19-
- name: Check change in source files
20-
id: changed_source
21-
uses: tj-actions/[email protected]
19+
- name: Check should proceed running steps
20+
id: precondition
21+
uses: ./.github/actions/condition
2222
with:
2323
files: |
2424
Sources/**/*.swift
@@ -27,7 +27,7 @@ jobs:
2727
.github/workflows/xcode.yml
2828
2929
- name: Build with Xcode
30-
if: steps.changed_source.outputs.any_changed == 'true'
30+
if: steps.precondition.outputs.proceed == 'true'
3131
uses: mxcl/xcodebuild@v1
3232
with:
3333
xcode: '11.3.1'

0 commit comments

Comments
 (0)