try to fix gitea deploy

This commit is contained in:
Alya Sirko 2022-09-10 15:58:22 +03:00
parent 04f9d2627c
commit f7a08cf146

71
ci.py
View file

@ -16,6 +16,8 @@ APP_BUILD_ID = APP_VERSION_FULL[APP_VERSION_FULL.find("+"):][1::]
HOST_MOUNTED_VOLUME = f"{HOST_HOME}/.local/share/containers/storage/volumes/src/_data" HOST_MOUNTED_VOLUME = f"{HOST_HOME}/.local/share/containers/storage/volumes/src/_data"
# Environments
def podman_offline(dir, *args): def podman_offline(dir, *args):
subprocess.run(["podman", "run", "--rm", "--network=none", f"--workdir={dir}", subprocess.run(["podman", "run", "--rm", "--network=none", f"--workdir={dir}",
"-v", f"src:{CONTAINER_HOME}/src:U", "-v", f"src:{CONTAINER_HOME}/src:U",
@ -33,6 +35,43 @@ def podman_online(dir, *args):
CONTAINER_IMAGE, "bash", "-c", ' '.join(args) CONTAINER_IMAGE, "bash", "-c", ' '.join(args)
]) ])
# Targets
def build_linux():
podman_offline(f"{CONTAINER_HOME}/src", "flutter pub get --offline")
podman_offline(f"{CONTAINER_HOME}/src", "flutter build linux")
def build_apk():
podman_offline(f"{CONTAINER_HOME}/src", "flutter pub get --offline")
podman_offline(f"{CONTAINER_HOME}/src", "flutter build apk")
def sign_apk_standalone():
podman_offline(f"{CONTAINER_HOME}/fdroid",
"zipalign -f -v 4 ../src/build/app/outputs/flutter-apk/app-release.apk",
f"standalone_{APP_NAME}-{APP_SEMVER}.apk")
podman_offline(f"{CONTAINER_HOME}/fdroid",
"apksigner sign --ks standalone-keystore --ks-key-alias standalone --ks-pass",
f"env:STANDALONE_KEYSTORE_PASS standalone_{APP_NAME}-{APP_SEMVER}.apk")
def sign_apk_fdroid():
podman_offline(f"{CONTAINER_HOME}/fdroid", f"rm -rf {CONTAINER_HOME}/fdroid/unsigned/*")
podman_offline(f"{CONTAINER_HOME}/fdroid",
f"test ! -f {CONTAINER_HOME}/fdroid/repo/{APP_NAME}_{APP_BUILD_ID}.apk",
"&& cp ../src/build/app/outputs/flutter-apk/app-release.apk",
f"unsigned/{APP_NAME}_{APP_BUILD_ID}.apk || echo exist")
podman_offline(f"{CONTAINER_HOME}/fdroid", "fdroid publish")
podman_offline(f"{CONTAINER_HOME}/fdroid", "fdroid update")
def package_linux_appimage():
podman_online(f"{CONTAINER_HOME}/src", "appimage-builder --recipe appimage.yml")
def package_linux_flatpak():
podman_online(f"{CONTAINER_HOME}/src", "flatpak-builder --disable-rofiles-fuse --force-clean --repo=flatpak-repo flatpak-build flatpak.yml")
podman_online(f"{CONTAINER_HOME}/src", f"flatpak build-bundle flatpak-repo {APP_NAME}-{APP_SEMVER}.flatpak pro.kherel.selfprivacy")
def package_linux_archive():
podman_online(f"{CONTAINER_HOME}/src", f"tar -C build/linux/x64/release/bundle -vacf {APP_NAME}-{APP_SEMVER}.tar.zstd .")
def deploy_gitea_release(): def deploy_gitea_release():
subprocess.run(["tea", "login", "add", "--token", os.environ.get('GITEA_RELEASE_TOKEN'), subprocess.run(["tea", "login", "add", "--token", os.environ.get('GITEA_RELEASE_TOKEN'),
"--url", "https://git.selfprivacy.org"]) "--url", "https://git.selfprivacy.org"])
@ -47,11 +86,13 @@ def deploy_gitea_release():
def deploy_fdroid_repo(): def deploy_fdroid_repo():
subprocess.run(["eval $(ssh-agent -s)"], shell=True) subprocess.run(["eval $(ssh-agent -s)"], shell=True)
subprocess.run(["printf " + os.environ.get('SSH_PRIVATE_KEY') + " | ssh-add -"], shell=True) subprocess.run(["echo \"$SSH_PRIVATE_KEY\" | tr -d '\r' | ssh-add -"], shell=True)
subprocess.run(["scp", "-oStrictHostKeyChecking=no", "-oUserKnownHostsFile=/dev/null", subprocess.run(["scp", "-oStrictHostKeyChecking=no", "-oUserKnownHostsFile=/dev/null",
"-r", f"{HOST_HOME}/fdroid/repo/*", "-r", f"{HOST_HOME}/fdroid/repo/*",
"deployer@selfprivacy.org:/var/www/fdroid.selfprivacy.org"]) "deployer@selfprivacy.org:/var/www/fdroid.selfprivacy.org"])
# Arguments
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
@ -67,33 +108,19 @@ if __name__ == "__main__":
args = parser.parse_args() args = parser.parse_args()
if args.build_linux: if args.build_linux:
podman_offline(f"{CONTAINER_HOME}/src", "flutter pub get --offline") build_linux()
podman_offline(f"{CONTAINER_HOME}/src", "flutter build linux")
elif args.build_apk: elif args.build_apk:
podman_offline(f"{CONTAINER_HOME}/src", "flutter pub get --offline") build_apk()
podman_offline(f"{CONTAINER_HOME}/src", "flutter build apk")
elif args.sign_apk_standalone: elif args.sign_apk_standalone:
podman_offline(f"{CONTAINER_HOME}/fdroid", sign_apk_standalone()
"zipalign -f -v 4 ../src/build/app/outputs/flutter-apk/app-release.apk",
f"standalone_{APP_NAME}-{APP_SEMVER}.apk")
podman_offline(f"{CONTAINER_HOME}/fdroid",
"apksigner sign --ks standalone-keystore --ks-key-alias standalone --ks-pass",
f"env:STANDALONE_KEYSTORE_PASS standalone_{APP_NAME}-{APP_SEMVER}.apk")
elif args.sign_apk_fdroid: elif args.sign_apk_fdroid:
podman_offline(f"{CONTAINER_HOME}/fdroid", f"rm -rf {CONTAINER_HOME}/fdroid/unsigned/*") sign_apk_fdroid()
podman_offline(f"{CONTAINER_HOME}/fdroid",
f"test ! -f {CONTAINER_HOME}/fdroid/repo/{APP_NAME}_{APP_BUILD_ID}.apk",
"&& cp ../src/build/app/outputs/flutter-apk/app-release.apk",
f"unsigned/{APP_NAME}_{APP_BUILD_ID}.apk || echo exist")
podman_offline(f"{CONTAINER_HOME}/fdroid", "fdroid publish")
podman_offline(f"{CONTAINER_HOME}/fdroid", "fdroid update")
elif args.package_linux_appimage: elif args.package_linux_appimage:
podman_online(f"{CONTAINER_HOME}/src", "appimage-builder --recipe appimage.yml") package_linux_appimage()
elif args.package_linux_flatpak: elif args.package_linux_flatpak:
podman_online(f"{CONTAINER_HOME}/src", "flatpak-builder --disable-rofiles-fuse --force-clean --repo=flatpak-repo flatpak-build flatpak.yml") package_linux_flatpak()
podman_online(f"{CONTAINER_HOME}/src", f"flatpak build-bundle flatpak-repo {APP_NAME}-{APP_SEMVER}.flatpak pro.kherel.selfprivacy")
elif args.package_linux_archive: elif args.package_linux_archive:
podman_online(f"{CONTAINER_HOME}/src", f"tar -C build/linux/x64/release/bundle -vacf {APP_NAME}-{APP_SEMVER}.tar.zstd .") package_linux_archive()
elif args.deploy_gitea_release: elif args.deploy_gitea_release:
deploy_gitea_release() deploy_gitea_release()
elif args.deploy_fdroid_repo: elif args.deploy_fdroid_repo: