diff --git a/.generate_device_recipe.py.kate-swp b/.generate_device_recipe.py.kate-swp new file mode 100644 index 0000000..057d5d4 Binary files /dev/null and b/.generate_device_recipe.py.kate-swp differ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4c499e9..12fd373 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,10 @@ -name: droidian rootfs-builder +name: lindroid rootfs-builder on: workflow_dispatch: push: + branches: + - trixie schedule: - cron: "59 23 * * *" @@ -20,7 +22,7 @@ jobs: - name: Generate matrix id: gen-matrix run: | - JOBS="$(./generate_device_recipe.py --matrix)" + JOBS="$(./generate_recipe.py --matrix)" echo ::set-output name=matrix::${JOBS} build: @@ -42,15 +44,15 @@ jobs: run: echo "release_suffix=_${{ env.current_date }}" >> $GITHUB_ENV - name: Set nightly version - if: startsWith(github.ref, 'refs/tags/droidian') != true - run: echo "DROIDIAN_VERSION=nightly" >> $GITHUB_ENV + if: startsWith(github.ref, 'refs/tags/lindroid') != true + run: echo "LINDROID_VERSION=nightly" >> $GITHUB_ENV - name: Set version - if: startsWith(github.ref, 'refs/tags/droidian') == true - run: echo "DROIDIAN_VERSION=$(echo ${{ github.ref }} | rev | cut -d'/' -f1 | rev)" >> $GITHUB_ENV + if: startsWith(github.ref, 'refs/tags/lindroid') == true + run: echo "LINDROID_VERSION=$(echo ${{ github.ref }} | rev | cut -d'/' -f1 | rev)" >> $GITHUB_ENV - name: Set identifier - run: echo "DROIDIAN_IDENTIFIER=${{ matrix.config.product }}-${{ matrix.config.arch }}-${{ matrix.config.edition }}-${{ matrix.config.variant }}-${{ matrix.config.apilevel }}" >> $GITHUB_ENV + run: echo "LINDROID_IDENTIFIER=${{ matrix.config.arch }}-${{ matrix.config.edition }}" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v2 @@ -68,19 +70,19 @@ jobs: run: mkdir -p /tmp/buildd-results - name: Pull container - run: docker pull quay.io/droidian/rootfs-builder:next-amd64 + run: docker pull registry.lindroid.org/lindroid/rootfs-builder:next-amd64 - name: Start Container - run: echo CONTAINER_HASH=$(docker run --detach --privileged -v /tmp/buildd-results:/buildd/out -v /dev:/host-dev -v /sys/fs/cgroup:/sys/fs/cgroup -v ${PWD}:/buildd/sources --security-opt seccomp:unconfined quay.io/droidian/rootfs-builder:next-amd64 /sbin/init) >> $GITHUB_ENV + run: echo CONTAINER_HASH=$(docker run --detach --privileged -v /tmp/buildd-results:/buildd/out -v /dev:/host-dev -v /sys/fs/cgroup:/sys/fs/cgroup -v ${PWD}:/buildd/sources --security-opt seccomp:unconfined registry.lindroid.org/lindroid/rootfs-builder:next-amd64 /sbin/init) >> $GITHUB_ENV - name: Build rootfs run: | - docker exec $CONTAINER_HASH /bin/sh -c 'cd /buildd/sources; DROIDIAN_VERSION="${{ env.DROIDIAN_VERSION }}" ./generate_device_recipe.py ${{ matrix.config.product }} ${{ matrix.config.arch }} ${{ matrix.config.edition }} ${{ matrix.config.variant }} ${{ matrix.config.apilevel }} && debos --disable-fakemachine generated/droidian.yaml' + docker exec $CONTAINER_HASH /bin/sh -c 'cd /buildd/sources; ./generate_recipe.py && debos --disable-fakemachine generated/lindroid-${{ matrix.config.edition }}-${{ matrix.config.arch }}.yaml' - name: Upload artifacts uses: actions/upload-artifact@v3 with: - name: droidian-out-${{ matrix.config.product }}-${{ matrix.config.arch }}-${{ matrix.config.edition }}-${{ matrix.config.variant }}-${{ matrix.config.apilevel }} + name: lindroid-out-${{ matrix.config.arch }}-${{ matrix.config.edition }} path: out/* if-no-files-found: error retention-days: 1 @@ -105,29 +107,29 @@ jobs: - name: Delete old nightly release uses: dev-drprasad/delete-tag-and-release@v0.2.1 - if: startsWith(github.ref, 'refs/tags/droidian') != true + if: startsWith(github.ref, 'refs/tags/lindroid') != true with: delete_release: true # default: false tag_name: nightly # tag name to delete env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - name: Tag snapshot - if: startsWith(github.ref, 'refs/tags/droidian') != true + if: startsWith(github.ref, 'refs/tags/lindroid') != true uses: tvdias/github-tagger@v0.0.1 with: - repo-token: ${{ secrets.GITHUB_TOKEN }} + repo-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} tag: nightly - name: Download artifacts uses: actions/download-artifact@v3 with: - path: droidian-out + path: lindroid-out - name: Create SHA256SUMS run: | - cd droidian-out - for x in droidian-out-*; do + cd lindroid-out + for x in lindroid-out-*; do cd $x sha256sum * >> ../SHA256SUMS cd .. @@ -135,23 +137,25 @@ jobs: - name: Create stable release (drafted) id: create_release - if: startsWith(github.ref, 'refs/tags/droidian') + if: startsWith(github.ref, 'refs/tags/lindroid') uses: softprops/action-gh-release@v1 with: - files: droidian-out/SHA256SUMS + files: lindroid-out/SHA256SUMS tag_name: ${{ github.ref }} draft: true prerelease: false + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - name: Create nightly release id: create_nightly - if: startsWith(github.ref, 'refs/tags/droidian') != true + if: startsWith(github.ref, 'refs/tags/lindroid') != true uses: softprops/action-gh-release@v1 with: - files: droidian-out/SHA256SUMS + files: lindroid-out/SHA256SUMS tag_name: nightly draft: false prerelease: true + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} publish: runs-on: ubuntu-20.04 @@ -170,25 +174,26 @@ jobs: - name: Download artifacts uses: actions/download-artifact@v3 with: - name: droidian-out-${{ matrix.config.product }}-${{ matrix.config.arch }}-${{ matrix.config.edition }}-${{ matrix.config.variant }}-${{ matrix.config.apilevel }} - path: droidian-out + name: lindroid-out-${{ matrix.config.arch }}-${{ matrix.config.edition }} + path: lindroid-out - name: Create stable release (drafted) id: create_release - if: startsWith(github.ref, 'refs/tags/droidian') + if: startsWith(github.ref, 'refs/tags/lindroid') uses: softprops/action-gh-release@v1 with: - files: droidian-out/* + files: lindroid-out/* tag_name: ${{ github.ref }} draft: true prerelease: false - name: Create nightly release id: create_nightly - if: startsWith(github.ref, 'refs/tags/droidian') != true + if: startsWith(github.ref, 'refs/tags/lindroid') != true uses: softprops/action-gh-release@v1 with: - files: droidian-out/* + files: lindroid-out/* tag_name: nightly draft: false prerelease: true + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} diff --git a/.gitignore b/.gitignore index 02c7fe0..02d4586 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -generated/ out/ +generated/* *.zip diff --git a/generate_device_recipe.py b/generate_device_recipe.py deleted file mode 100755 index 785febd..0000000 --- a/generate_device_recipe.py +++ /dev/null @@ -1,256 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import sys - -import os - -import yaml - -import json - -import datetime - -from itertools import chain - -SUITABLE_FILES = [ - # Used for community ports - "community_devices.yml", - # Droidian official devices and generic rootfs - "devices.yml", -] - -IS_COMMUNITY_PORT = False - -BUILDER_MAIN_DIRECTORY = os.path.abspath(os.path.dirname(sys.argv[0])) -BUILDER_GENERATED_DIRECTORY = os.path.join(BUILDER_MAIN_DIRECTORY, "generated") -BUILDER_OUT_DIRECTORY = os.path.join(BUILDER_MAIN_DIRECTORY, "out") - -TEMPLATE = """ -{{- $product := or .product "%(product)s" -}} -{{- $architecture := or .architecture "%(architecture)s" -}} -{{- $suffix := or .suffix "%(suffix)s" -}} -{{- $edition := or .edition "%(edition)s" -}} -{{- $variant := or .variant "%(variant)s" -}} -{{- $apilevel := or .apilevel %(apilevel)d -}} -{{- $version := or .version "%(version)s" -}} -{{- $mtype := or .mtype "%(mtype)s" -}} -{{- $image := or .image (printf "droidian-%%s-%%s-%%s-%%s-api%%d-%%s-%%s_%%s.zip" $mtype $edition $variant $product $apilevel $architecture $version $suffix) -}} -{{- $output_type := or .output_type "%(output_type)s" -}} -{{- $use_internal_repository := or .use_internal_repository "%(use_internal_repository)s" -}} - -architecture: {{ $architecture }} -actions: - - - action: run - description: Do nothing - chroot: false - command: echo "Doing nothing!" -""" - -TEMPLATE_ONLY_STABLE = """ -{{ if ne $version "nightly" }} -""" - -TEMPLATE_ONLY_NIGHTLY = """ -{{ if eq $version "nightly" }} -""" - -TEMPLATE_END = """ -{{end}} -""" - -TEMPLATE_ENTRYPOINT = """ - - action: recipe - description: Build Droidian - recipe: ../rootfs-templates/device.yaml - variables: - architecture: {{ $architecture }} - suffix: {{ $suffix }} - edition: {{ $edition }} - variant: {{ $variant }} - apilevel: {{ $apilevel }} - version: {{ $version }} - image: {{ $image }} - output_type: {{ $output_type }} - use_internal_repository: {{ $use_internal_repository }} -""" - -TEMPLATE_BUNDLE = """ - - action: recipe - description: Generate %(name)s feature bundle - recipe: ../rootfs-templates/recipes/sideload-create.yaml - variables: - architecture: %(architecture)s - device_arch: %(architecture)s - sideload_name: %(name)s-api%(apilevel)d-%(architecture)s_{{ $suffix }} - packages: %(packages)s -""" - -TEMPLATE_IMAGE_ADAPTATION = """ - - action: recipe - description: Install device adaptation - recipe: ../rootfs-templates/recipes/adaptation.yaml - variables: - architecture: %(architecture)s - packages: %(packages)s -""" - -def get_matrix(contents): - """ - Returns a JSON containing all the possible jobs. - """ - - get_list = lambda x: x if isinstance(x, list) else [x] - - return list( - chain( - *[ - [ - { - "job_name" : "%s (%s/%s edition) - %s (api%d)" % (product, edition, variant, arch, apilevel), - "product" : product, - "arch" : arch, - "edition" : edition, - "variant" : variant, - "apilevel" : apilevel, - } - for arch in get_list(config.get("arch", ["arm64"])) - for edition in get_list(config.get("edition", ["phosh"])) - for variant in get_list(config.get("variant", ["standard"])) - for apilevel in get_list(config.get("apilevel", [28])) - ] - for product, config in contents.items() - if not product.startswith(".") - ] - ) - ) - -def generate_recipe_for_product(contents, product, arch, edition, variant, apilevel): - """ - Generates a debos recipe for the given product - """ - - config = contents[product] - - if not os.path.exists(BUILDER_GENERATED_DIRECTORY): - os.makedirs(BUILDER_GENERATED_DIRECTORY) - - if not os.path.exists(BUILDER_OUT_DIRECTORY): - os.makedirs(BUILDER_OUT_DIRECTORY) - - template_config = { - "product" : product, - "architecture" : arch, - "edition" : edition, - "variant" : variant, - "apilevel" : int(apilevel), - "mtype" : "OFFICIAL" if not IS_COMMUNITY_PORT else "UNOFFICIAL", - "version" : os.environ.get("DROIDIAN_VERSION", "nightly"), - "suffix" : datetime.datetime.utcnow().strftime("%Y%m%d"), - "output_type" : config["type"], - "use_internal_repository" : "yes" if config.get("use_internal_repository", False) else "no", - } - - # TODO: perhaps use pyyaml? - with open(os.path.join(BUILDER_GENERATED_DIRECTORY, "product.yaml"), "w") as f: - f.write(TEMPLATE % template_config) - - if config["type"] == "rootfs" and config.get("bundles", []): - for bundle in config["bundles"]: - write_end = False - if bundle["arch"] in ("any", arch) and bundle.get("apilevel", 28) in ("any", int(apilevel)): - if bundle.get("only_stable", False): - f.write(TEMPLATE_ONLY_STABLE) - write_end = True - elif bundle.get("only_nightly", False): - f.write(TEMPLATE_ONLY_NIGHTLY) - write_end = True - - f.write( - TEMPLATE_BUNDLE % { - "name" : bundle["name"], - "architecture" : arch, - "packages" : " ".join(bundle["packages"]), - "apilevel" : int(apilevel), - } - ) - - if write_end: - f.write(TEMPLATE_END) - elif config["type"] == "rootfs" and config.get("packages", []): - f.write( - TEMPLATE_IMAGE_ADAPTATION % { - "architecture" : arch, - "packages" : " ".join(config["packages"]) - } - ) - elif config["type"] == "image": - f.write( - TEMPLATE_IMAGE_ADAPTATION % { - "architecture" : arch, - "packages" : " ".join(config["packages"]) - } - ) - - with open(os.path.join(BUILDER_GENERATED_DIRECTORY, "droidian.yaml"), "w") as f: - f.write(TEMPLATE % template_config) - f.write(TEMPLATE_ENTRYPOINT) - -def prompt_product(contents): - """ - Interactive prompt to generate_recipe_for_product(). - """ - - available = get_matrix(contents) - - print( - "Available products:\n\n%s\n" % - "\n".join( - [ - " %d) %s" % (i+1, available[i]["job_name"]) - for i in range(0, len(available)) - ] - ) - ) - - choice = input("Please choose a product: ") - try: - choice = int(choice) - 1 - generate_recipe_for_product( - contents, - available[choice]["product"], - available[choice]["arch"], - available[choice]["edition"], - available[choice]["variant"], - available[choice]["apilevel"], - ) - except: - raise - -if __name__ == "__main__": - contents = {} - - for candidate in SUITABLE_FILES: - path = os.path.join(BUILDER_MAIN_DIRECTORY, candidate) - if not os.path.exists(path): - continue - - with open(path, "r") as f: - contents = yaml.safe_load(f) - - if candidate == "community_devices.yml": - IS_COMMUNITY_PORT = True - - break - - argc = len(sys.argv) - if argc == 6: - generate_recipe_for_product(contents, *sys.argv[1:]) - elif argc == 1: - prompt_product(contents) - elif "--matrix" in sys.argv: - print(json.dumps(get_matrix(contents))) - else: - sys.stderr.write("USAGE: generate_device_recipe.py [--matrix]|( )\n") - sys.exit(1) diff --git a/generate_recipe.py b/generate_recipe.py new file mode 100755 index 0000000..42fe8a3 --- /dev/null +++ b/generate_recipe.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import json +from datetime import datetime +import argparse + +# List of architectures and UIs +architectures = ["arm64", "armhf", "amd64"] +uis = ["plasma", "plasma-mobile"] + +# Common suffix for all files +suffix = datetime.today().strftime('%Y%m%d') + +# Function to generate the content +def generate_content(architecture, ui): + return f"""{{{{- $product := or .product "rootfs" -}}}} +{{{{- $architecture := or .architecture "{architecture}" -}}}} +{{{{- $suffix := or .suffix "{suffix}" -}}}} +{{{{- $edition := or .edition "{ui}" -}}}} +{{{{- $version := or .version "nightly" -}}}} +{{{{- $mtype := or .mtype "OFFICIAL" -}}}} +{{{{- $image := or .image (printf "droidian-%s-%s-%s-%s-%s_%s.zip" $mtype $edition $architecture $version $suffix) -}}}} +{{{{- $output_type := or .output_type "rootfs" -}}}} +{{{{- $use_internal_repository := or .use_internal_repository "no" -}}}} + +architecture: {{{{ $architecture }}}} +actions: + + - action: run + description: Do nothing + chroot: false + command: echo "Doing nothing!" + + - action: recipe + description: Build Droidian + recipe: ../rootfs-templates/lindroid_{ui}.yaml + variables: + architecture: {{{{ $architecture }}}} + suffix: {{{{ $suffix }}}} + edition: {{{{ $edition }}}} + version: {{{{ $version }}}} + image: {{{{ $image }}}} + output_type: {{{{ $output_type }}}} + use_internal_repository: {{{{ $use_internal_repository }}}} +""" + +# Directory to save generated files +output_dir = "generated" +os.makedirs(output_dir, exist_ok=True) + +# Generate files and matrix +matrix = [] +for architecture in architectures: + for ui in uis: + filename = f"lindroid-{ui}-{architecture}.yaml" + filepath = os.path.join(output_dir, filename) + content = generate_content(architecture, ui) + with open(filepath, 'w') as file: + file.write(content) + + job_name = f"rootfs ({ui} edition) - {architecture}" + matrix.append({ + "job_name": job_name, + "product": "rootfs", + "arch": architecture, + "edition": ui + }) + +# Parse arguments for matrix generation +parser = argparse.ArgumentParser(description='Generate device recipe files and matrix.') +parser.add_argument('--matrix', action='store_true', help='Generate and display the matrix.') +args = parser.parse_args() + +# Display the matrix if the --matrix flag is set +if args.matrix: + print(json.dumps(matrix, indent=4)) diff --git a/rootfs-templates b/rootfs-templates index 0c60d68..086cbab 160000 --- a/rootfs-templates +++ b/rootfs-templates @@ -1 +1 @@ -Subproject commit 0c60d68c4169f63e5a74ed3263b90f9c81530999 +Subproject commit 086cbabca7e438c9610116cab1276353a091fe5d