-
Notifications
You must be signed in to change notification settings - Fork 1
172 lines (133 loc) · 4.58 KB
/
main.yml
File metadata and controls
172 lines (133 loc) · 4.58 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Pipeline tests and deploys on Ubuntu
on:
push:
# branches:
# - main
# - dev
branches: # necessary if using tags fields
- '**'
pull_request:
# branches:
# - main
# - dev
workflow_dispatch: # allows manual triggering
jobs:
#
# checks if there are some changes in the important code files
#
run-pipe-desicion:
runs-on: ubuntu-latest
outputs:
workflows: ${{ steps.filter.outputs.workflows == 'true' }}
code: ${{ steps.filter.outputs.code == 'true' || steps.filter.outputs.venv == 'true' || steps.filter.outputs.makefile == 'true' }}
changes: ${{ steps.filter.outputs.workflows == 'true' || steps.filter.outputs.venv == 'true' || steps.filter.outputs.makefile == 'true' || steps.filter.outputs.code == 'true' }}
skip_tests: ${{ steps.signs.outputs.SKIP_TESTS == 'yes' }}
last_workflow_failed: ${{ steps.last_status.outputs.last_status == 'failure' }}
steps:
- uses: actions/checkout@v3
- name: Set environment variables
run: |
# Short name for current branch. For PRs, use target branch (base ref)
GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV
- name: Info message
run: |
echo GitHub event = ${{ github.event_name }} on branch ${{ env.GIT_BRANCH }}
- name: Get previous workflow status
uses: Mercymeilya/last-workflow-status@v0.3.3
id: last_status
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
- uses: dorny/paths-filter@v2
id: filter
with:
base: ${{ github.head_ref || github.ref_name }} # compare with same branch
filters: |
workflows:
- '.github/workflows/main.yml'
makefile:
- 'Makefile'
venv:
- 'requirements.txt'
- 'requirements-dev.txt'
code:
- 'toml_union/**'
- name: workflow message
if: steps.filter.outputs.workflows == 'true'
run: echo "Changed python venv workflow"
- name: venv message
if: steps.filter.outputs.venv == 'true'
run: echo "Changed venv"
- name: makefile message
if: steps.filter.outputs.makefile == 'true'
run: echo "Changed Makefile or make scripts"
- name: code message
if: steps.filter.outputs.code == 'true'
run: echo "Changed backend code"
- name: check commit message for signs
id: signs
run: |
if [ '${{ github.event_name }}' == 'push' ]; then
message="${{ github.event.head_commit.message }}"
else
message="${{ github.event.pull_request.base.label}}"
fi
echo "commit message: ${message}"
echo "SKIP_TESTS=no" >> "$GITHUB_OUTPUT"
for pattern in "<>" "update to"
do
if [ "$(echo ${message} | grep "$pattern")" != "" ]; then
echo "SKIP_TESTS=yes" >> "$GITHUB_OUTPUT"
echo "signal of test skipping"
break
fi
done
build-and-test:
runs-on: ubuntu-latest
needs: run-pipe-desicion
if: needs.run-pipe-desicion.outputs.workflows == 'true' || (( needs.run-pipe-desicion.outputs.changes == 'true' || needs.run-pipe-desicion.outputs.last_workflow_failed == 'true' ) && needs.run-pipe-desicion.outputs.skip_tests != 'true' )
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.9"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
sudo apt update
sudo apt install -y make
echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV
####################
#
# INSTALL/CACHE venv
#
####################
- name: Cache venv
id: cache-venv
uses: actions/cache@v3
env:
cache-name: cache-venv
with:
path: venv
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt', 'requirements-dev.txt') }}
- if: ${{ steps.cache-venv.outputs.cache-hit != 'true' }}
name: Create venv
run: |
rm -rf venv || true
python -m venv venv
venv/bin/python -m pip install -r requirements-dev.txt
#############
#
# BASIC TESTS
#
#############
- name: doctest
run: |
make doctest
- name: pytest
run: |
make doctest