Build daily LLVM snapshots on Copr #722
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: | |
runs-on: ubuntu-latest | |
container: fedora:38 | |
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 | |
- uses: actions/checkout@v3 | |
- name: "Variables and functions" | |
shell: bash -e {0} | |
run: | | |
source github/functions.sh | |
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=$username/llvm-snapshots-incubator-$today" >> $GITHUB_ENV | |
echo "project_yesterday=$username/llvm-snapshots-incubator-$yesterday" >> $GITHUB_ENV | |
echo "project_target=$username/llvm-snapshots" >> $GITHUB_ENV | |
- name: "Check for Copr projects existence (yesterday, today, target)" | |
shell: bash -e {0} | |
run: | | |
source github/functions.sh | |
# 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 github/functions.sh | |
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 github/functions.sh | |
copr delete ${{ env.project_today }} | |
- name: "Create today's Copr project: ${{ env.project_today }}" | |
shell: bash -e {0} | |
run: | | |
source github/functions.sh | |
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/fedora-\$releasever-\$basearch" \ | |
--multilib on \ | |
--appstream off \ | |
--delete-after-days 32 \ | |
$chroot_opts "${{ env.project_today }}" | |
- name: "Create today's packages: ${{ env.packages }}" | |
shell: bash -e {0} | |
run: | | |
source github/functions.sh | |
for pkg in ${{ env.packages }}; do | |
copr add-package-scm \ | |
--clone-url https://src.fedoraproject.org/rpms/${pkg}.git \ | |
--commit upstream-snapshot \ | |
--spec ${pkg}.spec \ | |
--type git \ | |
--method make_srpm \ | |
--name ${pkg} \ | |
"${{ env.project_today }}" | |
done | |
- name: "Build llvm-snapshot-builder from SRPM into today's project: ${{ env.project_today }}" | |
shell: bash -e {0} | |
run: | | |
source github/functions.sh | |
make -C llvm-snapshot-builder/ srpm | |
copr build \ | |
"${{ env.project_today }}" \ | |
llvm-snapshot-builder/tmp/SRPMS/llvm-snapshot-builder-*.rpm \ | |
- name: "Build packages in chroot batches in this order: ${{ env.packages }}" | |
shell: bash -e {0} | |
run: | | |
source github/functions.sh | |
for chroot in ${{ env.chroots }}; do | |
# Modify chroot to know about compat package repo and about the --with=snapshot_build option | |
copr edit-chroot \ | |
--repos "https://download.copr.fedorainfracloud.org/results/%40fedora-llvm-team/llvm-compat-packages/${chroot}/" \ | |
--rpmbuild-with "snapshot_build" \ | |
--packages "llvm-snapshot-builder" \ | |
${{ env.project_today }}/$chroot | |
# Start a new batch | |
after_build_id="" | |
for pkg in ${{ env.packages }}; do | |
if ! is_package_supported_by_chroot "${pkg}" "${chroot}"; then | |
echo "Skipping ${pkg} for s390x architecture in 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 }} |