-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Use a Python script to query the GitHub API to determine `bas…
…e` and `head`" This reverts commit 7bf64ee.
- Loading branch information
Showing
1 changed file
with
24 additions
and
54 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 |
---|---|---|
|
@@ -28,61 +28,31 @@ jobs: | |
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Create container name | ||
id: create-container-info | ||
shell: python -u {0} | ||
run: | | ||
import os | ||
import json | ||
import pathlib | ||
import subprocess | ||
import urllib.request | ||
GITHUB_OUTPUT = pathlib.Path(os.environ["GITHUB_OUTPUT"]) | ||
TAG_NAME = "${{ hashFiles('Dockerfile') }}" | ||
req = urllib.request.Request( | ||
url=f"https://api.github.com/repos/{os.environ['REPOSITORY']}", | ||
headers={ | ||
"Authorization": "token ${{ secrets.GITHUB_TOKEN }}", | ||
"Accept": "application/vnd.github.v3+json", | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
} | ||
) | ||
with urllib.request.urlopen(req) as response: | ||
assert response.status == 200 | ||
data = json.loads(response.read().decode()) | ||
head_image = data["full_name"].lower() | ||
if data["parent"]: | ||
base_image = data["parent"]["full_name"].lower() | ||
else: | ||
base_image = head_image | ||
image_name = head_image | ||
build = True | ||
for image in {base_image, head_image}: | ||
try: | ||
subprocess.run([ | ||
"docker", "manifest", "inspect", | ||
f"{os.environ['REGISTRY']}/{image}:{TAG_NAME}" | ||
], check=True) | ||
except subprocess.CalledProcessError: | ||
continue | ||
else: | ||
image_name = image | ||
build = False | ||
break | ||
with GITHUB_OUTPUT.open("a") as f: | ||
f.writelines([ | ||
f"build={build}\n", | ||
f"tag_name={TAG_NAME}\n", | ||
f"image_name={image_name}\n", | ||
f"container_name={os.environ['REGISTRY']}/{image_name}:{TAG_NAME}\n", | ||
]) | ||
base_image=$(echo ${{ github.event.pull_request.base.repo.full_name }} | tr [:upper:] [:lower:]) | ||
head_image=$(echo ${{ github.event.pull_request.head.repo.full_name }} | tr [:upper:] [:lower:]) | ||
tag_name="${{ hashFiles('Dockerfile') }}" | ||
# Default to building a new container under the original repo | ||
image_name=$head_image | ||
build=true | ||
# Check if we can use the base image (Nabu Casa) | ||
if docker manifest inspect ${{ env.REGISTRY }}/$base_image:$tag_name; then | ||
image_name=$base_image | ||
build=false | ||
fi | ||
# Check if we can use the head image (PR) | ||
if docker manifest inspect ${{ env.REGISTRY }}/$head_image:$tag_name; then | ||
image_name=$head_image | ||
build=false | ||
fi | ||
echo "build=$build" >> $GITHUB_OUTPUT | ||
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT | ||
echo "image_name=$image_name" >> $GITHUB_OUTPUT | ||
echo "container_name=${{ env.REGISTRY }}/$image_name:$tag_name" >> $GITHUB_OUTPUT | ||
- name: Set up Docker Buildx | ||
uses: docker/[email protected] | ||
if: steps.create-container-info.outputs.build == 'true' | ||
|