-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(maint) - Extract raw python to scripts
- Loading branch information
1 parent
9948a76
commit dbf6b34
Showing
4 changed files
with
82 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
import os | ||
import re | ||
import subprocess | ||
|
||
re_image = re_dockerfile = '' | ||
changed_files = json.loads(os.environ['CHANGED_FILES']) | ||
with open('images.json') as fd: | ||
builds = json.load(fd) | ||
|
||
dockerfiles = list(map(lambda v: v.removesuffix('.dockerfile'), filter(lambda v: re.match('.*dockerfile$', v), changed_files))) | ||
if len(dockerfiles) > 0: | ||
re_dockerfile = '|'.join(dockerfiles) | ||
|
||
if 'images.json' in changed_files: | ||
try: | ||
data = subprocess.run(['git', 'show', 'HEAD^:images.json'], stdout=subprocess.PIPE).stdout.decode('utf-8') | ||
images = json.loads(data) | ||
with open('images.json', 'r') as fd: | ||
new_images = json.load(fd) | ||
diff = list(filter(lambda v: v not in images, new_images)) | ||
if len(diff) > 0: | ||
re_image = '|'.join(map(lambda v: f"{v['image']}:{v['tag']}", diff)) | ||
except json.decoder.JSONDecodeError: | ||
re_image = '.*' | ||
|
||
with open(os.environ['GITHUB_OUTPUT'], 'a') as output: | ||
if re_dockerfile == re_image: | ||
print('do_build=false', file=output) | ||
print('::notice title=::no image build changes detected') | ||
else: | ||
print('do_build=true', file=output) | ||
print(f're_dockerfile=({re_dockerfile})', file=output) | ||
print(f're_image=({re_image})', file=output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
import os | ||
from re import match | ||
|
||
# parse workflow inputs | ||
image = os.environ['image'] | ||
dockerfile = os.environ['dockerfile'] | ||
refresh = True if os.environ['refresh'] == "true" else False | ||
|
||
# output | ||
matrix = [] | ||
|
||
# load matrix json | ||
with open('images.json') as fd: | ||
builds = json.load(fd) | ||
for i, v in enumerate(builds): | ||
builds[i]['image_tag'] = f"{v['image']}:{v['tag']}" | ||
builds[i]['base_image_tag'] = f"{v['base_image']}:{v['base_tag']}" | ||
builds[i]['refresh'] = refresh | ||
|
||
if dockerfile: | ||
dockerfile = f"^{dockerfile}$" | ||
for _, v in enumerate(builds): | ||
if match(dockerfile, v['dockerfile']): | ||
# always refresh | ||
v['refresh'] = True | ||
matrix.append(v) | ||
|
||
if image: | ||
image = f"^{image}$" if image else image | ||
for _, v in enumerate(builds): | ||
if match(image, v['image_tag']): | ||
matrix.append(v) | ||
|
||
# unique list of images | ||
matrix = list({v['image_tag']:v for v in matrix}.values()) | ||
|
||
if len(matrix) == 0: | ||
print("::error title::failed to build matrix, no images matched?") | ||
raise SystemExit(1) | ||
|
||
with open(os.environ['GITHUB_OUTPUT'], 'a') as output: | ||
print('matrix=' + json.dumps({ 'include': matrix }), file=output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters