Skip to content

Commit

Permalink
add changelog support
Browse files Browse the repository at this point in the history
  • Loading branch information
antheas committed Aug 3, 2024
1 parent 97b2b3e commit 7737191
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 62 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/online_test_deck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ jobs:
prev-ref: ${{ github.event.inputs.prev == 'true' && 'ghcr.io/hhd-dev/bazzite-automated-deck:stable' || '' }}
rechunk: 'ghcr.io/hhd-dev/rechunk:latest'
version: 'rc${{ github.event.inputs.ref }}'
revision: ${{ github.sha }}
pretty: 'Rechunked (from ${{ github.event.inputs.ref }})'
git: "${{ github.workspace }}"
labels: |
io.artifacthub.package.logo-url=https://raw.githubusercontent.com/ublue-os/bazzite/main/repo_content/logo.png
io.artifacthub.package.readme-url=https://bazzite.gg/
org.opencontainers.image.created=<timestamp>
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=https://github.com/ublue-os/bazzite
org.opencontainers.image.title=bazzite
org.opencontainers.image.url=https://github.com/ublue-os/bazzite
Expand All @@ -66,6 +67,26 @@ jobs:
HHD: <version:hhd>,
Adjustor: <version:adjustor>,
HHD-UI: <version:hhd-ui>]
changelog: |
Bazzite Deck <pretty>
Version: <version>
Major Components:
- Kernel: <relver:kernel>
- Gamescope: <relver:gamescope>
- KDE: <version:kwayland>
Handheld Daemon:
- HHD: <version:hhd>
- Adjustor: <version:adjustor>
- HHD-UI: <version:hhd-ui>
Changes since version <previous>:
<commits>
Package Changes:
<pkgupd>
- name: Upload Image
id: upload
Expand Down
23 changes: 17 additions & 6 deletions 3_chunk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ fi
if [ -n "$PRETTY" ]; then
PREV_ARG+=("--pretty" "$PRETTY")
fi
if [ -n "$CHANGELOG" ]; then
PREV_ARG+=("--changelog" "$CHANGELOG")
fi
if [ -n "$GIT_DIR" ]; then
PREV_ARG+=("--git-dir" "$GIT_DIR")
fi
if [ -n "$REFISION" ]; then
PREV_ARG+=("--revision" "$REVISION")
fi

LABEL_ARR=()
if [ -n "$LABELS" ]; then
Expand All @@ -89,8 +98,12 @@ if [ -n "$DESCRIPTION" ]; then
LABEL_ARR+=("--label" "org.opencontainers.image.description=$DESCRIPTION")
fi

echo $RECHUNK -r "$REPO" -b "$OUT_TAG" -c "$CONTENT_META" "${PREV_ARG[@]}" "${LABEL_ARR[@]}"
$RECHUNK -r "$REPO" -b "$OUT_TAG" -c "$CONTENT_META" "${PREV_ARG[@]}" "${LABEL_ARR[@]}"
cmd=$RECHUNK -r "$REPO" -b "$OUT_TAG" -c "$CONTENT_META" \
--changelog-fn "${OUT_NAME}.changelog.txt" \
"${PREV_ARG[@]}" "${LABEL_ARR[@]}"
echo Running "$cmd"
$cmd


PREV_ARG=""
if [ -n "$SKIP_COMPRESSION" ]; then
Expand All @@ -107,10 +120,8 @@ ostree-ext-cli \

echo Created archive with ref ${OUT_REF}

# TODO: Temporarily remove to try newlines
# echo Writing manifests to ./$OUT_NAME.manifest.json, ./$OUT_NAME.manifest.raw.json
# skopeo inspect ${OUT_REF} > ${OUT_NAME}.manifest.json
# skopeo inspect --raw ${OUT_REF} > ${OUT_NAME}.manifest.raw.json
echo Writing manifest to ./$OUT_NAME.manifest.json
skopeo inspect ${OUT_REF} > ${OUT_NAME}.manifest.json

# Reset perms to make the files usable
chmod 666 -R ${OUT_NAME}*
35 changes: 34 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ inputs:
By default, this action will remove the ref image provided in `ref`.
This variable will disable discarding it after the OSTree commit is created.
May cause the storage overflow.
changelog:
description: |
The changelog of the image. Can be substituted with the <changelog> variable
and will be placed
git:
description: |
The git repository to use for the action. Used for versioning the output.
Defaults to the current repository.
revision:
description: |
The revision that will be recorded in the image metadata and in
"org.opencontainers.image.revision". Used for the <commit>
tag along with the git path.
If <commit> is not used, providing it as part of a "org.opencontainers.image.revision"
is the same.
outputs:
ref:
Expand All @@ -76,6 +91,14 @@ outputs:
description: |
The filesystem location of the rechunked image, so that it can be removed.
value: ${{ steps.rechunk.outputs.location }}
changelog:
description: |
The changelog of the image, with the <changelog> variable substituted.
value: ${{ steps.rechunk.outputs.changelog }}
manifest:
description: |
The skopeo manifest of the rechunked image.
value: ${{ steps.rechunk.outputs.manifest }}

runs:
using: 'composite'
Expand Down Expand Up @@ -124,9 +147,14 @@ runs:
shell: bash
run: |
OUT_NAME=$(echo ${{ inputs.ref }} | rev | cut -d'/' -f1 | rev | sed 's/:/_/')
GIT_PATH="${{ inputs.git }}"
if [ -n "$GIT_PATH" ]; then
GIT_PATH="${{ github.workspace }}"
fi
sudo podman run --rm \
-v "${{ github.workspace }}:/workspace" \
-v "$GIT_PATH:/var/git" \
-v "cache_ostree:/var/ostree" \
-e REPO=/var/ostree/repo \
-e MAX_LAYERS="${{ inputs.max-layers }}" \
Expand All @@ -138,7 +166,10 @@ runs:
-e VERSION_FN="/workspace/version.txt" \
-e PRETTY="${{ inputs.pretty }}" \
-e DESCRIPTION="${{ inputs.description }}" \
-e CHANGELOG="${{ inputs.changelog }}" \
-e OUT_REF="oci:$OUT_NAME" \
-e GIT_DIR="/var/git" \
-e REVISION="${{ inputs.revision }}" \
-e PREV_REF_FAIL="${{ inputs.prev-ref-fail }}" \
-u 0:0 \
${{ inputs.rechunk }} \
Expand All @@ -147,6 +178,8 @@ runs:
echo "version=$(sudo cat ${{ github.workspace }}/version.txt)" >> $GITHUB_OUTPUT
echo "ref=oci:${{ github.workspace }}/$OUT_NAME" >> $GITHUB_OUTPUT
echo "location=${{ github.workspace }}/$OUT_NAME" >> $GITHUB_OUTPUT
echo "changelog=${{ github.workspace }}/$OUT_NAME.changelog.txt" >> $GITHUB_OUTPUT
echo "manifest=${{ github.workspace }}/$OUT_NAME.manifest.json" >> $GITHUB_OUTPUT
# Remove root permissions
sudo chown $(id -u):$(id -g) -R "${{ github.workspace }}/$OUT_NAME"
Expand Down
20 changes: 18 additions & 2 deletions src/rechunk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,23 @@ def argparse_func():
parser.add_argument(
"-l", "--label", help="Add labels to the output image.", action="append"
)
parser.add_argument("--pretty", help="Pretty version string.", default=None)
parser.add_argument(
"--pretty", help="Pretty version string.", default=None
"--version-fn", help="Output path for version name.", default=None
)
parser.add_argument(
"--version-fn", help="Output path for version name.", default=None
"--revision",
help="The git hash of the project (placed in 'org.opencontainers.image.revision' and internal metadata for calculating changelogs).",
default=None,
)
parser.add_argument(
"--git-dir",
help="The checked out git directory for calculating changelogs.",
default=None,
)
parser.add_argument("--changelog", help="Changelog template.", default=None)
parser.add_argument(
"--changelog-fn", help="Output path for the generated changelog.", default=None
)

# Hyperparameters
Expand Down Expand Up @@ -118,6 +130,10 @@ def argparse_func():
pretty=args.pretty,
version_fn=args.version_fn,
result_fn=None,
revision=args.revision,
git_dir=args.git_dir,
changelog=args.changelog,
changelog_fn=args.changelog_fn,
)


Expand Down
57 changes: 43 additions & 14 deletions src/rechunk/alg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
from rechunk.model import MetaPackage, Package

from .fedora import get_packages
from .model import INFO_KEY, Package, get_layers
from .ostree import calculate_ostree_layers, dump_ostree_contentmeta, get_ostree_map, run_with_ostree_files
from .model import INFO_KEY, Package, get_layers, get_info, ExportInfo
from .ostree import (
calculate_ostree_layers,
dump_ostree_contentmeta,
get_ostree_map,
run_with_ostree_files,
)
from .utils import get_default_meta_yaml, get_labels, get_update_matrix, tqdm

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -429,18 +434,22 @@ def load_previous_manifest(
fn: str | list[str], packages: list[MetaPackage], max_layers: int
):
logger.info(f"Loading previous manifest from '{fn}'.")
info = None

if isinstance(fn, str):
with open(fn, "r") as f:
raw = json.load(f)

# Since podman/skopeo do not respect layer annotations, use
# a JSON config key
layers = get_layers(raw)
# a JSON config key
info = get_info(raw)
layers = get_layers(info)

# Then as a fallback use the old OSTree format
if layers:
logger.info(f"Processing previous manifest with {len(layers)} layers (loaded from '{INFO_KEY}').")
logger.info(
f"Processing previous manifest with {len(layers)} layers (loaded from '{INFO_KEY}')."
)
else:
layers = []
for data in raw["LayersData"]:
Expand All @@ -452,11 +461,15 @@ def load_previous_manifest(
if "ostree.components" not in annotations:
continue
layers.append(annotations["ostree.components"].split(","))
logger.info(f"Processing previous manifest with {len(raw)} layers (loaded from 'ostree.components').")
logger.info(
f"Processing previous manifest with {len(raw)} layers (loaded from 'ostree.components')."
)
else:
raw = None
layers = [l.split(",") for l in fn]
logger.info(f"Processing previous manifest with {len(fn)} layers (through cache argument).")
logger.info(
f"Processing previous manifest with {len(fn)} layers (through cache argument)."
)

assert layers, "No layers found in previous manifest. Raising."

Expand All @@ -476,7 +489,9 @@ def load_previous_manifest(
for p in todo:
if p.name == name:
if pkg is not None:
logger.error(f"Duplicate package '{name}' found in previous manifest.")
logger.error(
f"Duplicate package '{name}' found in previous manifest."
)
pkg = p

if pkg is None:
Expand Down Expand Up @@ -508,7 +523,7 @@ def load_previous_manifest(
if removed:
logger.info(f"The following packages were removed:\n{removed}")

return todo, dedi_layers, prefill, raw
return todo, dedi_layers, prefill, raw, info


def main(
Expand All @@ -527,6 +542,10 @@ def main(
pretty: str | None = None,
version_fn: str | None = None,
_cache: dict | None = None,
revision: str | None = None,
git_dir: str | None = None,
changelog: str | None = None,
changelog_fn: str | None = None,
):
if not meta_fn:
meta_fn = get_default_meta_yaml()
Expand Down Expand Up @@ -593,7 +612,7 @@ def main(
if previous_manifest:
try:
logger.info("Loading existing layer data.")
todo, dedi_layers, prefill, manifest_json = load_previous_manifest(
todo, dedi_layers, prefill, manifest_json, info = load_previous_manifest(
previous_manifest, new_packages, max_layers
)
found_previous_plan = True
Expand All @@ -602,6 +621,7 @@ def main(

if not found_previous_plan:
manifest_json = None
info = None
logger.warning("No existing layer data. Expect layer shifts")
todo, dedi_layers, prefill = prefill_layers(
new_packages, upd_matrix, max_layers, prefill_size
Expand All @@ -617,11 +637,20 @@ def main(
layers = fill_layers(todo, prefill, upd_matrix, max_layer_size=max_layer_size)
print_results(dedi_layers, prefill, layers, upd_matrix, result_fn)

final_layers, ostree_out = calculate_ostree_layers(
dedi_layers, layers, mapping
)
final_layers, ostree_out = calculate_ostree_layers(dedi_layers, layers, mapping)
new_labels, timestamp = get_labels(
labels, version, manifest_json, version_fn, pretty, packages, final_layers
labels=labels,
version=version,
prev_manifest=manifest_json,
version_fn=version_fn,
pretty=pretty,
base_pkg=packages,
layers=final_layers,
revision=revision,
git_dir=git_dir,
changelog_template=changelog,
changelog_fn=changelog_fn,
info=info,
)

if contentmeta_fn:
Expand Down
11 changes: 8 additions & 3 deletions src/rechunk/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class ExportInfoV2(TypedDict):
uniq: str
layers: Sequence[Sequence[str]]
packages: dict[str, str]
revision: str | None


def get_layers(manifest):
def get_info(manifest):
import json

if not "Labels" in manifest:
Expand All @@ -55,10 +55,13 @@ def get_layers(manifest):
return None

try:
info = json.loads(labels[INFO_KEY])
return json.loads(labels[INFO_KEY])
except json.JSONDecodeError:
return None

ExportInfo = ExportInfoV1 | ExportInfoV2

def get_layers(info):
if info["version"] < 2:
return None

Expand All @@ -72,6 +75,7 @@ def export_v2(
uniq: str | None,
base_pkg: Sequence[Package] | None,
layers: Sequence[Sequence[str]],
revision: str | None = None,
) -> str:
import json

Expand All @@ -86,5 +90,6 @@ def export_v2(
uniq=uniq or "",
packages=packages,
layers=layers,
revision=revision,
)
)
Loading

0 comments on commit 7737191

Please sign in to comment.