Skip to content

Commit 3aa3cc7

Browse files
authored
Merge pull request #11 from Hasenpfote/improve-gha-workflows
Improve GitHub Actions workflows
2 parents 79eb4cb + dcd228b commit 3aa3cc7

File tree

7 files changed

+190
-166
lines changed

7 files changed

+190
-166
lines changed

.github/settings/filters.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/settings/lint_filters.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This is used by the action below.
2+
# https://github.com/dorny/paths-filter
3+
4+
shared: &shared
5+
- '.github/actions/read-yaml/action.yml'
6+
- '.github/settings/lint_filters.yml'
7+
- '.github/workflows/lint.yml'
8+
9+
# python scripts
10+
py-shared: &py-shared
11+
- '.github/actions/setup-poetry/action.yml'
12+
- '.github/actions/setup-poetry-dependencies/action.yml'
13+
- '.github/settings/env.yml'
14+
- '.github/workflows/py_lint.yml'
15+
- 'poetry.lock'
16+
- 'pyproject.toml'
17+
18+
py-lint: &py-lint
19+
- 'tox.ini'
20+
- added|modified: '**/*.py'
21+
22+
py:
23+
- *shared
24+
- *py-shared
25+
- *py-lint
26+
27+
# markdown files
28+
md-lint: &md-lint
29+
- '.markdownlint.yml'
30+
- added|modified: '**/*.md'
31+
32+
md:
33+
- *shared
34+
- *md-lint

.github/settings/test_filters.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This is used by the action below.
2+
# https://github.com/dorny/paths-filter
3+
4+
shared: &shared
5+
- '.github/actions/read-yaml/action.yml'
6+
- '.github/settings/test_filters.yml'
7+
- '.github/workflows/test.yml'
8+
9+
# python scripts
10+
py-shared: &py-shared
11+
- '.github/actions/setup-poetry/action.yml'
12+
- '.github/actions/setup-poetry-dependencies/action.yml'
13+
- '.github/settings/test_matrix.yml'
14+
- '.github/workflows/codecov_upload.yml'
15+
- '.github/workflows/py_test.yml'
16+
- 'poetry.lock'
17+
- 'pyproject.toml'
18+
19+
py-test: &py-test
20+
- 'tox.ini'
21+
- added|modified: '**/*.py'
22+
23+
py:
24+
- *shared
25+
- *py-shared
26+
- *py-test

.github/workflows/codecov_upload.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: Upload coverage reports to Codecov
22

33
on:
4-
workflow_dispatch:
54
workflow_call:
5+
inputs:
6+
artifact-name:
7+
description: 'Artifact name'
8+
default: 'coverage-reports'
9+
required: false
10+
type: string
611

712
jobs:
813
env_prep:
@@ -56,7 +61,7 @@ jobs:
5661
- name: Download coverage reports
5762
uses: actions/download-artifact@v3
5863
with:
59-
name: coverage-reports
64+
name: ${{ inputs.artifact-name }}
6065

6166
- name: Combine coverage reports
6267
run: |

.github/workflows/lint.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,11 @@ jobs:
2121
- name: Checkout
2222
uses: actions/checkout@v3
2323

24-
- name: Read YAML file
25-
id: read-file
26-
uses: ./.github/actions/read-yaml
27-
with:
28-
path: .github/settings/filters.yml
29-
filter: '.lint'
30-
3124
- name: Categorize changed files
3225
uses: dorny/paths-filter@v2
3326
id: filter
3427
with:
35-
filters: ${{ steps.read-file.outputs.content }}
28+
filters: .github/settings/lint_filters.yml
3629

3730
py-lint:
3831
needs: determine-changes

.github/workflows/py_test.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
enable-test:
5+
description: 'Enable test'
6+
default: true
7+
required: false
8+
type: boolean
9+
10+
artifact-name:
11+
description: 'Artifact name'
12+
default: 'coverage-reports'
13+
required: false
14+
type: string
15+
16+
outputs:
17+
has-coverage-reports:
18+
description: 'This test has coverage reports or not'
19+
value: ${{ jobs.check.outputs.has-coverage-reports }}
20+
21+
jobs:
22+
matrix_prep:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
matrix: ${{ steps.read-file.outputs.content }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
30+
- name: Read YAML file
31+
id: read-file
32+
uses: ./.github/actions/read-yaml
33+
with:
34+
path: .github/settings/test_matrix.yml
35+
filter: '.matrix'
36+
37+
build:
38+
needs: matrix_prep
39+
strategy:
40+
fail-fast: false
41+
matrix: ${{ fromJson(needs.matrix_prep.outputs.matrix) }}
42+
43+
runs-on: ${{ matrix.os }}
44+
name: ${{ format('build ({0}, {1})', matrix.os, matrix.python-version) }}
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v3
48+
49+
- name: Set up Python ${{ matrix.python-version }}
50+
id: setup-python
51+
uses: actions/setup-python@v4
52+
with:
53+
python-version: ${{ matrix.python-version }}
54+
55+
- name: Set up Poetry ${{ matrix.poetry-version }}
56+
id: setup-poetry
57+
uses: ./.github/actions/setup-poetry
58+
with:
59+
cache-path: ${{ matrix.poetry-cache-paths }}
60+
cache-key: ${{ format(matrix.poetry-cache-key-fmt, matrix.poetry-version, matrix.os, steps.setup-python.outputs.python-version) }}
61+
poetry-version: ${{ matrix.poetry-version }}
62+
poetry-home: ${{ matrix.poetry-home }}
63+
poetry-path: ${{ matrix.poetry-path }}
64+
65+
- name: Set up Poetry dependencies
66+
id: setup-poetry-dependencies
67+
uses: ./.github/actions/setup-poetry-dependencies
68+
with:
69+
cache-key: ${{ format(matrix.venv-cache-key-fmt, matrix.os, steps.setup-python.outputs.python-version, hashFiles('**/poetry.lock')) }}
70+
python-version: ${{ steps.setup-python.outputs.python-version }}
71+
poetry-install-args: --no-interaction --no-root --with dev
72+
73+
- name: Test with pytest
74+
id: test-with-pytest
75+
if: inputs.enable-test == true
76+
run: |
77+
${{ steps.setup-poetry-dependencies.outputs.venv-activate }}
78+
tox -e py -- -v --color=yes
79+
deactivate
80+
# Create a dummy file.
81+
touch "dummy-$(echo .coverage.*)"
82+
83+
- name: Upload coverage reports
84+
if: steps.test-with-pytest.conclusion != 'skipped' && matrix.enable-coverage == 'true'
85+
uses: actions/upload-artifact@v3
86+
with:
87+
name: ${{ inputs.artifact-name }}
88+
path: .coverage.*
89+
retention-days: 1
90+
91+
- name: Upload dummy files
92+
if: steps.test-with-pytest.conclusion != 'skipped' && matrix.enable-coverage == 'true'
93+
uses: actions/upload-artifact@v3
94+
with:
95+
name: dummy-files
96+
path: dummy-*
97+
retention-days: 1
98+
99+
check:
100+
needs: build
101+
runs-on: ubuntu-latest
102+
outputs:
103+
has-coverage-reports: ${{ steps.download.outputs.download-path != '' }}
104+
steps:
105+
- name: Download dummy files
106+
id: download
107+
continue-on-error: true
108+
uses: actions/download-artifact@v3
109+
with:
110+
name: dummy-files

0 commit comments

Comments
 (0)