Skip to content

Commit

Permalink
Merge pull request #38 from Luap99/image-ref
Browse files Browse the repository at this point in the history
Patch the image ref in the VM to point to the right container image and post image urls in PR comments
openshift-merge-bot[bot] authored Nov 14, 2024
2 parents d9beef6 + 266214d commit c56397b
Showing 3 changed files with 102 additions and 1 deletion.
78 changes: 78 additions & 0 deletions .github/workflows/pr_image_links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---

# Use the latest published version of the cirrus-ci_retrospective container
# to determine the execution context of _this_ workflow run. If it is a
# pull request, post the artifact URLs so it is easy to download and test.

on:
check_suite: # ALWAYS triggered from the default branch
# Ref: https://help.github.com/en/actions/reference/events-that-trigger-workflows#check-suite-event-check_suite
types:
- completed

jobs:
comment_image_id:
# Do not execute for other github applications, only works with cirrus-ci
if: github.event.check_suite.app.name == 'Cirrus CI'
runs-on: ubuntu-latest
env:
# This is the last component of the gist URL
# i.e. https://gist.github.com/<user>/<id>
built_images_gist_id: f505b6fb78db279855862e035629f8aa
steps:
- name: Execute latest upstream cirrus-ci_retrospective
uses: docker://quay.io/libpod/cirrus-ci_retrospective:latest
env:
GITHUB_TOKEN: ${{ github.token }}
# Writes $GITHUB_WORKSPACE/cirrus-ci_retrospective.json

- name: Debug cirrus-ci_retrospective JSON
run: jq --indent 4 --color-output . $GITHUB_WORKSPACE/cirrus-ci_retrospective.json

- name: Load JSON into github workflow output variables
id: retro
run: |
ccirjson=$GITHUB_WORKSPACE/cirrus-ci_retrospective.json
prn=$(jq --raw-output \
'.[] | select(.name == "'success'") | .build.pullRequest' \
"$ccirjson")
bid=$(jq --raw-output \
'.[] | select(.name == "'success'") | .build.id' \
"$ccirjson")
status=$(jq --raw-output \
'.[] | select(.name == "'success'") | .status' \
"$ccirjson")
if [[ -n "$prn" ]] && \
[[ "$prn" != "null" ]] && \
[[ $prn -gt 0 ]] && \
[[ "$status" == "COMPLETED" ]]
then
printf "prn=%s\n" "$prn" >> $GITHUB_OUTPUT
printf "bid=%s\n" "$bid" >> $GITHUB_OUTPUT
printf "is_pr=%s\n" "true" >> $GITHUB_OUTPUT
else
printf "prn=%s\n" "0" >> $GITHUB_OUTPUT
printf "bid=%s\n" "0" >> $GITHUB_OUTPUT
printf "is_pr=%s\n" "false" >> $GITHUB_OUTPUT
fi
- if: steps.retro.outputs.is_pr == 'true'
uses: actions/checkout@v4
with:
persist-credentials: false

- if: steps.retro.outputs.is_pr == 'true'
name: Print Artifacts output
id: artifact_output
run: ./contrib/cirrus/print-artifacts-urls.sh "${{ steps.retro.outputs.bid }}"

- if: steps.retro.outputs.is_pr == 'true'
name: Count the number of manifest.json files downloaded
uses: thollander/actions-comment-pull-request@v3
with:
pr-number: ${{ steps.retro.outputs.prn }}
# the tag causes it to replace the comment
comment-tag: artifacts
mode: recreate
message: ${{ steps.artifact_output.outputs.stdout }}
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ echo "Preparing to build ${FULL_IMAGE_NAME}"

if [[ ! -d "build-podman-machine-os-disks" ]]; then
git clone https://github.com/dustymabe/build-podman-machine-os-disks
sed -i -e 's|fedora:quay.io/containers.*"|fedora:quay.io/podman/machine-os:${PODMAN_VERSION%.*}"|' build-podman-machine-os-disks/build-podman-machine-os-disks.sh
fi

echo " Building image locally"
@@ -28,7 +29,7 @@ mkdir -p $OUTDIR
podman save --format oci-archive -o "${OUTDIR}/${DISK_IMAGE_NAME}" "${FULL_IMAGE_NAME_ARCH}"

echo "Transforming OCI image into disk image"
pushd $OUTDIR && sudo sh $SRCDIR/build-podman-machine-os-disks/build-podman-machine-os-disks.sh "${PWD}/${DISK_IMAGE_NAME}"
pushd $OUTDIR && sh $SRCDIR/build-podman-machine-os-disks/build-podman-machine-os-disks.sh "${PWD}/${DISK_IMAGE_NAME}"

echo "Compressing disk images with zstd"
# note: we are still "in" the outdir at this point
22 changes: 22 additions & 0 deletions contrib/cirrus/print-artifacts-urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

CIRRUS_BUILD_ID=$1

if [[ -z "$CIRRUS_BUILD_ID" ]]; then
echo "Requires cirrus build as first argument" 1>&2
exit 1
fi

echo "Image Downloads for id ${CIRRUS_BUILD_ID}:"
echo
echo "| Name | URL |"
echo "| --- | --- |"

for arch in x86_64 aarch64; do
for end in applehv.raw.zst hyperv.vhdx.zst qemu.qcow2.zst tar; do
name="podman-machine.$arch.$end"
echo "| $name | https://api.cirrus-ci.com/v1/artifact/build/${CIRRUS_BUILD_ID}/image_build/image/$name |"
done
done

echo "| Everything zip | https://api.cirrus-ci.com/v1/artifact/build/${CIRRUS_BUILD_ID}/image.zip |"

0 comments on commit c56397b

Please sign in to comment.