forked from openstack-snaps/ubuntu-openstack-rocks
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add image rebuild workflow for tempest rock.
- Loading branch information
1 parent
fcda604
commit 5ae6523
Showing
2 changed files
with
127 additions
and
0 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,81 @@ | ||
name: Check and Rebuild Tempest Image | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
branch: | ||
description: The branch to run checks on and re-build images from | ||
type: string | ||
required: true | ||
|
||
jobs: | ||
check-update: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
rebuild_image: ${{ steps.check.outputs.rebuild_image }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.branch }} | ||
- name: Install yq | ||
run: | | ||
sudo snap install yq | ||
- name: Check if a recent snap updates is found | ||
id: check | ||
env: | ||
TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# get the snap name and its channel that the ROCK image should track | ||
snap=$(yq '.parts.[].stage-snaps.[]' rocks/tempest/rockcraft.yaml) | ||
IFS='/' read -r name channel <<< "$snap" | ||
echo "snap: $name, channel: $channel" | ||
image_version=$(yq '.version' rocks/tempest/rockcraft.yaml) | ||
echo "image version: $image_version" | ||
# parse date of the last release and reformat it to seconds | ||
format='+%s' | ||
snap_update_date=$(snap info $name | grep $channel | awk '{ print $3 }') | ||
echo "last update date for snap $name in $channel: $snap_update_date" | ||
snap_update_date_in_seconds=$(date -d "$snap_update_date" "$format") | ||
# confirm the validity of the snap release date | ||
if [[ "$?" != 0 ]]; then | ||
echo "$snap_update_date is not a valid date." | ||
exit 1 | ||
fi | ||
# get the last image update date and reformat it to seconds | ||
image_update_date=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/canonical/packages/container/tempest/versions | yq '.[] | select(.metadata.container.tags[0]==$image_version) | .updated_at') | ||
echo "last update date for image tempest tag $image_version: $image_update_date" | ||
# exit unsuccessfully if the image tag is not found in registry (to be safe we only update image with exiting tags) | ||
if [[ -z "$image_update_date" ]]; then | ||
echo "Tempest image with tag '$image_version' not found in registry." | ||
exit 1 | ||
fi | ||
image_update_date_in_seconds=$(date -d "$image_update_date" "$format") | ||
# confirm the validity of the image release date | ||
if [[ "$?" != 0 ]]; then | ||
echo "$image_update_date is not a valid date." | ||
exit 1 | ||
fi | ||
# re-build and publish image if the image update date is earlier than snap update date | ||
if [ "$image_update_date_in_seconds" -lt "$snap_update_date_in_seconds" ]; then | ||
echo "A recent snap release is found. Will re-build and publish a new image." | ||
echo "rebuild_image=1" >> $GITHUB_OUTPUT | ||
else | ||
echo "No new snap releases detected." | ||
echo "rebuild_image=0" >> $GITHUB_OUTPUT | ||
fi | ||
build-and-publish: | ||
needs: check-update | ||
if: ${{ needs.check-update.outputs.rebuild_image == 1 }} | ||
uses: ./.github/workflows/build_publish.yaml | ||
with: | ||
rocks: '["tempest"]' | ||
branch: ${{ inputs.branch }} | ||
publish: true |
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,46 @@ | ||
name: Update Tempest Releases | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '12 1 * * 1,4' # run workflow at 1:12 (an arbitrary time) every Mon and Thu | ||
|
||
jobs: | ||
get_release_branches: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
branches: ${{ steps.get-branches.outputs.branches }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install jq | ||
run: | | ||
sudo apt install jq | ||
- name: Get branches | ||
id: get-branches | ||
run: | | ||
# filter branches prefixed with `stable/*` in remote repo | ||
filtered_branches=$(git branch -a --list "origin/stable/*" --format='%(refname:short)' | sed 's/origin\///') | ||
# add `main` branch as it tracks the latest release in development | ||
branches_array="main" | ||
# create a json list of branches | ||
while IFS= read -r line | ||
do | ||
branches_array+=($line) | ||
done < <(printf '%s\n' "$filtered_branches") | ||
branches_json=$(jq -c -n '$ARGS.positional' --args -- "${branches_array[@]}") | ||
echo $branches_json | ||
echo "branches=$branches_json" >> $GITHUB_OUTPUT | ||
check-update: | ||
needs: get_release_branches | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
branch: ${{ fromJson(needs.get_release_branches.outputs.branches) }} | ||
uses: ./.github/workflows/check_rebuild_tempest.yaml | ||
with: | ||
branch: ${{ matrix.branch }} |