121 lines (115 loc) · 4.47 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Build
on:
pull_request:
push:
branches:
- main
paths-ignore: # These will run in publish.yml.
- .github/**
- pyproject.toml
- scripts/build.sh
workflow_call:
outputs:
version:
description: "Version of built module"
value: ${{ jobs.build.outputs.version }}
permissions: {} # No permissions needed for this workflow.
jobs:
build:
name: Build and test
outputs:
version: ${{ steps.build.outputs.version }}
strategy:
max-parallel: 5 # Set equal to the number of Linux tests.
matrix:
os: ['ubuntu-latest']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
include:
- os: windows-latest
python-version: '3.8'
- os: macos-latest
python-version: '3.8'
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Enable build input caching
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
with:
path: |
./.cache/pip
./.cache/pypoetry
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Don't restore for pushes to the main branch. Otherwise the cache
# will continue to grow over time.
restore-keys: >-
${{ github.event_name == 'push' &&
github.ref_name == 'main' &&
'no-restore' || runner.os }}-${{ matrix.python-version }}-
- name: Build
id: build
env:
OUTPUT_ENV_VAR: GITHUB_OUTPUT
PIP_CACHE_DIR: ./.cache/pip
POETRY_CACHE_DIR: ./.cache/pypoetry
run: bash -x ./scripts/build.sh
- name: Check for code modifications
if: always()
id: modified
run: |
# exit 0 if nothing was modified.
[ -z "$(git diff-index "${GITHUB_SHA}")" ] && exit 0
# Copy modified files to ./.cache/diff. This path is in .gitignore
rm -fR ./.cache/diff && mkdir --parents ./.cache/diff
git diff-index -z --name-only --diff-filter=M "${GITHUB_SHA}" | \
xargs -0 cp --parents -t ./.cache/diff/ -- 2>/dev/null && \
echo "build-changes=./.cache/diff/" | tee -a "$GITHUB_OUTPUT"
echo "FAIL: Files were changed during the Build step"
echo "Please ensure pre-commit was run on these changes"
exit 1
- name: Archive code modifications
if: failure() && steps.modified.outputs.build-changes
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: build-changes-${{ join(matrix.*, '-') }}
path: ${{ steps.modified.outputs.build-changes }}
- name: Archive build artifacts
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
if-no-files-found: error
name: dist-${{ join(matrix.*, '-') }}
path: dist/
- name: Archive coverage results
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
if-no-files-found: error
name: coverage-${{ join(matrix.*, '-') }}
path: ${{ steps.build.outputs.coverage-lcov }}
# Coverage reporting is its own step so it can optionally fail if coveralls
# is experiencing issues. pyWeMo doesn't currently have any logic that is
# different between Python versions, so the coverage output from only one
# version needs to be reported. Change the artifact name to use the coverage
# from a different matrix build version.
coverage:
name: Report coverage to coveralls.io
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: coverage-ubuntu-latest-3.10
- uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # v2.2.3
with:
path-to-lcov: coverage.lcov