mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 14:07:05 +05:30
scripts: return to monke
I don't like bash but turns out I dislike Python more This reverts commit2628bfc2cd
,d77fa13903
and69f63cced4
.
This commit is contained in:
parent
892d68581d
commit
591c68a6e4
8 changed files with 90 additions and 218 deletions
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
|
@ -28,10 +28,6 @@ jobs:
|
|||
distribution: temurin
|
||||
java-version: 18
|
||||
|
||||
- name: Set up black (Python)
|
||||
shell: bash
|
||||
run: pip install black==23.3.0
|
||||
|
||||
- name: Run unit tests
|
||||
uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c # v2.7.0
|
||||
with:
|
||||
|
@ -61,12 +57,6 @@ jobs:
|
|||
distribution: temurin
|
||||
java-version: 18
|
||||
|
||||
- name: Set up Git author
|
||||
shell: bash
|
||||
run: |
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email noreply@github.com
|
||||
|
||||
- name: Decrypt secrets
|
||||
run: |
|
||||
./scripts/setup-age.sh
|
||||
|
@ -87,6 +77,6 @@ jobs:
|
|||
run: scripts/signing-cleanup.sh
|
||||
|
||||
- name: Deploy snapshot
|
||||
run: scripts/deploy-snapshot.py
|
||||
run: scripts/deploy-snapshot.sh
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
@ -35,10 +35,6 @@ class SpotlessPlugin : Plugin<Project> {
|
|||
targetExclude("**/build/")
|
||||
licenseHeaderFile(project.file("spotless/license.kt"), "import|plugins|@file")
|
||||
}
|
||||
python {
|
||||
target("scripts/**.py")
|
||||
black("23.3.0")
|
||||
}
|
||||
format("xml") {
|
||||
target("**/*.xml")
|
||||
targetExclude("**/build/", ".idea/", "/spotless/", "**/lint-baseline.xml")
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import signal
|
||||
import subprocess
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
emu_process = None
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
if emu_process is not None:
|
||||
emu_process.signal(signal.SIGINT)
|
||||
|
||||
|
||||
def make_cmdline_tools_path(android_home: Path) -> str:
|
||||
return android_home / "cmdline-tools" / "latest" / "bin"
|
||||
|
||||
|
||||
def main():
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
android_home = os.getenv("ANDROID_HOME")
|
||||
if not android_home:
|
||||
raise RuntimeError("$ANDROID_HOME must be set to use this script")
|
||||
android_home = Path(android_home)
|
||||
api_level = os.getenv("ANDROID_API_LEVEL")
|
||||
if not api_level:
|
||||
print("$ANDROID_API_LEVEL not defined; defaulting to 33")
|
||||
api_level = "33"
|
||||
cmdline_path = make_cmdline_tools_path(android_home)
|
||||
image_package = f"system-images;android-{api_level};google_apis;x86_64"
|
||||
subprocess.run(
|
||||
[
|
||||
cmdline_path / "sdkmanager",
|
||||
image_package,
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
cmdline_path / "avdmanager",
|
||||
"create",
|
||||
"avd",
|
||||
"--force",
|
||||
"-n",
|
||||
f"Pixel_XL_API_{api_level}",
|
||||
"--abi",
|
||||
"google_apis/x86_64",
|
||||
"--package",
|
||||
image_package,
|
||||
"--device",
|
||||
"pixel_xl",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
emu_process = subprocess.Popen(
|
||||
[
|
||||
android_home / "emulator" / "emulator",
|
||||
"-avd",
|
||||
f"Pixel_XL_API_{api_level}",
|
||||
"-gpu",
|
||||
"swiftshader_indirect",
|
||||
"-noaudio",
|
||||
],
|
||||
)
|
||||
emu_process.wait()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
28
scripts/boot-emulator.sh
Executable file
28
scripts/boot-emulator.sh
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Creates and boots an emulator that exactly matches the one in our CI. It is recommended
|
||||
# to use this as the target device for screenshot tests.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
[ -n "${ANDROID_HOME:-}" ] || {
|
||||
echo "ANDROID_HOME must be set to use this script"
|
||||
exit 1
|
||||
}
|
||||
[ -n "${ANDROID_API_LEVEL:-}" ] || { echo "ANDROID_API_LEVEL not defined; defaulting to 33"; }
|
||||
|
||||
API_LEVEL="${ANDROID_API_LEVEL:-33}"
|
||||
|
||||
sdkmanager "system-images;android-${API_LEVEL};google_apis;x86_64"
|
||||
|
||||
echo no | "${ANDROID_HOME}"/cmdline-tools/latest/bin/avdmanager create avd \
|
||||
--force \
|
||||
-n "Pixel_XL_API_${API_LEVEL}" \
|
||||
--abi 'google_apis/x86_64' \
|
||||
--package "system-images;android-${API_LEVEL};google_apis;x86_64" \
|
||||
--device 'pixel_xl'
|
||||
|
||||
"${ANDROID_HOME}"/emulator/emulator \
|
||||
-avd "Pixel_XL_API_${API_LEVEL}" \
|
||||
-gpu 'swiftshader_indirect' \
|
||||
-noaudio
|
|
@ -1,101 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
from typing import Optional
|
||||
from pathlib import Path
|
||||
import glob
|
||||
import tempfile
|
||||
|
||||
NIGHTLY_TAG = "nightly"
|
||||
|
||||
|
||||
def exec(command_str: str, shell: bool = False) -> Optional[int]:
|
||||
print(f"Executing '{command_str}'")
|
||||
proc = None
|
||||
if shell:
|
||||
proc = subprocess.run(
|
||||
command_str,
|
||||
text=True,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
else:
|
||||
proc = subprocess.run(
|
||||
command_str.split(" "),
|
||||
text=True,
|
||||
shell=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
result = proc.returncode
|
||||
print(f"{proc.stdout}")
|
||||
return result
|
||||
|
||||
|
||||
def exec_out(command_str: str, shell: bool = False) -> str:
|
||||
print(f"Executing '{command_str}'")
|
||||
proc = None
|
||||
if shell:
|
||||
proc = subprocess.run(command_str, capture_output=True, text=True, shell=True)
|
||||
else:
|
||||
proc = subprocess.run(
|
||||
command_str.split(" "), capture_output=True, text=True, shell=False
|
||||
)
|
||||
data = proc.stdout
|
||||
return data
|
||||
|
||||
|
||||
def get_current_rev() -> str:
|
||||
return exec_out("git rev-parse --short HEAD")
|
||||
|
||||
|
||||
def get_asset_directory() -> Path:
|
||||
workspace = os.getenv("GITHUB_WORKSPACE")
|
||||
return Path(workspace) / "android" / "apk"
|
||||
|
||||
|
||||
def overwrite_local_tag():
|
||||
exec(f"git tag -f {NIGHTLY_TAG} -m 'Nightly release'", shell=True)
|
||||
|
||||
|
||||
def overwrite_remote_tag():
|
||||
exec(f"git push -f origin {NIGHTLY_TAG}")
|
||||
|
||||
|
||||
def has_release() -> bool:
|
||||
result = exec(f"gh release view {NIGHTLY_TAG}")
|
||||
return result is not None and result == 0
|
||||
|
||||
|
||||
def delete_release():
|
||||
exec(f"gh release delete --yes {NIGHTLY_TAG}")
|
||||
|
||||
|
||||
def create_release():
|
||||
with tempfile.NamedTemporaryFile("w+") as cf:
|
||||
cf.write(f"Latest release for Claw from revision {get_current_rev()}")
|
||||
cf.flush()
|
||||
cwd = os.getcwd()
|
||||
os.chdir(get_asset_directory())
|
||||
apks = " ".join(glob.glob("*.apk"))
|
||||
exec(
|
||||
"gh release create --prerelease "
|
||||
+ f"--title 'Latest snapshot build' --notes-file {cf.name} "
|
||||
+ f"{NIGHTLY_TAG} {apks}",
|
||||
shell=True,
|
||||
)
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
def main():
|
||||
overwrite_local_tag()
|
||||
if has_release():
|
||||
delete_release()
|
||||
overwrite_remote_tag()
|
||||
create_release()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
43
scripts/deploy-snapshot.sh
Executable file
43
scripts/deploy-snapshot.sh
Executable file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euxo pipefail
|
||||
|
||||
NIGHTLY_TAG="nightly"
|
||||
CURRENT_REV="$(git rev-parse --short HEAD)"
|
||||
ASSET_DIRECTORY="${GITHUB_WORKSPACE:?}/android/apk"
|
||||
|
||||
function overwrite_local_tag() {
|
||||
git tag -f "${NIGHTLY_TAG}"
|
||||
}
|
||||
|
||||
function overwrite_remote_tag() {
|
||||
git push -f origin "${NIGHTLY_TAG}"
|
||||
}
|
||||
|
||||
function has_release() {
|
||||
gh release view "${NIGHTLY_TAG}" &>/dev/null
|
||||
echo "$?"
|
||||
}
|
||||
|
||||
function delete_release() {
|
||||
gh release delete --yes "${NIGHTLY_TAG}"
|
||||
}
|
||||
|
||||
function create_release() {
|
||||
local CHANGELOG_FILE
|
||||
CHANGELOG_FILE="$(mktemp)"
|
||||
echo "Latest release for Claw from revision ${CURRENT_REV}" | tee "${CHANGELOG_FILE}"
|
||||
pushd "${ASSET_DIRECTORY}" || return
|
||||
gh release create --prerelease --title "Latest snapshot build" --notes-file "${CHANGELOG_FILE}" "${NIGHTLY_TAG}" ./*.apk
|
||||
popd || return
|
||||
}
|
||||
|
||||
overwrite_local_tag
|
||||
|
||||
if [[ "$(has_release)" -eq 0 ]]; then
|
||||
delete_release
|
||||
fi
|
||||
|
||||
overwrite_remote_tag
|
||||
|
||||
create_release
|
|
@ -1,31 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 4:
|
||||
raise RuntimeError(
|
||||
"USAGE: encrypt-secret.py <input file> <output file> <encryption key>"
|
||||
)
|
||||
input_file = Path(sys.argv[1])
|
||||
output_file = Path(sys.argv[2])
|
||||
age_key = sys.argv[3]
|
||||
if shutil.which("age") is None:
|
||||
raise RuntimeError("age not installed")
|
||||
if not input_file.exists():
|
||||
raise RuntimeError(f"Input file '{input_file.name}' does not exist")
|
||||
recipient = subprocess.run(
|
||||
["age-keygen", "-y"], capture_output=True, text=True, input=age_key
|
||||
).stdout.strip()
|
||||
subprocess.run(
|
||||
["age", "--encrypt", "-r", recipient, "-o", output_file],
|
||||
input=input_file.read_bytes(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
18
scripts/encrypt-secret.sh
Executable file
18
scripts/encrypt-secret.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
INPUT_FILE="${1:-}"
|
||||
OUTPUT_FILE="${2:-}"
|
||||
AGE_KEY="${3:-}"
|
||||
|
||||
if ! command -v age 1>/dev/null; then
|
||||
echo "age not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$AGE_KEY" && -n "$INPUT_FILE" && -n "$OUTPUT_FILE" ]]; then
|
||||
age --encrypt -r "$(echo "${AGE_KEY}" | age-keygen -y)" -o "${OUTPUT_FILE}" < "${INPUT_FILE}"
|
||||
else
|
||||
echo "Usage: ./encrypt-secret.sh <input file> <output file> <encryption key>"
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue