Skip to content

Commit fe7891e

Browse files
authored
Improve GitHub Actions workflows (#61)
* Set bash as default shell in test workflow * Cache pip folder in linting job * Enable cache on Windows * Create local poetry venv instead of in default location * Set cache keys with OS name and Python version * Add comment for cron schedule on quality workflow * Skip dependency installation on cache hit * Move if statement below step name * Limit documentation deployment to successful builds * Add Python version to step name * Rename variables in test workflow matrix * Override Python setup in code scanning job * Ensure CodeQL analysis uses correct Python location * Revert changes to Python setup in CodeQL job * Add name keyword to docs job Uses YAML structure that is consistent with other workflows * Use GitHub Actions runner in job name * Use same variable for workflow job name and runner
1 parent aaad447 commit fe7891e

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

.github/workflows/docs.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ on:
1010
- 'poetry.lock'
1111

1212
jobs:
13-
Build:
13+
build:
14+
name: Build
1415
runs-on: ubuntu-latest
1516

1617
steps:
@@ -20,27 +21,32 @@ jobs:
2021
- name: Set up Python
2122
uses: actions/[email protected]
2223

23-
- name: Install Poetry
24-
uses: Gr1N/setup-poetry@v4
24+
- name: Get Python version
25+
id: python-version
26+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
2527

26-
- name: Write environment information to a file
27-
run: |
28-
pwd > environment
29-
python --version >> environment
28+
- name: Install Poetry
29+
uses: snok/install-poetry@v1
30+
with:
31+
virtualenvs-create: true
32+
virtualenvs-in-project: true
3033

3134
- name: Restore cache
35+
id: cache
3236
uses: actions/[email protected]
3337
with:
34-
path: ~/.cache/pypoetry
35-
key: poetry|${{ hashFiles('environment') }}|${{ hashFiles('poetry.lock') }}
38+
path: .venv
39+
key: poetry-${{ runner.os }}-${{ steps.python-version.outputs.version }}-${{ hashFiles('poetry.lock') }}
3640

3741
- name: Install dependencies
42+
if: steps.cache.outputs.cache-hit != 'true'
3843
run: poetry install
3944

4045
- name: Build documentation
4146
run: poetry run make -C docs html
4247

4348
- name: Deploy documentation
49+
if: success()
4450
uses: JamesIves/[email protected]
4551
with:
4652
branch: gh-pages

.github/workflows/quality.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ jobs:
4242
- name: Set up Python
4343
uses: actions/[email protected]
4444

45-
- name: Hash Python version
46-
id: hash
47-
run: echo ::set-output name=hash::$(python --version | sha256sum | cut -d' ' -f1)
45+
- name: Get Python version
46+
id: python-version
47+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
4848

4949
- name: Restore cache
5050
uses: actions/[email protected]
5151
with:
52-
path: ~/.cache/pre-commit
53-
key: pre-commit|${{ steps.hash.outputs.hash }}|${{ hashFiles('.pre-commit-config.yaml') }}
52+
path: |
53+
~/.cache/pip
54+
~/.cache/pre-commit
55+
key: pre-commit-${{ runner.os }}-${{ steps.python-version.outputs.version }}-${{ hashFiles('.pre-commit-config.yaml') }}
5456

5557
- name: Run pre-commit
5658
uses: pre-commit/[email protected]

.github/workflows/test.yml

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,47 @@ on:
1414

1515
jobs:
1616
test:
17-
name: '${{ matrix.os_name }}: Python ${{ matrix.python }}'
18-
runs-on: ${{ matrix.os }}
17+
name: ${{ matrix.os }} / ${{ matrix.python-version }}
18+
runs-on: ${{ matrix.os }}-latest
19+
defaults:
20+
run:
21+
shell: bash
1922

2023
strategy:
2124
fail-fast: false
2225
matrix:
23-
os: [ubuntu-latest, macos-latest, windows-latest]
24-
python: [3.7, 3.8, 3.9]
25-
include:
26-
- os: ubuntu-latest
27-
os_name: Linux
28-
poetry_cache: ~/.cache/pypoetry
29-
30-
- os: macos-latest
31-
os_name: macOS
32-
poetry_cache: ~/Library/Caches/pypoetry
33-
34-
- os: windows-latest
35-
os_name: Windows
36-
poetry_cache: ~\AppData\Local\pypoetry\Cache
26+
os: [Ubuntu, macOS, Windows]
27+
python-version: [3.7, 3.8, 3.9]
3728

3829
steps:
3930
- name: Checkout
4031
uses: actions/[email protected]
4132

42-
- name: Set up Python
33+
- name: Set up Python ${{ matrix.python-version }}
4334
uses: actions/[email protected]
4435
with:
45-
python-version: ${{ matrix.python }}
36+
python-version: ${{ matrix.python-version }}
4637

47-
- name: Install Poetry
48-
uses: Gr1N/setup-poetry@v4
38+
- name: Get Python version
39+
id: python-version
40+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
4941

50-
- name: Write environment information to a file
51-
run: |
52-
pwd > environment
53-
python --version >> environment
42+
- name: Install Poetry
43+
uses: snok/install-poetry@v1
44+
with:
45+
virtualenvs-create: true
46+
virtualenvs-in-project: true
5447

5548
- name: Restore cache
56-
id: poetry-cache
49+
id: cache
5750
uses: actions/[email protected]
58-
if: runner.os != 'Windows'
5951
with:
60-
path: ${{ matrix.poetry_cache }}
61-
key: poetry|${{ hashFiles('environment') }}|${{ hashFiles('poetry.lock') }}
52+
path: .venv
53+
key: poetry-${{ runner.os }}-${{ steps.python-version.outputs.version }}-${{ hashFiles('poetry.lock') }}
6254

6355
- name: Install dependencies
56+
if: steps.cache.outputs.cache-hit != 'true'
6457
run: poetry install
65-
if: steps.poetry-cache.outputs.cache-hit != 'true'
6658

6759
- name: Run tests
6860
run: poetry run pytest tests/ --cov=torchts
@@ -71,8 +63,8 @@ jobs:
7163
run: poetry run coverage xml
7264

7365
- name: Upload coverage report
74-
uses: codecov/codecov-action@v1
7566
if: success()
67+
uses: codecov/codecov-action@v1
7668
with:
7769
token: ${{ secrets.CODECOV_TOKEN }}
7870
file: ./coverage.xml

0 commit comments

Comments
 (0)