Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 5e6b32c

Browse files
committed
ci: dffml: build: images: containers: Use create manifest instance action
Signed-off-by: John Andersen <[email protected]>
1 parent 285163a commit 5e6b32c

File tree

1 file changed

+17
-88
lines changed

1 file changed

+17
-88
lines changed

.github/workflows/dffml_build_images_containers.yml

Lines changed: 17 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -13,110 +13,39 @@ on:
1313
- ".github/workflows/build_images_containers.yml"
1414
- ".github/workflows/dffml_build_images_containers.yml"
1515
- "Dockerfile"
16+
- "**/*Dockerfile"
17+
- "**/*.manifest.json"
1618
push:
1719
branches:
1820
- main
1921
paths:
2022
- ".github/workflows/build_images_containers.yml"
2123
- ".github/workflows/dffml_build_images_containers.yml"
2224
- "Dockerfile"
25+
- "**/*Dockerfile"
26+
- "**/*.manifest.json"
2327

2428
jobs:
2529
manifest:
2630
runs-on: ubuntu-latest
2731
outputs:
28-
manifest: ${{ steps.create-manifest-instance.outputs.manifest }}
32+
manifest: ${{ steps.create-manifest-instance.outputs.github_actions_manifest }}
2933
steps:
30-
- name: Set up Python 3.9
31-
uses: actions/setup-python@v2
32-
with:
33-
python-version: 3.9
3434
- uses: actions/checkout@v3
3535
- name: Build manifest from changed dockerfiles
36+
uses: "./.github/actions/create_manifest_instance_build_images_containers"
3637
id: create-manifest-instance
37-
env:
38-
# Must be a valid directory with "*Dockerfile"s in it
39-
PREFIX: ""
40-
ROOT_PATH: "."
41-
OWNER_REPOSITORY: ${{ github.repository }}
42-
BRANCH: ${{ github.ref_name }}
43-
COMPARE_URL: ${{ github.event.repository.compare_url }}
44-
GH_ACCESS_TOKEN: ${{ github.token }}
45-
HEAD: ${{ github.event.after }}
46-
BASE: ${{ github.event.before }}
47-
BASE_REF: ${{ github.base_ref }}
48-
shell: python -u {0}
49-
run: |
50-
import os
51-
import json
52-
import pathlib
53-
import urllib.request
54-
owner, repository = os.environ["OWNER_REPOSITORY"].split("/", maxsplit=1)
55-
base = None
56-
env_vars = ["BASE", "BASE_REF"]
57-
for env_var in env_vars:
58-
if env_var in os.environ and os.environ[env_var].strip():
59-
# Set if present and not blank
60-
base = os.environ[env_var]
61-
# Empty manifest (list of manifests for each build file) in case not triggered
62-
# from on file change (workflow changed or dispatched).
63-
manifest = []
64-
# Path to root of repo
65-
root_path = pathlib.Path(os.environ["ROOT_PATH"])
66-
# Must be a valid directory with .Dockerfiles in it
67-
prefix_path = pathlib.Path(os.environ["PREFIX"])
68-
# Grab most recent commit to use by default
69-
commit = pathlib.Path(
70-
".git", pathlib.Path(".git", "HEAD").read_text().split()[-1],
71-
).read_text()
72-
if base is None:
73-
print(f"::notice file=dffml_build_images_containers.yml,line=1,endLine=1,title=nobase::None of {env_vars!r} found in os.environ")
74-
else:
75-
compare_url = os.environ["COMPARE_URL"]
76-
compare_url = compare_url.replace("{base}", base)
77-
compare_url = compare_url.replace("{head}", os.environ["HEAD"])
78-
with urllib.request.urlopen(
79-
urllib.request.Request(
80-
compare_url,
81-
headers={
82-
"Authorization": "bearer " + os.environ["GH_ACCESS_TOKEN"],
83-
},
84-
)
85-
) as response:
86-
response_json = json.load(response)
87-
# Build the most recent commit
88-
commit = response_json["commits"][-1]["sha"]
89-
manifest = list([
90-
{
91-
"image_name": pathlib.Path(compare_file["filename"]).stem,
92-
"dockerfile": compare_file["filename"],
93-
"owner": owner,
94-
"repository": repository,
95-
"branch": os.environ["BRANCH"],
96-
"commit": commit,
97-
}
98-
for compare_file in response_json["files"]
99-
if (
100-
compare_file["filename"].startswith(os.environ["PREFIX"])
101-
and compare_file["filename"].endswith("Dockerfile")
102-
)
103-
])
104-
# Build everything if we aren't sure why we got here (alice changes or
105-
# workflow re-run)
106-
if not manifest:
107-
manifest = list([
108-
{
109-
"image_name": path.stem if path.stem != path.name else (repository if str(path.relative_to(root_path)) == path.stem else path.resolve().parent.stem),
110-
"dockerfile": str(path.relative_to(root_path)),
111-
"owner": owner,
112-
"repository": repository,
113-
"branch": os.environ["BRANCH"],
114-
"commit": commit,
115-
}
116-
for path in prefix_path.glob("*Dockerfile")
117-
])
118-
print(json.dumps(manifest, sort_keys=True, indent=4))
119-
print("::set-output name=manifest::" + json.dumps({"include": manifest}))
38+
with:
39+
root_path: "."
40+
owner_repository: ${{ github.repository }}
41+
branch: ${{ github.ref_name }}
42+
compare_url: ${{ github.event.repository.compare_url }}
43+
gh_access_token: ${{ github.token }}
44+
head: ${{ github.event.after }}
45+
base: ${{ github.event.before }}
46+
base_ref: ${{ github.base_ref }}
47+
prefix: '[".", "scripts", "dffml/skel/operations"]'
48+
no_delta_prefix: '["."]'
12049

12150
build:
12251
needs: manifest

0 commit comments

Comments
 (0)