mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-16 21:53:17 +00:00
python ci script
This commit is contained in:
parent
d2f5eaad8b
commit
1d61793144
14
.drone.yml
14
.drone.yml
|
@ -27,7 +27,7 @@ steps:
|
|||
|
||||
- name: Build Intermediate Linux Release Artifact (Binary)
|
||||
commands:
|
||||
- ./ci.sh --build-linux
|
||||
- ./ci.py --build-linux
|
||||
environment:
|
||||
STANDALONE_KEYSTORE_PASS:
|
||||
from_secret: STANDALONE_KEYSTORE_PASS
|
||||
|
@ -36,7 +36,7 @@ steps:
|
|||
|
||||
- name: Build Intermediate Android Release Artifact (.APK)
|
||||
commands:
|
||||
- ./ci.sh --build-apk
|
||||
- ./ci.py --build-apk
|
||||
environment:
|
||||
STANDALONE_KEYSTORE_PASS:
|
||||
from_secret: STANDALONE_KEYSTORE_PASS
|
||||
|
@ -45,7 +45,7 @@ steps:
|
|||
|
||||
- name: Sign Android Release Artifact (.APK) for Standalone Use
|
||||
commands:
|
||||
- ./ci.sh --sign-apk-standalone
|
||||
- ./ci.py --sign-apk-standalone
|
||||
environment:
|
||||
STANDALONE_KEYSTORE_PASS:
|
||||
from_secret: STANDALONE_KEYSTORE_PASS
|
||||
|
@ -54,7 +54,7 @@ steps:
|
|||
|
||||
- name: Sign Android Release Artifact (.APK) for F-Droid Repository
|
||||
commands:
|
||||
- ./ci.sh --sign-apk-fdroid
|
||||
- ./ci.py --sign-apk-fdroid
|
||||
environment:
|
||||
STANDALONE_KEYSTORE_PASS:
|
||||
from_secret: STANDALONE_KEYSTORE_PASS
|
||||
|
@ -63,15 +63,15 @@ steps:
|
|||
|
||||
- name: Package Linux AppImage Artifact
|
||||
commands:
|
||||
- ./ci.sh --package-linux-appimage
|
||||
- ./ci.py --package-linux-appimage
|
||||
|
||||
- name: Package Linux Flatpak Artifact
|
||||
commands:
|
||||
- ./ci.sh --package-linux-flatpak
|
||||
- ./ci.py --package-linux-flatpak
|
||||
|
||||
- name: Package Linux Archive Artifact
|
||||
commands:
|
||||
- ./ci.sh --package-linux-archive
|
||||
- ./ci.py --package-linux-archive
|
||||
|
||||
trigger:
|
||||
event:
|
||||
|
|
73
ci.py
Executable file
73
ci.py
Executable file
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import yaml
|
||||
import argparse
|
||||
|
||||
CONTAINER_IMAGE = "localhost/flutter-build-env"
|
||||
HOST_HOME = "/var/lib/drone-runner-exec"
|
||||
CONTAINER_HOME = "/var/lib/builder"
|
||||
|
||||
APP_NAME = "pro.kherel.selfprivacy"
|
||||
APP_VERSION_FULL = yaml.safe_load(open("pubspec.yaml", "r"))['version']
|
||||
APP_SEMVER = APP_VERSION_FULL[:APP_VERSION_FULL.find("+")]
|
||||
APP_BUILD_ID = APP_VERSION_FULL[APP_VERSION_FULL.find("+"):][1::]
|
||||
|
||||
def podman_offline(dir, *args):
|
||||
subprocess.run(["podman", "run", "--rm", "--network=none", f"--workdir={dir}",
|
||||
"-v", f"src:{CONTAINER_HOME}/src:U",
|
||||
"-v", f"{HOST_HOME}/fdroid:{CONTAINER_HOME}/fdroid:U",
|
||||
"-v", f"{HOST_HOME}/fdroid-keystore:{CONTAINER_HOME}/fdroid/fdroid-keystore:U",
|
||||
"-v", f"{HOST_HOME}/standalone-keystore:{CONTAINER_HOME}/fdroid/standalone-keystore:U",
|
||||
"--env", "FDROID_KEYSTORE_PASS=" + os.environ.get('FDROID_KEYSTORE_PASS'),
|
||||
"--env", "STANDALONE_KEYSTORE_PASS=" + os.environ.get('STANDALONE_KEYSTORE_PASS'),
|
||||
CONTAINER_IMAGE, "bash", "-c", ' '.join(args)
|
||||
])
|
||||
|
||||
def podman_online(dir, *args):
|
||||
subprocess.run(["podman", "run", "--rm", "--privileged", f"--workdir={dir}",
|
||||
"-v", f"src:{CONTAINER_HOME}/src:U",
|
||||
CONTAINER_IMAGE, "bash", "-c", ' '.join(args)
|
||||
])
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument("--build-linux", action="store_true")
|
||||
group.add_argument("--build-apk", action="store_true")
|
||||
group.add_argument("--sign-apk-standalone", action="store_true")
|
||||
group.add_argument("--sign-apk-fdroid", action="store_true")
|
||||
group.add_argument("--package-linux-appimage", action="store_true")
|
||||
group.add_argument("--package-linux-flatpak", action="store_true")
|
||||
group.add_argument("--package-linux-archive", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.build_linux:
|
||||
podman_offline(f"{CONTAINER_HOME}/src", "flutter pub get --offline")
|
||||
podman_offline(f"{CONTAINER_HOME}/src", "flutter build linux")
|
||||
elif args.build_apk:
|
||||
podman_offline(f"{CONTAINER_HOME}/src", "flutter pub get --offline")
|
||||
podman_offline(f"{CONTAINER_HOME}/src", "flutter build apk")
|
||||
elif args.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")
|
||||
elif args.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")
|
||||
elif args.package_linux_appimage:
|
||||
podman_online(f"{CONTAINER_HOME}/src", "appimage-builder --recipe appimage.yml")
|
||||
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")
|
||||
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:
|
||||
podman_online(f"{CONTAINER_HOME}/src", f"tar -C build/linux/x64/release/bundle -vacf {APP_NAME}-{APP_SEMVER}.tar.zstd .")
|
98
ci.sh
98
ci.sh
|
@ -1,98 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -o errexit -o pipefail -o noclobber -o nounset -x
|
||||
|
||||
CONTAINER_IMAGE="localhost/flutter-build-env"
|
||||
APP_NAME="pro.kherel.selfprivacy"
|
||||
APP_VERSION_FULL="$(yq '.version' pubspec.yaml)"
|
||||
APP_SEMVER="$(printf $APP_VERSION_FULL | cut -d '+' -f1)"
|
||||
APP_BUILD_ID="$(printf $APP_VERSION_FULL | cut -d '+' -f2)"
|
||||
|
||||
OPTS=$(getopt -o "" --long "build-linux,build-apk,sign-apk-standalone,sign-apk-fdroid,package-linux-appimage,package-linux-flatpak,package-linux-archive" -- "$@")
|
||||
eval set -- "$OPTS"
|
||||
|
||||
usage () {
|
||||
echo "Usage: $0 [--build-linux] [--build-apk] [--sign-apk-standalone] [--sign-apk-fdroid] [--package-linux-appimage] [--package-linux-flatpak] [--package-linux-archive]" 1>&2; exit 1;
|
||||
}
|
||||
|
||||
podman_offline () {
|
||||
podman run --rm -v src:/var/lib/builder/src:U -v /var/lib/drone-runner-exec/fdroid:/var/lib/builder/fdroid:U -v /var/lib/drone-runner-exec/fdroid-keystore:/var/lib/builder/fdroid/fdroid-keystore:U -v /var/lib/drone-runner-exec/standalone-keystore:/var/lib/builder/fdroid/standalone-keystore:U --env FDROID_KEYSTORE_PASS="$FDROID_KEYSTORE_PASS" --env STANDALONE_KEYSTORE_PASS="$STANDALONE_KEYSTORE_PASS" --network=none --workdir $1 "$CONTAINER_IMAGE" ${@:2}
|
||||
}
|
||||
|
||||
podman_online () {
|
||||
podman run --rm -v src:/var/lib/builder/src:U --privileged --workdir $1 "$CONTAINER_IMAGE" ${@:2}
|
||||
}
|
||||
|
||||
build_linux () {
|
||||
podman_offline "/var/lib/builder/src" flutter pub get --offline
|
||||
podman_offline "/var/lib/builder/src" flutter build linux
|
||||
}
|
||||
|
||||
build_apk () {
|
||||
podman_offline "/var/lib/builder/src" flutter pub get --offline
|
||||
podman_offline "/var/lib/builder/src" flutter build apk
|
||||
}
|
||||
|
||||
sign_apk_standalone () {
|
||||
podman_offline "/var/lib/builder/fdroid" zipalign -f -v 4 ../src/build/app/outputs/flutter-apk/app-release.apk standalone_"$APP_NAME"-"$APP_SEMVER".apk
|
||||
podman_offline "/var/lib/builder/fdroid" apksigner sign --ks standalone-keystore --ks-key-alias standalone --ks-pass env:STANDALONE_KEYSTORE_PASS standalone_"$APP_NAME"-"$APP_SEMVER".apk
|
||||
}
|
||||
|
||||
sign_apk_fdroid () {
|
||||
podman_offline "/var/lib/builder/fdroid" rm -rf /var/lib/builder/fdroid/unsigned/*
|
||||
podman_offline "/var/lib/builder/fdroid" test ! -f /var/lib/builder/fdroid/repo/"$APP_NAME"_"$APP_BUILD_ID".apk && cp ../src/build/app/outputs/flutter-apk/app-release.apk unsigned/"$APP_NAME"_"$APP_BUILD_ID".apk || echo exist"
|
||||
podman_offline "/var/lib/builder/fdroid" fdroid publish
|
||||
podman_offline "/var/lib/builder/fdroid" fdroid update
|
||||
}
|
||||
|
||||
package_linux_appimage () {
|
||||
podman_online "/var/lib/builder/src" appimage-builder --recipe appimage.yml
|
||||
}
|
||||
|
||||
package_linux_flatpak () {
|
||||
podman_online "/var/lib/builder/src" flatpak-builder --disable-rofiles-fuse --force-clean --repo=flatpak-repo flatpak-build flatpak.yml
|
||||
podman_online "/var/lib/builder/src" flatpak build-bundle flatpak-repo $APP_NAME-$APP_SEMVER.flatpak pro.kherel.selfprivacy
|
||||
}
|
||||
|
||||
package_linux_archive () {
|
||||
podman_online "/var/lib/builder/src" tar -C build/linux/x64/release/bundle -vacf $APP_NAME-$APP_SEMVER.tar.zstd .
|
||||
}
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
--build-linux )
|
||||
build_linux
|
||||
shift
|
||||
;;
|
||||
--build-apk )
|
||||
build_apk
|
||||
shift
|
||||
;;
|
||||
--sign-apk-standalone )
|
||||
sign_apk_standalone
|
||||
shift
|
||||
;;
|
||||
--sign-apk-fdroid )
|
||||
sign_apk_fdroid
|
||||
shift
|
||||
;;
|
||||
--package-linux-appimage )
|
||||
package_linux_appimage
|
||||
shift
|
||||
;;
|
||||
--package-linux-flatpak )
|
||||
package_linux_flatpak
|
||||
shift
|
||||
;;
|
||||
--package-linux-archive )
|
||||
package_linux_archive
|
||||
shift
|
||||
;;
|
||||
-- )
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
Loading…
Reference in a new issue