Skip to content

Commit 31a151b

Browse files
committed
New CleanupArtifacts job template.
1 parent 9004342 commit 31a151b

4 files changed

Lines changed: 200 additions & 50 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# ==================================================================================================================== #
2+
# Authors: #
3+
# Patrick Lehmann #
4+
# #
5+
# ==================================================================================================================== #
6+
# Copyright 2020-2026 The pyTooling Authors #
7+
# #
8+
# Licensed under the Apache License, Version 2.0 (the "License"); #
9+
# you may not use this file except in compliance with the License. #
10+
# You may obtain a copy of the License at #
11+
# #
12+
# http://www.apache.org/licenses/LICENSE-2.0 #
13+
# #
14+
# Unless required by applicable law or agreed to in writing, software #
15+
# distributed under the License is distributed on an "AS IS" BASIS, #
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
17+
# See the License for the specific language governing permissions and #
18+
# limitations under the License. #
19+
# #
20+
# SPDX-License-Identifier: Apache-2.0 #
21+
# ==================================================================================================================== #
22+
name: 🗑️ Cleanup
23+
24+
on:
25+
workflow_call:
26+
inputs:
27+
ubuntu_image_version:
28+
description: 'Ubuntu image version.'
29+
required: false
30+
default: '24.04'
31+
type: string
32+
json:
33+
description: 'JSON string of artifact names'
34+
required: false
35+
default: ''
36+
type: string
37+
artifact-json-ids:
38+
description: 'Artifacts to be removed by JSON name.'
39+
required: false
40+
default: ''
41+
type: string
42+
json2:
43+
description: 'Second JSON string of artifact names'
44+
required: false
45+
default: ''
46+
type: string
47+
artifact-json-ids2:
48+
description: 'Second set of artifacts to be removed by JSON name.'
49+
required: false
50+
default: ''
51+
type: string
52+
others:
53+
description: 'Other artifacts to be removed.'
54+
required: false
55+
default: ''
56+
type: string
57+
58+
jobs:
59+
CleanUp:
60+
name: 🗑️ Artifact Cleanup
61+
runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}"
62+
steps:
63+
- name: Compute artifact names
64+
id: compute
65+
shell: python
66+
run: |
67+
from json import loads, dumps
68+
from os import getenv
69+
70+
artifactNames = loads("""${{ inputs.json }}""")
71+
artifactNames2 = loads("""${{ inputs.json2 }}""")
72+
73+
artifactsToDelect = [k for k in "${{ inputs.artifact-json-ids }}".split(" ") if k != ""]
74+
artifactsToDelect2 = [k for k in "${{ inputs.artifact-json-ids2 }}".split(" ") if k != ""]
75+
76+
artifacts = []
77+
for name in artifactsToDelect:
78+
if name.startswith('#'):
79+
continue
80+
match name.split(":"):
81+
case [key] if key in artifactNames:
82+
artifacts.append(artifactNames[key])
83+
case [key, postfix] if key in artifactNames:
84+
artifacts.append(f"{artifactNames[key]}{postfix}")
85+
case [prefix, key] if key in artifactNames:
86+
artifacts.append(f"{prefix}{artifactNames[key]}")
87+
case [prefix, key, postfix] if key in artifactNames:
88+
artifacts.append(f"{prefix}{artifactNames[key]}{postfix}")
89+
case _:
90+
printf(f"Name '{name}' not found in JSON dictionary.")
91+
92+
print(f"{artifacts}")
93+
94+
artifacts2 = []
95+
for name in artifactsToDelect2:
96+
if name.startswith('#'):
97+
continue
98+
match name.split(":"):
99+
case [key] if key in artifactNames2:
100+
artifacts.append(artifactNames2[key])
101+
case [key, postfix] if key in artifactNames2:
102+
artifacts.append(f"{artifactNames2[key]}{postfix}")
103+
case [prefix, key] if key in artifactNames2:
104+
artifacts.append(f"{prefix}{artifactNames2[key]}")
105+
case [prefix, key, postfix] if key in artifactNames2:
106+
artifacts.append(f"{prefix}{artifactNames2[key]}{postfix}")
107+
case _:
108+
printf(f"Name '{name}' not found in second JSON dictionary.")
109+
110+
print(f"{artifacts2}")
111+
112+
# Write requirements path to special file
113+
github_output = Path(getenv("GITHUB_OUTPUT"))
114+
print(f"GITHUB_OUTPUT: {github_output}")
115+
with github_output.open("a+") as f:
116+
f.write(f"artifacts={dumps(artifacts)}\n")
117+
f.write(f"artifacts2={dumps(artifacts2)}\n")
118+
119+
- name: 🗑️ Delete artifacts
120+
uses: geekyeggo/delete-artifact@v5
121+
if: inputs.artifacts != ''
122+
continue-on-error: true
123+
with:
124+
name: |
125+
${{ join(fromJSON(steps.compute.outputs.artifacts).*, '
126+
') }}
127+
128+
- name: 🗑️ Delete second set of artifacts
129+
uses: geekyeggo/delete-artifact@v5
130+
if: inputs.artifacts2 != ''
131+
continue-on-error: true
132+
with:
133+
name: |
134+
${{ join(fromJSON(steps.compute.outputs.artifacts2).*, '
135+
') }}
136+
137+
- name: 🗑️ Delete other Artifacts
138+
uses: geekyeggo/delete-artifact@v5
139+
if: ${{ inputs.others != '' }}
140+
with:
141+
name: ${{ inputs.others }}

.github/workflows/CompletePipeline.yml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,17 @@ jobs:
384384
latex_artifact: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).documentation_latex }}
385385

386386
IntermediateCleanUp:
387-
uses: pyTooling/Actions/.github/workflows/IntermediateCleanUp.yml@dev
387+
uses: pyTooling/Actions/.github/workflows/CleanupArtifacts.yml@dev
388388
needs:
389389
- UnitTestingParams
390390
- PublishCoverageResults
391391
- PublishTestResults
392392
if: ( success() || failure() ) && inputs.cleanup == 'true'
393393
with:
394-
sqlite_coverage_artifacts_prefix: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_sqlite }}-
395-
xml_unittest_artifacts_prefix: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_xml }}-
394+
json: ${{ needs.UnitTestingParams.outputs.artifact_names }}
395+
artifact-json-ids: <|
396+
unittesting_xml:-*
397+
codecoverage_sqlite:-*
396398

397399
PDFDocumentation:
398400
uses: pyTooling/Actions/.github/workflows/LaTeXDocumentation.yml@dev
@@ -472,7 +474,7 @@ jobs:
472474
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
473475

474476
ArtifactCleanUp:
475-
uses: pyTooling/Actions/.github/workflows/ArtifactCleanUp.yml@dev
477+
uses: pyTooling/Actions/.github/workflows/CleanupArtifacts.yml@dev
476478
needs:
477479
- UnitTestingParams
478480
- UnitTesting
@@ -487,20 +489,21 @@ jobs:
487489
- IntermediateCleanUp
488490
if: inputs.cleanup == 'true'
489491
with:
490-
package: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).package_all }}
491-
remaining: |
492-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_html }}-*
493-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_xml }}-*
494-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_json }}-*
495-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_html }}-*
496-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_xml }}
497-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_html }}
498-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_sqlite }}
499-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_xml }}
500-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_json }}
501-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_html }}
502-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).statictyping_html }}
503-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).documentation_html }}
504-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).documentation_latex }}
505-
# ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).apptesting_xml }}-*
506-
# ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).documentation_pdf }}
492+
json: ${{ needs.UnitTestingParams.outputs.artifact_names }}
493+
artifact-json-ids: <|
494+
package_all
495+
unittesting_html:-*
496+
codecoverage_xml:-*
497+
codecoverage_json:-*
498+
codecoverage_html:-*
499+
unittesting_xml
500+
unittesting_html
501+
codecoverage_sqlite
502+
codecoverage_xml
503+
codecoverage_json
504+
codecoverage_html
505+
statictyping_html
506+
#apptesting_xml:-*
507+
documentation_html
508+
documentation_latex
509+
#documentation_pdf

.github/workflows/_Checking_ArtifactCleanup.yml renamed to .github/workflows/_Checking_CleanupArtifacts.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ jobs:
5050
retention-days: 1
5151

5252
ArtifactCleanUp:
53-
uses: pyTooling/Actions/.github/workflows/ArtifactCleanUp.yml@dev
53+
uses: pyTooling/Actions/.github/workflows/CleanupArtifacts.yml@dev
5454
needs:
5555
- Params
5656
- Testing
5757
- Package
5858
with:
59-
package: ${{ fromJson(needs.Params.outputs.artifact_names).package_all }}
60-
remaining: |
61-
${{ fromJson(needs.Params.outputs.artifact_names).unittesting_xml }}-*
59+
json: ${{ needs.Params.outputs.artifact_names }}
60+
artifact-json-ids: <|
61+
unittesting_xml:-*
62+
package_all

.github/workflows/_Checking_JobTemplates.yml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,16 @@ jobs:
187187
latex_artifact: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).documentation_latex }}
188188

189189
IntermediateCleanUp:
190-
uses: pyTooling/Actions/.github/workflows/IntermediateCleanUp.yml@dev
190+
uses: pyTooling/Actions/.github/workflows/CleanupArtifacts.yml@dev
191191
needs:
192192
- UnitTestingParams
193193
- PublishCoverageResults
194194
- PublishTestResults
195195
with:
196-
sqlite_coverage_artifacts_prefix: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_sqlite }}-
197-
xml_unittest_artifacts_prefix: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_xml }}-
196+
json: ${{ needs.UnitTestingParams.outputs.artifact_names }}
197+
artifact-json-ids: <|
198+
codecoverage_sqlite:-*
199+
unittesting_xml:-*
198200

199201
PDFDocumentation:
200202
uses: pyTooling/Actions/.github/workflows/LaTeXDocumentation.yml@dev
@@ -269,7 +271,7 @@ jobs:
269271
secrets: inherit
270272

271273
ArtifactCleanUp:
272-
uses: pyTooling/Actions/.github/workflows/ArtifactCleanUp.yml@dev
274+
uses: pyTooling/Actions/.github/workflows/CleanupArtifacts.yml@dev
273275
needs:
274276
- UnitTestingParams
275277
- PlatformTestingParams
@@ -284,24 +286,27 @@ jobs:
284286
- Install
285287
- IntermediateCleanUp
286288
with:
287-
package: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).package_all }}
288-
remaining: |
289-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_xml }}-*
290-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_html }}-*
291-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_xml }}-*
292-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_json }}-*
293-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_html }}-*
294-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_xml }}
295-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).unittesting_html }}
296-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_sqlite }}
297-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_xml }}
298-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_json }}
299-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).codecoverage_html }}
300-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).statictyping_html }}
301-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).documentation_html }}
302-
${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).documentation_latex }}
303-
${{ fromJson(needs.PlatformTestingParams.outputs.artifact_names).unittesting_xml }}-*
304-
${{ fromJson(needs.PlatformTestingParams.outputs.artifact_names).unittesting_html }}-*
305-
${{ fromJson(needs.PlatformTestingParams.outputs.artifact_names).codecoverage_xml }}-*
306-
${{ fromJson(needs.PlatformTestingParams.outputs.artifact_names).codecoverage_json }}-*
307-
${{ fromJson(needs.PlatformTestingParams.outputs.artifact_names).codecoverage_html }}-*
289+
json: ${{ needs.UnitTestingParams.outputs.artifact_names }}
290+
artifact-json-ids: <|
291+
package_all
292+
unittesting_xml:-*
293+
unittesting_html:-*
294+
codecoverage_xml:-*
295+
codecoverage_json:-*
296+
codecoverage_html:-*
297+
unittesting_xml
298+
unittesting_html
299+
codecoverage_sqlite
300+
codecoverage_xml
301+
codecoverage_json
302+
codecoverage_html
303+
statictyping_html
304+
documentation_html
305+
documentation_latex
306+
json2: ${{ needs.PlatformTestingParams.outputs.artifact_names }}
307+
artifact-json-ids2: <|
308+
unittesting_xml:-*
309+
unittesting_html:-*
310+
codecoverage_xml:-*
311+
codecoverage_json:-*
312+
codecoverage_html:-*

0 commit comments

Comments
 (0)