Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate AUR publishing #76

Merged
merged 4 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
steps:
- name: Download all artifacts
uses: actions/download-artifact@v3

- name: Assemble release directory
run: |
mkdir release
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Publish package"

on:
workflow_dispatch:
release:
types: [published]

jobs:
aur-publish:
name: Publish to AUR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Generate PKGBUILD
run: nix build .#caligula-bin-aur

- name: Publish AUR package
uses: KSXGitHub/github-actions-deploy-aur@v2
with:
pkgname: caligula-bin
pkgbuild: ./result/PKGBUILD
test: true
commit_username: ifd3f
commit_email: [email protected]
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
commit_message: Update AUR package
ssh_keyscan_types: rsa,dsa,ecdsa,ed25519
11 changes: 10 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@
'';

caligula = self.packages."${system}"."caligula-${system}";
} // crossHelpers.caligulaPackages;
}

// crossHelpers.caligulaPackages

// (if system == "x86_64-linux" then {
caligula-bin-aur = pkgs.callPackage ./nix/aur.nix {
caligula = self.packages.x86_64-linux.caligula;
};
} else
{ });

devShells.default = crossHelpers.crossCompileDevShell.overrideAttrs
(final: prev: {
Expand Down
49 changes: 49 additions & 0 deletions nix/aur.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# runs on x86_64-linux only
{ runCommand, caligula, pkgrel ? "1" }:
let
sha256 = runCommand "caligula-sha256" { } ''
sha256sum ${caligula}/bin/caligula | awk '{print $1}'
'';
pkgdesc = "A lightweight, user-friendly disk imaging TUI";

pkgbuild = ''
pkgname=caligula-bin
pkgdesc="${pkgdesc}"
pkgrel=${pkgrel}
pkgver=${caligula.version}
url="https://github.com/ifd3f/caligula"
license=("GPL-3.0")
arch=("x86_64")
provides=("caligula")
conflicts=("caligula")
source=("https://github.com/ifd3f/caligula/releases/download/v$pkgver/caligula-$CARCH-linux")
sha256sums=("%%SHA256SUM%%")

package() {
mv caligula-x86_64-linux caligula
install -Dm755 caligula -t "$pkgdir/usr/bin"
}
'';

srcinfo = ''
pkgbase = caligula-bin
pkgdesc = ${pkgdesc}
pkgver = ${caligula.version}
pkgrel = ${pkgrel}
url = https://github.com/ifd3f/caligula
arch = x86_64
license = GPL-3.0
provides = caligula
conflicts = caligula
source = https://github.com/ifd3f/caligula/releases/download/v${caligula.version}/caligula-x86_64-linux
sha256sums = %%SHA256SUM%%

pkgname = caligula-bin
'';
in runCommand "caligula-bin-aur" { inherit srcinfo pkgbuild; } ''
sha256=$(sha256sum ${caligula}/bin/caligula | awk '{print $1}')

mkdir -p $out
echo "$srcinfo" | sed "s/%%SHA256SUM%%/$sha256/" > $out/.SRCINFO
echo "$pkgbuild" | sed "s/%%SHA256SUM%%/$sha256/" > $out/PKGBUILD
''
2 changes: 0 additions & 2 deletions packaging/aur/.gitignore

This file was deleted.

14 changes: 1 addition & 13 deletions packaging/aur/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
rootdir=$(shell pwd)

.PHONY: main
main: inputs dockerimage build caligula-bin
docker run --rm -it -v $(rootdir)/inputs:/inputs:ro -v $(rootdir)/caligula-bin:/caligula-bin caligula-packaging

caligula-bin:
git clone ssh://[email protected]/caligula-bin.git

.PHONY: dockerimage
dockerimage: dockerenv
docker build -t caligula-packaging $<

build:
mkdir -p build
docker build -t caligula-aur-packager $<
8 changes: 5 additions & 3 deletions packaging/aur/dockerenv/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM archlinux

RUN pacman -Syu --noconfirm \
python3 \
base-devel \
rust \
sudo

RUN useradd -m user
RUN useradd -m -G wheel user
RUN echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

COPY entrypoint.sh /entrypoint.sh
COPY tools /tools

ENTRYPOINT [ "/entrypoint.sh" ]
ENTRYPOINT [ "/tools/entrypoint.py" ]
11 changes: 0 additions & 11 deletions packaging/aur/dockerenv/entrypoint.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# pkgver, pkgrel, and sha256sums are inserted by script.

pkgname=caligula-bin
pkgver=0.3.0
pkgrel=1
pkgdesc="A lightweight, user-friendly disk imaging tool"
url="https://github.com/ifd3f/caligula"
license=("GPL-3.0")
arch=("x86_64")
provides=("caligula")
conflicts=("caligula")
source=("https://github.com/ifd3f/caligula/releases/download/v$pkgver/caligula-$CARCH-linux")
sha256sums=("ae1dda2649d7c9152b032b8ded1623bef8705296ea11d6060471ff3f63aa1046")

package() {
mv caligula-x86_64-linux caligula
Expand Down
110 changes: 110 additions & 0 deletions packaging/aur/dockerenv/tools/entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env python3

import argparse
import shutil
import subprocess
import logging

from pathlib import Path
from typing import Optional


tools_dir = Path(__file__).resolve().parent


def arg_parser():
parser = argparse.ArgumentParser(
description="Caligula AUR packaging script",
)

parser.add_argument(
"out_dir",
help="Output directory for the PKGBUILD files. Everything here will be clobbered!",
)
parser.add_argument(
"--sha256sum", required=True, help="SHA256SUM of x86_64-linux executable"
)
parser.add_argument(
"--pkgver",
required=True,
help="Version number of the package without the leading v.",
)
parser.add_argument(
"--pkgrel",
required=True,
help="Sequential release number to distinguish between same builds of different versions. Usually set to 1.",
)

return parser


def main():
args = arg_parser().parse_args()
assert args.pkgver[0] != "v", "pkgver must not start with leading v"
out_dir = Path(args.out_dir).resolve()
logging.basicConfig(
level=logging.DEBUG,
format="----- %(asctime)s [%(levelname)s] %(message)s",
)

logging.info(f"Cleaning {out_dir}")
out_dir.mkdir(parents=True, exist_ok=True)
for c in out_dir.iterdir():
shutil.rmtree(c)

# TODO: make a non-bin PKGBUILD and run that too
write_bin_pkgbuild(args, out_dir / "caligula-bin", "caligula-bin")
run_makepkg(out_dir / "caligula-bin")
test_caligula()


def write_bin_pkgbuild(args, out_dir: Path, target_name: str):
template_path = tools_dir / f"{target_name}.PKGBUILD"
target_path = out_dir / "PKGBUILD"

logging.info(f"templating {template_path} into {target_path}")

with template_path.open() as f:
template = f.read()

target_path.parent.mkdir(parents=True, exist_ok=True)
with target_path.open("w") as f:
f.write(f'sha256sums=("{args.sha256sum}")\n')
f.write(f"pkgver={args.pkgver}\n")
f.write(f"pkgrel={args.pkgrel}\n")
f.write(template)


def run_makepkg(pkgbuild_dir: Path, makepkguser="user"):
run_shell(f"chown -R {makepkguser} {pkgbuild_dir}")

logging.info(f"generating .SRCINFO in {pkgbuild_dir}")
run_shell(
f"sudo -u {makepkguser} makepkg --printsrcinfo > .SRCINFO",
cwd=pkgbuild_dir,
)

logging.info(f"executing makepkg --install")
run_shell(
f"yes | sudo -u {makepkguser} makepkg --install",
cwd=pkgbuild_dir,
)


def test_caligula():
logging.info("Testing if we can run caligula")
run_shell("caligula --version")


def run_shell(cmd: str, cwd: Optional[str] = None):
logging.debug(f"Running shell command: {cmd}")
subprocess.run(
cmd,
shell=True,
cwd=cwd,
check=True,
)


if __name__ == "__main__":
main()