Build daily LLVM snapshots on Copr #1074
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
name: "Build daily LLVM snapshots on Copr" | |
on: | |
schedule: | |
# Everyday at 00:45am | |
# See https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule | |
- cron: "45 0 * * *" | |
workflow_dispatch: {} | |
jobs: | |
build-on-copr: | |
strategy: | |
fail-fast: false | |
matrix: | |
name: [big-merge, pgo] | |
include: | |
- name: big-merge | |
copr_project_tpl: "@fedora-llvm-team/llvm-snapshots-big-merge-YYYYMMDD" | |
copr_target_project: "@fedora-llvm-team/llvm-snapshots" | |
clone_url_tpl: "https://src.fedoraproject.org/rpms/PKG.git" | |
clone_ref: rawhide | |
- name: pgo | |
copr_project_tpl: "@fedora-llvm-team/llvm-snapshots-pgo-YYYYMMDD" | |
copr_target_project: "@fedora-llvm-team/llvm-snapshots-pgo" | |
extra_script_file: "scripts/functions-pgo.sh" | |
clone_url_tpl: "https://src.fedoraproject.org/forks/kkleine/rpms/PKG.git" | |
clone_ref: pgo | |
runs-on: ubuntu-latest | |
container: fedora:39 | |
steps: | |
- name: Setup Copr config file | |
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 | |
run: | | |
dnf install -y copr-cli make bzip2 rpm-build pcre2-tools jq | |
- uses: actions/checkout@v4 | |
- name: "Variables and functions" | |
shell: bash -e {0} | |
run: | | |
source scripts/functions.sh | |
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }} | |
today=`date +%Y%m%d` | |
yesterday=`date -d "${today} -1 day" +%Y%m%d` | |
packages="`get_packages`" | |
chroots="`get_chroots`" | |
username=@fedora-llvm-team | |
echo "username=$username" >> $GITHUB_ENV | |
echo "packages=$packages" >> $GITHUB_ENV | |
echo "chroots=$chroots" >> $GITHUB_ENV | |
echo "all_chroots=$all_chroots" >> $GITHUB_ENV | |
echo "project_today=${{ matrix.copr_project_tpl }}" | sed "s/YYYYMMDD/$today/" >> $GITHUB_ENV | |
echo "project_yesterday=${{ matrix.copr_project_tpl }}" | sed "s/YYYYMMDD/$yesterday/" >> $GITHUB_ENV | |
echo "project_target=${{ matrix.copr_target_project }}" >> $GITHUB_ENV | |
- name: "Check for Copr projects existence (yesterday, today, target)" | |
shell: bash -e {0} | |
run: | | |
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 ! has_all_good_builds ${{env.project_yesterday}}; 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' }} | |
shell: bash -e {0} | |
run: | | |
source scripts/functions.sh | |
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }} | |
build_ids="" | |
for build_id in `get_active_build_ids ${{ env.project_today }}`; do | |
echo "Canceling build with ID $build_id" | |
copr cancel $build_id | |
build_ids="$build_ids $build_id" | |
done | |
if [[ "$build_ids" != "" ]]; then | |
echo "Waiting for build IDs to be canceled: $build_ids" | |
copr watch-build $build_ids || true | |
fi | |
- name: "Deleting today's Copr project before recreating it: ${{ env.project_today }}" | |
if: ${{ env.todays_project_exists == 'true' }} | |
shell: bash -e {0} | |
run: | | |
source scripts/functions.sh | |
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }} | |
copr delete ${{ env.project_today }} | |
- name: "Create today's Copr project: ${{ env.project_today }}" | |
shell: bash -e {0} | |
run: | | |
source scripts/functions.sh | |
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }} | |
chroot_opts=`for c in ${{ env.chroots }}; do echo -n " --chroot $c "; done` | |
copr create \ | |
--instructions "`cat project-instructions.md`" \ | |
--description "`cat project-description.md`" \ | |
--unlisted-on-hp on \ | |
--enable-net on \ | |
--runtime-repo-dependency "https://download.copr.fedorainfracloud.org/results/%40fedora-llvm-team/llvm-compat-packages/\$distname-\$releasever-\$basearch" \ | |
--multilib on \ | |
--appstream off \ | |
--delete-after-days 32 \ | |
--module-hotfixes on \ | |
$chroot_opts "${{ env.project_today }}" | |
- name: "Enable snapshot_build build condition for all and swig:4.0 module in RHEL 8 build chroots (if any)" | |
shell: bash -e {0} | |
run: | | |
source scripts/functions.sh | |
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }} | |
for chroot in ${{ env.chroots }}; do | |
copr edit-chroot --rpmbuild-with "snapshot_build" ${{ env.project_today }}/$chroot | |
if [[ "$chroot" == rhel-8-* ]]; then | |
copr edit-chroot --modules "swig:4.0" ${{ env.project_today }}/$chroot | |
fi | |
done | |
- name: "Create today's packages: ${{ env.packages }}" | |
shell: bash -e {0} | |
run: | | |
source scripts/functions.sh | |
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }} | |
for pkg in ${{ env.packages }}; do | |
clone_url=`echo "${{ matrix.clone_url_tpl }}" | sed "s/PKG/$pkg/"` | |
copr add-package-scm \ | |
--clone-url ${clone_url} \ | |
--commit ${{ matrix.clone_ref }} \ | |
--spec ${pkg}.spec \ | |
--type git \ | |
--method make_srpm \ | |
--name ${pkg} \ | |
"${{ env.project_today }}" | |
done | |
- name: "Build packages in chroot batches in this order: ${{ env.packages }}" | |
shell: bash -e {0} | |
run: | | |
source scripts/functions.sh | |
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }} | |
for chroot in ${{ env.chroots }}; do | |
# Start a new batch | |
after_build_id="" | |
for pkg in ${{ env.packages }}; do | |
if ! is_package_supported_by_chroot "${pkg}" "${chroot}"; then | |
echo "Package '${pkg}' is not supported by chroot: ${chroot}"; | |
else | |
copr build-package \ | |
--timeout $((30*3600)) \ | |
--nowait \ | |
--name $pkg ${after_build_id} \ | |
--chroot ${chroot} \ | |
${{ env.project_today }} \ | |
| tee ${pkg}.log | |
after_build_id="--after-build-id `cat ${pkg}.log | grep -Po 'Created builds: \K(\d+)'`" | |
fi | |
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 }} |