Skip to content

Commit dcd09c4

Browse files
[CONFIG] More Improvements for CI/CD (- WIP #388 -)
Additions with file .github/actions/setup-py-reqs/action.yml: * ✨ New action for handling python pip installs in CI/CD Changes in file .github/workflows/Tests.yml: * improved summary reporting for CI/CD tests * integrated new GHA template * related work Changes in file Makefile: * attempt to make build target less pre-emptive * related work
1 parent 8b3d5cc commit dcd09c4

File tree

3 files changed

+625
-49
lines changed

3 files changed

+625
-49
lines changed
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
---
2+
name: 'Manage and install requirements'
3+
description: 'Performs steps to install from various requirement.txt files for the Multicast Project.'
4+
author: 'Mr. Walls'
5+
branding:
6+
icon: 'download-cloud'
7+
color: 'purple'
8+
inputs:
9+
sha:
10+
description: |
11+
The commit to report dependencies for. Should already be cloned and checked-out beforehand.
12+
required: true
13+
default: ${{ github.server_url == 'https://github.com' && github.sha || 'HEAD' }}
14+
token:
15+
description: |
16+
The token used to authenticate when fetching results from GitHub repositories.
17+
When running this action on github.com, the default value is sufficient. When running on
18+
GHES, you can pass a personal access token for github.com if you are experiencing
19+
rate limiting.
20+
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
21+
required: true
22+
python-version:
23+
description: |
24+
The python version to use. The default is to use the value of the environment
25+
variable 'PYTHON_VERSION'.
26+
default: '3.12'
27+
required: true
28+
outputs:
29+
sha:
30+
description: "The SHA of the commit checked-out"
31+
value: ${{ steps.output_sha.outputs.sha || 'HEAD' }}
32+
python-version:
33+
description: "The python version that was used in the run"
34+
value: ${{ steps.output_python.outputs.python-version || '' }}
35+
deps_status:
36+
description: "The outcome of evaluating the DEPs steps"
37+
value: ${{ steps.deps_outcome.outcome || 'cancelled' }}
38+
deps_build_status:
39+
description: "The outcome of the requirements.txt install Group"
40+
value: ${{ steps.install_build_requirements.outcome || 'cancelled' }}
41+
deps_test_status:
42+
description: "The outcome of the tests/requirements.txt install Group"
43+
value: ${{ steps.install_test_requirements.outcome || 'cancelled' }}
44+
deps_doc_status:
45+
description: "The outcome of the docs/requirements.txt install Group"
46+
value: ${{ steps.install_docs_requirements.outcome || 'cancelled' }}
47+
artifact-name:
48+
description: "The uploaded artifact-name"
49+
value: ${{ steps.output_artifact_name.outputs.artifact-name }}
50+
artifact-files:
51+
description: "The uploaded artifact-files"
52+
value: ${{ steps.output_artifact_files.outputs.files }}
53+
artifact-id:
54+
description: "The uploaded artifact-id"
55+
value: ${{ steps.upload.outputs.artifact-id }}
56+
artifact-url:
57+
description: "The uploaded artifact-url"
58+
value: ${{ steps.upload.outputs.artifact-url }}
59+
artifact-digest:
60+
description: "The uploaded artifact-digest"
61+
value: ${{ steps.upload.outputs.artifact-digest }}
62+
63+
runs:
64+
using: composite
65+
steps:
66+
- name: "Calculate Commit SHA"
67+
id: output_sha
68+
shell: bash
69+
run: |
70+
printf "sha=%s\n" $(git rev-parse --verify '${{ inputs.sha }}') >> "$GITHUB_OUTPUT"
71+
printf "BUILD_SHA=%s\n" $(git rev-parse --verify '${{ inputs.sha }}') >> "$GITHUB_ENV"
72+
- name: "Setup Python"
73+
id: output_python
74+
if: ${{ !cancelled() }}
75+
env:
76+
PYTHON_VERSION_INPUT: ${{ inputs.python-version }}
77+
shell: bash
78+
run: |
79+
if [[ -z $PYTHON_VERSION_INPUT ]]; then
80+
printf "python-version=%s\n" "${PYTHON_VERSION_INPUT}" >> "$GITHUB_OUTPUT"
81+
PYTHON_VERSION=${PYTHON_VERSION_INPUT}
82+
else
83+
printf "python-version=%s\n" "${PYTHON_VERSION}" >> "$GITHUB_OUTPUT"
84+
fi
85+
printf "%s\n" "PYTHON_VERSION=${PYTHON_VERSION}" >> "$GITHUB_ENV"
86+
- name: "Prepare Artifact Name"
87+
id: output_artifact_name
88+
if: ${{ !cancelled() }}
89+
shell: bash
90+
run: |
91+
printf "artifact-name=%s\n" multicast-deps-${{ steps.output_sha.outputs.sha }}-part-$(uuidgen) >> "$GITHUB_OUTPUT"
92+
printf "%s\n" "DEPS_STEP_SUMMARY=Dependencies-Summary-Artifact-${PYTHON_VERSION}.txt" >> "$GITHUB_ENV"
93+
- name: "Install Build Dependencies"
94+
id: install_build_requirements
95+
if: ${{ !cancelled() }}
96+
shell: bash
97+
run: |
98+
printf "%s\n" "::group::prep-build-reqs"
99+
make -j1 -f Makefile init || exit 1
100+
printf "%s\n" "::endgroup::"
101+
- name: "Install Test Dependencies"
102+
id: install_test_requirements
103+
if: ${{ !cancelled() }}
104+
shell: bash
105+
run: |
106+
printf "%s\n" "::group::prep-test-reqs"
107+
make -j1 -f Makefile test-reqs || exit 1
108+
printf "%s\n" "::endgroup::"
109+
- name: "Install Documentation Dependencies"
110+
id: install_docs_requirements
111+
if: ${{ !cancelled() }}
112+
shell: bash
113+
run: |
114+
printf "%s\n" "::group::prep-docs-reqs"
115+
make -j1 -f Makefile docs-reqs || exit 1
116+
printf "%s\n" "::endgroup::"
117+
- name: "Evaluate Dependencies"
118+
id: deps_outcome
119+
if: ${{ !cancelled() }}
120+
shell: bash
121+
run: |
122+
if [[ "${{ steps.install_build_requirements.outcome }}" != "failure" ]] ; then
123+
if [[ ( -r requirements.txt ) ]] ; then
124+
THE_RESULT="success"
125+
else
126+
THE_RESULT="skipped"
127+
fi
128+
else
129+
THE_RESULT="failure"
130+
fi
131+
if [[ "${{ steps.install_test_requirements.outcome }}" == "success" && "${THE_RESULT}" == "success" ]] ; then
132+
THE_RESULT="success"
133+
else
134+
if [[ "${{ steps.install_test_requirements.outcome }}" == "failure" ]] ; then
135+
THE_RESULT="failure"
136+
fi
137+
fi
138+
if [[ "${{ steps.install_docs_requirements.outcome }}" == "success" && "${THE_RESULT}" == "success" ]] ; then
139+
THE_RESULT="success"
140+
else
141+
if [[ "${{ steps.install_docs_requirements.outcome }}" == "failure" ]] ; then
142+
THE_RESULT="failure"
143+
fi
144+
fi
145+
if [[ "${THE_RESULT}" == "success" ]] ; then
146+
exit 0
147+
else
148+
exit 1
149+
fi
150+
- name: "Summarize DEPs"
151+
id: deps_report
152+
if: ${{ always() }}
153+
shell: bash
154+
run: |
155+
if [[ "${{ steps.deps_outcome.outcome }}" == "success" ]] ; then
156+
printf "%s\n" " * :ballot_box_with_check: Installing dependencies succeeded with python version \`${PYTHON_VERSION}\` for [${BUILD_SHA}](https://github.com/reactive-firewall/multicast/blob/${BUILD_SHA}/requirements.txt)" > "$DEPS_STEP_SUMMARY"
157+
printf "%s\n" " :ballot_box_with_check: Installing dependencies succeeded with python version \`${PYTHON_VERSION}\`" >> "$GITHUB_STEP_SUMMARY"
158+
else
159+
printf "%s\n" " * :x: ~Installing dependencies succeeded with python version \`${PYTHON_VERSION}\` for \`${BUILD_SHA}\`~" > "$DEPS_STEP_SUMMARY"
160+
printf "%s\n" " :x: ~Installing dependencies succeeded with python version \`${PYTHON_VERSION}\`~" >> "$GITHUB_STEP_SUMMARY"
161+
fi
162+
if [[ "${{ steps.install_build_requirements.outcome }}" == "success" ]] ; then
163+
printf "%s\n" " * :ballot_box_with_check: Installing from [requirements.txt](https://github.com/reactive-firewall/multicast/blob/${BUILD_SHA}/requirements.txt) succeeded" >> "$DEPS_STEP_SUMMARY"
164+
else
165+
printf "%s\n" " * :x: Installing from `requirements.txt` failed" >> "$DEPS_STEP_SUMMARY"
166+
fi
167+
if [[ "${{ steps.install_test_requirements.outcome }}" == "success" ]] ; then
168+
printf "%s\n" " * :ballot_box_with_check: Installing from [tests/requirements.txt](https://github.com/reactive-firewall/multicast/blob/${BUILD_SHA}/tests/requirements.txt) succeeded" >> "$DEPS_STEP_SUMMARY"
169+
else
170+
printf "%s\n" " * :x: Installing from `tests/requirements.txt` failed" >> "$DEPS_STEP_SUMMARY"
171+
fi
172+
if [[ "${{ steps.install_docs_requirements.outcome }}" == "success" ]] ; then
173+
printf "%s\n" " * :ballot_box_with_check: Installing from [docs/requirements.txt](https://github.com/reactive-firewall/multicast/blob/${BUILD_SHA}/docs/requirements.txt) succeeded" >> "$DEPS_STEP_SUMMARY"
174+
else
175+
printf "%s\n" " * :x: Installing from `docs/requirements.txt` failed" >> "$DEPS_STEP_SUMMARY"
176+
fi
177+
- name: "Collect and Enumerate Generated Files"
178+
id: output_artifact_files
179+
if: ${{ !cancelled() && (github.repository == 'reactive-firewall/multicast') }}
180+
env:
181+
DEPS_MATCH_PATTERN: "Dependencies-Summary-Artifact-*.txt"
182+
SCRIPT_NAME: ".github/actions/setup-py-reqs/action.yml"
183+
shell: bash
184+
run: |
185+
FILES=$(git ls-files -o --exclude-standard -- ${{ env.DEPS_MATCH_PATTERN }} )
186+
if [ -z "$FILES" ]; then
187+
printf "::warning file=%s:: %s\n" "${SCRIPT_NAME}" "No summary files found."
188+
printf "%s\n" "files=" >> "$GITHUB_OUTPUT"
189+
exit 1
190+
else
191+
printf "%s\n" "DEPS summary files found:"
192+
printf "%s\n" "$FILES"
193+
mkdir DEPS || :
194+
# Replace line breaks with spaces for GitHub Action Output
195+
FILES="${FILES//$'\n'/ }"
196+
printf "%s\n" "files=$FILES" >> "$GITHUB_OUTPUT"
197+
exit 0
198+
fi
199+
- name: "Upload Details"
200+
id: upload
201+
if: ${{ !cancelled() && (github.repository == 'reactive-firewall/multicast') }}
202+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
203+
with:
204+
path: DEPS
205+
name: ${{ steps.output_artifact_name.outputs.artifact-name }}
206+
if-no-files-found: error
207+
compression-level: 9
208+
overwrite: true
209+
- name: "Cleanup from run"
210+
id: deps_cleanup_success
211+
if: ${{ success() }}
212+
shell: bash
213+
run: |
214+
rm -fRd ./DEPS 2>/dev/null || :
215+
- name: "Cleanup from failed run"
216+
id: deps_cleanup_failure
217+
if: ${{ failure() }}
218+
shell: bash
219+
run: |
220+
rm -fRd ./DEPS 2>/dev/null
221+
exit 1

0 commit comments

Comments
 (0)