Skip to content

Commit

Permalink
Outsource snapshot promotion into encapsulated composite action
Browse files Browse the repository at this point in the history
This is related to #59 because it allows us to call the snapshot
promotion from different places in the workflow more easily.
  • Loading branch information
kwk committed Feb 5, 2024
1 parent 19a1c9e commit dc2148e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 33 deletions.
86 changes: 86 additions & 0 deletions .github/actions/promote-snapshot/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# See https://docs.github.com/en/actions/creating-actions/creating-a-composite-action#creating-an-action-metadata-file

name: "Promote snapshot"
description: "Promote snapshot from source to target"
inputs:
checkout-path:
description: "Where this project was checked out"
required: false
default: "."
project-source:
description: The copr source project to be promoted
required: true
project-target:
description: The copr target project that the source project will be promoted to
required: true
source-project-needs-llvm-snapshot-builder:
description: Whether the source project needs the llvm-snapshot-builder package.
required: true
copr-config:
description: "The secret copr configuration found here https://copr.fedorainfracloud.org/api/"
required: true
runs:
using: "composite"
steps:
- name: Setup Copr config file
shell: bash -e {0}
env:
# You need to have those secrets in your repo.
# See also: https://copr.fedorainfracloud.org/api/.
COPR_CONFIG_FILE: ${{ secrets.copr-config }}
run: |
mkdir -p ~/.config
printf "$COPR_CONFIG_FILE" > ~/.config/copr
- name: Install Copr CLI and required tools
shell: bash -e {0}
run: |
dnf install -y copr-cli make bzip2 rpm-build pcre2-tools jq
- uses: actions/checkout@v4
- name: "Check if source project exists and all builds succeeded"
shell: bash -e {0}
run: |
source ${{ inputs.checkout-path }}/scripts/functions.sh
# Check if source project exists and all builds succeeded
if [ ! copr_project_exists ${{ inputs.project_source }} ]; then
>&2 echo "The source project ${{ inputs.project_source }} does not exist. Aborting promotion."
exit 111;
fi
if [ ${{ inputs.source_project_needs_llvm_snapshot_builder }} ]; then
extra_packages=llvm-snapshot-builder
fi
if [ ! has_all_good_builds ${{inputs.project_source}} $extra_packages ]; then
>&2 echo "The source project ${{ inputs.project_source }} contains broken builds. Aborting promotion."
exit 222;
fi
- name: "Delete target Copr project at ${{ inputs.project_target }} (if it exists) before forking to it"
if: success()
shell: bash -e {0}
run: |
if [ ! copr_project_exists ${{ inputs.project_target }} ]; then
>&2 echo "The target project ${{ inputs.project_source }} does not exist yet. No need to delete it."
exit 0
fi
copr delete "${{ inputs.project_target }}"
# Give Copr some time to process the deletion, to avoid race conditions with forking.
# TODO: Keep and eye on https://github.com/fedora-copr/copr/issues/2698 if there's a better way to handle this.
# TODO(kwk): The issue above is closed. We should add try without the sleep sometime.
sleep 1m
- name: "Fork Copr project from ${{ inputs.project_source }} to ${{ inputs.project_target }}"
if: success()
shell: bash -e {0}
run: |
copr fork --confirm ${{ inputs.project_source }} ${{ inputs.project_target }}
# Ensure the target project is not hidden from the Homepage and ensure
# it won't be automatically deleted like the incubator projects.
copr modify --delete-after-days -1 --unlisted-on-hp off ${{ inputs.project_target }}
- name: "Regenerate repositories for target project ${{ inputs.project_target }}"
if: success()
shell: bash -e {0}
run: |
copr regenerate-repos ${{ inputs.project_target }}
40 changes: 7 additions & 33 deletions .github/workflows/fedora-copr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,7 @@ jobs:
source scripts/functions.sh
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }}
# Check if yesterday's project exists and all builds succeeded
yesterdays_project_exists=`project_exists ${{ env.project_yesterday }}`
if [[ "$yesterdays_project_exists" == "true" ]]; then
if [ "${{ matrix.needs_llvm_snapshot_builder }}" == "true" ]; then
extra_packages=llvm-snapshot-builder
fi
if ! has_all_good_builds ${{env.project_yesterday}} $extra_packages; then
yesterdays_project_exists=false
fi
fi
echo "todays_project_exists=`project_exists ${{ env.project_today }}`" >> $GITHUB_ENV
echo "yesterdays_project_exists=$yesterdays_project_exists" >> $GITHUB_ENV
echo "target_project_exists=`project_exists ${{ env.project_target }}`" >> $GITHUB_ENV
- name: "Canceling active builds (if any) in today's Copr project before recreating it: ${{ env.project_today }}"
if: ${{ env.todays_project_exists == 'true' }}
Expand Down Expand Up @@ -206,23 +193,10 @@ jobs:
done
done
- name: "Delete target Copr project at ${{ env.project_target }} before forking to it"
if: ${{ env.yesterdays_project_exists == 'true' && env.target_project_exists == 'true' }}
run: |
copr delete "${{ env.project_target }}"
# Give Copr some time to process the deletion, to avoid race conditions with forking.
# TODO: Keep and eye on https://github.com/fedora-copr/copr/issues/2698 if there's a better way to handle this.
sleep 1m
- name: "Fork Copr project from ${{ env.project_yesterday }} to ${{ env.project_target }}"
if: ${{ env.yesterdays_project_exists == 'true' }}
run: |
copr fork --confirm ${{ env.project_yesterday }} ${{ env.project_target }}
copr modify --delete-after-days -1 --unlisted-on-hp off ${{ env.project_target }}
- name: "Regenerate repos for target project ${{ env.project_target }}"
# If yesterday's project didn't exist, we haven't forked and so we don't
# need to regenerate the repos.
if: ${{ env.yesterdays_project_exists == 'true' }}
run: |
copr regenerate-repos ${{ env.project_target }}
- uses: ./.github/actions/promote-snapshot
if: success()
with:
project-source: ${{ env.project_yesterday }}
project-target: ${{ env.project_yesterday }}
source-project-needs-llvm-snapshot-builder: ${{ matrix.needs_llvm_snapshot_builder }}
copr-config: ${{ secrets.COPR_CONFIG }}

0 comments on commit dc2148e

Please sign in to comment.