From f7706428a2d8b0549aced336f05e42bf84301010 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 28 Sep 2022 15:09:53 +0200 Subject: [PATCH 1/2] Make release only if we are running the workflow on a `r_xx` tag. Also check that we are not a scheduled workflow (But it is more a double check. This shloud not happen) --- .github/scripts/build_release_nightly.py | 25 ++++++++++-------------- .github/scripts/common.py | 1 + 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/scripts/build_release_nightly.py b/.github/scripts/build_release_nightly.py index ab5adc5..5907ac8 100755 --- a/.github/scripts/build_release_nightly.py +++ b/.github/scripts/build_release_nightly.py @@ -18,15 +18,10 @@ from common import ( OS_NAME, PLATFORM_TARGET, DESKTOP, + MAKE_RELEASE, notarize_macos_build, ) - -if os.environ.get('GITHUB_EVENT_NAME') == 'schedule': - RELEASE = False -else: - RELEASE = True - if PLATFORM_TARGET.startswith("android_") or PLATFORM_TARGET.startswith("iOS"): TARGETS = ("libzim", "libkiwix") elif PLATFORM_TARGET.startswith("native_"): @@ -47,34 +42,34 @@ else: TARGETS = ("libzim", "zim-tools", "libkiwix", "kiwix-tools") # Filter what to build if we are doing a release. -if RELEASE: +if MAKE_RELEASE: def release_filter(project): return release_versions.get(project) is not None TARGETS = tuple(filter(release_filter, TARGETS)) for target in TARGETS: - run_kiwix_build(target, platform=PLATFORM_TARGET, make_release=RELEASE) + run_kiwix_build(target, platform=PLATFORM_TARGET, make_release=MAKE_RELEASE) if target == "kiwix-desktop": - archive = create_desktop_image(make_release=RELEASE) + archive = create_desktop_image(make_release=MAKE_RELEASE) else: if PLATFORM_TARGET == "native_mixed" and OS_NAME == "osx": fix_macos_rpath(target) notarize_macos_build(target) - archive = make_archive(target, make_release=RELEASE) + archive = make_archive(target, make_release=MAKE_RELEASE) if archive: - upload_archive(archive, target, make_release=RELEASE) - if RELEASE and target in ("zim-tools", "kiwix-tools"): + upload_archive(archive, target, make_release=MAKE_RELEASE) + if MAKE_RELEASE and target in ("zim-tools", "kiwix-tools"): trigger_docker_publish(target) # We have few more things to do for release: -if RELEASE: +if MAKE_RELEASE: # Publish source archives if PLATFORM_TARGET in ("native_dyn", "native_mixed") and OS_NAME != "osx": for target in TARGETS: if release_versions.get(target) != 0: continue run_kiwix_build( - target, platform=PLATFORM_TARGET, make_release=RELEASE, make_dist=True + target, platform=PLATFORM_TARGET, make_release=MAKE_RELEASE, make_dist=True ) full_target_name = "{}-{}".format(target, main_project_versions[target]) if target == "kiwix-desktop": @@ -88,7 +83,7 @@ if RELEASE: / "meson-dist" / "{}.tar.xz".format(full_target_name) ) - upload_archive(archive, target, make_release=RELEASE) + upload_archive(archive, target, make_release=MAKE_RELEASE) # Publish flathub if PLATFORM_TARGET == "flatpak" and "kiwix-desktop" in TARGETS: diff --git a/.github/scripts/common.py b/.github/scripts/common.py index 404194f..d41b30d 100644 --- a/.github/scripts/common.py +++ b/.github/scripts/common.py @@ -37,6 +37,7 @@ KIWIX_DESKTOP_ONLY = False _ref = _environ.get("GITHUB_REF", "").split("/")[-1] MAKE_RELEASE = re.fullmatch(r"r_[0-9]+", _ref) is not None +MAKE_RELEASE = MAKE_RELEASE and (_environ.get('GITHUB_EVENT_NAME') != 'schedule') RELEASE_OS_NAME = "macos" if OS_NAME == "osx" else "linux" From dc814c626ddfc10d91abc6e9f45409db17ea25be Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 28 Sep 2022 15:11:08 +0200 Subject: [PATCH 2/2] Upload read-only archive. By uploading read-only archive, we prevent potential (implicit) re-upload. A re-upload will always be possible if we remove the archive and rerun the workflow. But it will be clearly explicit in this case. --- .github/scripts/common.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/scripts/common.py b/.github/scripts/common.py index d41b30d..1f9d307 100644 --- a/.github/scripts/common.py +++ b/.github/scripts/common.py @@ -226,7 +226,7 @@ def upload(file_to_upload, host, dest_path): command = [ "scp", - "-r", + "-rp", "-P", port, "-i", @@ -241,6 +241,10 @@ def upload(file_to_upload, host, dest_path): def upload_archive(archive, project, make_release): + if not archive.exists(): + print_message("No archive {} to upload!", archive) + return + if project.startswith("kiwix-") or project in ['libkiwix']: host = "ci@master.download.kiwix.org:30022" dest_path = "/data/download/" @@ -253,6 +257,10 @@ def upload_archive(archive, project, make_release): else: dest_path = dest_path + "nightly/" + DATE + # Make the archive read only. This way, scp will preserve rights. + # If somehow we try to upload twice the same archive, scp will fails. + archive.chmod(0o444) + upload(archive, host, dest_path)