Skip to content

Commit 26811a8

Browse files
authored
Merge pull request #710 from consideRatio/pr/github-ci-spacing
Revision of our GitHub Workflows and README.rst to README.md
2 parents d4be3c1 + 6cb3172 commit 26811a8

File tree

11 files changed

+433
-216
lines changed

11 files changed

+433
-216
lines changed

.github/integration-test.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import os
55

66

7-
def build_systemd_image(image_name, source_path):
7+
def build_systemd_image(image_name, source_path, build_args=None):
88
"""
99
Build docker image with systemd at source_path.
1010
1111
Built image is tagged with image_name
1212
"""
13-
subprocess.check_call([
14-
'docker', 'build', '-t', image_name, source_path
15-
])
13+
cmd = ['docker', 'build', '-t', image_name, source_path]
14+
if build_args:
15+
cmd.extend([f"--build-arg={ba}" for ba in build_args])
16+
subprocess.check_call(cmd)
1617

1718

1819
def run_systemd_image(image_name, container_name, bootstrap_pip_spec):
@@ -94,6 +95,10 @@ def run_test(image_name, test_name, bootstrap_pip_spec, test_files, upgrade, ins
9495
copy_to_container(test_name, os.path.join(source_path, 'bootstrap/.'), '/srv/src')
9596
copy_to_container(test_name, os.path.join(source_path, 'integration-tests/'), '/srv/src')
9697

98+
# These logs can be very relevant to debug a container startup failure
99+
print(f"--- Start of logs from the container: {test_name}")
100+
print(subprocess.check_output(['docker', 'logs', test_name]).decode())
101+
print(f"--- End of logs from the container: {test_name}")
97102

98103
# Install TLJH from the default branch first to test upgrades
99104
if upgrade:
@@ -115,7 +120,10 @@ def run_test(image_name, test_name, bootstrap_pip_spec, test_files, upgrade, ins
115120
)
116121
run_container_command(
117122
test_name,
118-
'/opt/tljh/hub/bin/python3 -m pytest -v {}'.format(
123+
# We abort pytest after two failures as a compromise between wanting to
124+
# avoid a flood of logs while still understanding if multiple tests
125+
# would fail.
126+
'/opt/tljh/hub/bin/python3 -m pytest --verbose --maxfail=2 --color=yes --durations=10 --capture=no {}'.format(
119127
' '.join([os.path.join('/srv/src/integration-tests/', f) for f in test_files])
120128
)
121129
)
@@ -138,13 +146,21 @@ def main():
138146
argparser = argparse.ArgumentParser()
139147
subparsers = argparser.add_subparsers(dest='action')
140148

141-
subparsers.add_parser('build-image')
149+
build_image_parser = subparsers.add_parser('build-image')
150+
build_image_parser.add_argument(
151+
"--build-arg",
152+
action="append",
153+
dest="build_args",
154+
)
155+
142156
subparsers.add_parser('stop-container').add_argument(
143157
'container_name'
144158
)
159+
145160
subparsers.add_parser('start-container').add_argument(
146161
'container_name'
147162
)
163+
148164
run_parser = subparsers.add_parser('run')
149165
run_parser.add_argument('container_name')
150166
run_parser.add_argument('command')
@@ -181,7 +197,7 @@ def main():
181197
elif args.action == 'stop-container':
182198
stop_container(args.container_name)
183199
elif args.action == 'build-image':
184-
build_systemd_image(image_name, 'integration-tests')
200+
build_systemd_image(image_name, 'integration-tests', args.build_args)
185201

186202

187203
if __name__ == '__main__':
Lines changed: 166 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,182 @@
1+
# This is a GitHub workflow defining a set of jobs with a set of steps.
2+
# ref: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
3+
#
4+
name: Integration tests
5+
16
on:
27
pull_request:
8+
paths-ignore:
9+
- "docs/**"
10+
- "**.md"
11+
- "**.rst"
12+
- ".github/workflows/*"
13+
- "!.github/workflows/integration-test.yaml"
314
push:
15+
paths-ignore:
16+
- "docs/**"
17+
- "**.md"
18+
- "**.rst"
19+
- ".github/workflows/*"
20+
- "!.github/workflows/integration-test.yaml"
21+
branches-ignore:
22+
- "dependabot/**"
23+
- "pre-commit-ci-update-config"
424
workflow_dispatch:
525

626
jobs:
7-
integration-test:
8-
runs-on: ubuntu-18.04
27+
28+
# This job is used as a workaround to a limitation when using a matrix of
29+
# variations that a job should be executed against. The limitation is that a
30+
# matrix once defined can't include any conditions.
31+
#
32+
# What this job does before our real test job with a matrix of variations run,
33+
# is to decide on that matrix of variations a conditional logic of our choice.
34+
#
35+
# For more details, see this excellent stack overflow answer:
36+
# https://stackoverflow.com/a/65434401/2220152
37+
#
38+
decide-on-test-jobs-to-run:
39+
name: Decide on test jobs to run
40+
runs-on: ubuntu-latest
41+
42+
outputs:
43+
matrix: ${{ steps.set-matrix.outputs.matrix }}
44+
45+
steps:
46+
# Currently, this logic filters out a matrix entry equaling a specific git
47+
# reference identified by "dont_run_on_ref".
48+
- name: Decide on test jobs to run
49+
id: set-matrix
50+
run: |
51+
matrix_post_filter=$(
52+
echo "$matrix_include_pre_filter" \
53+
| yq e --output-format=json '.' - \
54+
| jq '{"include": map( . | select(.dont_run_on_ref != "${{ github.ref }}" ))}'
55+
)
56+
echo ::set-output name=matrix::$(echo "$matrix_post_filter")
57+
58+
echo "The subsequent job's matrix are:"
59+
echo $matrix_post_filter | jq '.'
60+
env:
61+
matrix_include_pre_filter: |
62+
- name: "Int. tests: Ubuntu 18.04, Py 3.6"
63+
ubuntu_version: "18.04"
64+
python_version: "3.6"
65+
extra_flags: ""
66+
- name: "Int. tests: Ubuntu 20.04, Py 3.9"
67+
ubuntu_version: "20.04"
68+
python_version: "3.9"
69+
extra_flags: ""
70+
- name: "Int. tests: Ubuntu 21.10, Py 3.9"
71+
runs_on: "20.04"
72+
ubuntu_version: "21.10"
73+
python_version: "3.9"
74+
extra_flags: ""
75+
- name: "Int. tests: Ubuntu 20.04, Py 3.9, --upgrade"
76+
ubuntu_version: "20.04"
77+
python_version: "3.9"
78+
extra_flags: --upgrade
79+
dont_run_on_ref: refs/heads/master
80+
81+
integration-tests:
82+
needs: decide-on-test-jobs-to-run
83+
84+
# runs-on can only be configured to the LTS releases of ubuntu (18.04,
85+
# 20.04, ...), so if we want to test against the latest non-LTS release, we
86+
# must compromise when configuring runs-on and configure runs-on to be the
87+
# latest LTS release instead.
88+
#
89+
# This can have consequences because actions like actions/setup-python will
90+
# mount cached installations associated with the chosen runs-on environment.
91+
#
92+
runs-on: ${{ format('ubuntu-{0}', matrix.runs_on || matrix.ubuntu_version) }}
93+
94+
name: ${{ matrix.name }}
95+
strategy:
96+
fail-fast: false
97+
matrix: ${{ fromJson(needs.decide-on-test-jobs-to-run.outputs.matrix) }}
98+
999
steps:
10100
- uses: actions/checkout@v2
11101
- uses: actions/setup-python@v2
12102
with:
13-
python-version: 3.6
14-
- name: Set BOOTSTRAP_PIP_SPEC value
103+
python-version: ${{ matrix.python_version }}
104+
105+
- name: Install pytest
106+
run: python3 -m pip install pytest
107+
108+
# We abort pytest after two failures as a compromise between wanting to
109+
# avoid a flood of logs while still understanding if multiple tests would
110+
# fail.
111+
- name: Run bootstrap tests (Runs in/Builds ubuntu:${{ matrix.ubuntu_version }} derived image)
15112
run: |
16-
echo "BOOTSTRAP_PIP_SPEC=git+https://github.com/$GITHUB_REPOSITORY.git@$GITHUB_REF" >> $GITHUB_ENV
17-
- name: Build systemd image
113+
pytest --verbose --maxfail=2 --color=yes --durations=10 --capture=no \
114+
integration-tests/test_bootstrap.py
115+
timeout-minutes: 15
116+
env:
117+
# integration-tests/test_bootstrap.py will build and start containers
118+
# based on this environment variable. This is similar to how
119+
# .github/integration-test.py build-image can take a --build-arg
120+
# setting the ubuntu_version.
121+
UBUNTU_VERSION: ${{ matrix.ubuntu_version }}
122+
123+
# We build a docker image from wherein we will work
124+
- name: Build systemd image (Builds ubuntu:${{ matrix.ubuntu_version }} derived image)
18125
run: |
19-
.github/integration-test.py build-image
20-
- name: Run bootstrap checks
126+
.github/integration-test.py build-image \
127+
--build-arg "ubuntu_version=${{ matrix.ubuntu_version }}"
128+
129+
# FIXME: Make the logic below easier to follow.
130+
# - In short, setting BOOTSTRAP_PIP_SPEC here, specifies from what
131+
# location the tljh python package should be installed from. In this
132+
# GitHub Workflow's test job, we provide a remote reference to itself as
133+
# found on GitHub - this could be the HEAD of a PR branch or the default
134+
# branch on merge.
135+
#
136+
# Overview of how this logic influences the end result.
137+
# - integration-test.yaml:
138+
# Runs integration-test.py by passing --bootstrap-pip-spec flag with a
139+
# reference to the pull request on GitHub.
140+
# - integration-test.py:
141+
# Starts a pre-build systemd container, setting the
142+
# TLJH_BOOTSTRAP_PIP_SPEC based on its passed --bootstrap-pip-spec value.
143+
# - systemd container:
144+
# Runs bootstrap.py
145+
# - bootstrap.py
146+
# Makes use of TLJH_BOOTSTRAP_PIP_SPEC environment variable to install
147+
# the tljh package from a given location, which could be a local git
148+
# clone of this repo where setup.py resides, or a reference to some
149+
# GitHub branch for example.
150+
- name: Set BOOTSTRAP_PIP_SPEC value
21151
run: |
22-
python3 -m pip install pytest
23-
pytest integration-tests/test_bootstrap.py -s
24-
- name: Run basic tests
152+
echo "BOOTSTRAP_PIP_SPEC=git+https://github.com/$GITHUB_REPOSITORY.git@$GITHUB_REF" >> $GITHUB_ENV
153+
echo $BOOTSTRAP_PIP_SPEC
154+
155+
- name: Run basic tests (Runs in ubuntu:${{ matrix.ubuntu_version }} derived image)
25156
run: |
26-
.github/integration-test.py run-test \
27-
--bootstrap-pip-spec "$BOOTSTRAP_PIP_SPEC" \
28-
basic-tests test_hub.py test_proxy.py \
29-
test_install.py test_extensions.py
30-
- name: Run admin tests
157+
.github/integration-test.py run-test basic-tests \
158+
--bootstrap-pip-spec "$BOOTSTRAP_PIP_SPEC" \
159+
${{ matrix.extra_flags }} \
160+
test_hub.py \
161+
test_proxy.py \
162+
test_install.py \
163+
test_extensions.py
164+
timeout-minutes: 15
165+
166+
- name: Run admin tests (Runs in ubuntu:${{ matrix.ubuntu_version }} derived image)
31167
run: |
32-
.github/integration-test.py run-test \
33-
--installer-args "--admin admin:admin" \
34-
--bootstrap-pip-spec "$BOOTSTRAP_PIP_SPEC" \
35-
basic-tests test_admin_installer.py \
36-
- name: Run plugin tests
168+
.github/integration-test.py run-test admin-tests \
169+
--installer-args "--admin admin:admin" \
170+
--bootstrap-pip-spec "$BOOTSTRAP_PIP_SPEC" \
171+
${{ matrix.extra_flags }} \
172+
test_admin_installer.py
173+
timeout-minutes: 15
174+
175+
- name: Run plugin tests (Runs in ubuntu:${{ matrix.ubuntu_version }} derived image)
37176
run: |
38-
.github/integration-test.py run-test \
39-
--bootstrap-pip-spec "$BOOTSTRAP_PIP_SPEC" \
40-
--installer-args "--plugin /srv/src/integration-tests/plugins/simplest" \
41-
plugins test_simplest_plugin.py \
177+
.github/integration-test.py run-test plugin-tests \
178+
--bootstrap-pip-spec "$BOOTSTRAP_PIP_SPEC" \
179+
--installer-args "--plugin /srv/src/integration-tests/plugins/simplest" \
180+
${{ matrix.extra_flags }} \
181+
test_simplest_plugin.py
182+
timeout-minutes: 15

0 commit comments

Comments
 (0)