From 6b84d824fef6cf65b436a77aa34cf6d1deb111c0 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 15 Aug 2024 21:59:24 -0400 Subject: [PATCH] forgejo-ci: initial --- .forgejo/bin/deploy.sh | 25 ++++++++++ .forgejo/patches/build.patch | 80 ++++++++++++++++++++++++++++++ .forgejo/workflows/build-edge.yaml | 51 +++++++++++++++++++ .forgejo/workflows/lint.yaml | 21 ++++++++ 4 files changed, 177 insertions(+) create mode 100755 .forgejo/bin/deploy.sh create mode 100644 .forgejo/patches/build.patch create mode 100644 .forgejo/workflows/build-edge.yaml create mode 100644 .forgejo/workflows/lint.yaml diff --git a/.forgejo/bin/deploy.sh b/.forgejo/bin/deploy.sh new file mode 100755 index 0000000..db6d45d --- /dev/null +++ b/.forgejo/bin/deploy.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# shellcheck disable=SC3040 +set -eu -o pipefail + +readonly BASEBRANCH=$(grep PRETTY_NAME /etc/os-release | awk '{print $3}' | tr -d '"') +readonly TARGET_REPO=$CI_ALPINE_REPO + +apkgs=$(find package -type f -name "*.apk") + +for apk in $apkgs; do + branch=$(echo $apk | awk -F '/' '{print $2}') + arch=$(echo $apk | awk -F '/' '{print $3}') + name=$(echo $apk | awk -F '/' '{print $4}') + + echo "Sending $name of arch $arch to $TARGET_REPO/$BASEBRANCH/$branch" + return=$(curl -s --user $FORGE_REPO_USER:$FORGE_REPO_TOKEN --upload-file $apk $TARGET_REPO/$BASEBRANCH/$branch 2>&1) + echo $return + if [ "$return" == "package file already exists" ]; then + echo "Package already exists, refreshing..." + curl -s --user $FORGE_REPO_USER:$FORGE_REPO_TOKEN -X DELETE $TARGET_REPO/$BASEBRANCH/$branch/$arch/$name + curl -s --user $FORGE_REPO_USER:$FORGE_REPO_TOKEN --upload-file $apk $TARGET_REPO/$BASEBRANCH/$branch + fi +done + diff --git a/.forgejo/patches/build.patch b/.forgejo/patches/build.patch new file mode 100644 index 0000000..8411df6 --- /dev/null +++ b/.forgejo/patches/build.patch @@ -0,0 +1,80 @@ +diff --git a/usr/local/bin/build.sh.orig b/usr/local/bin/build.sh +old mode 100644 +new mode 100755 +index c3b8f7a..dc5d72b +--- a/usr/local/bin/build.sh.orig ++++ b/usr/local/bin/build.sh +@@ -7,13 +7,15 @@ + set -eu -o pipefail + + readonly APORTSDIR=$CI_PROJECT_DIR +-readonly REPOS="main community testing non-free" ++readonly ALPINE_REPOS="main community testing" + readonly ARCH=$(apk --print-arch) + # gitlab variables + readonly BASEBRANCH=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME ++readonly REPOS="qubes-$BASEBRANCH" + + : "${REPODEST:=$HOME/packages}" +-: "${MIRROR:=https://dl-cdn.alpinelinux.org/alpine}" ++: "${MIRROR:=https://lab.ilot.io/ayakael/repo-apk/-/raw}" ++: "${ALPINE_MIRROR:=http://dl-cdn.alpinelinux.org/alpine}" + : "${MAX_ARTIFACT_SIZE:=300000000}" #300M + : "${CI_DEBUG_BUILD:=}" + +@@ -67,13 +69,21 @@ report() { + } + + get_release() { ++ grep PRETTY_NAME /etc/os-release | awk '{print $3}' | tr -d '"' ++} ++ ++get_qubes_release() { + case $BASEBRANCH in +- *-stable) echo v"${BASEBRANCH%-*}";; +- master) echo edge;; +- *) die "Branch \"$BASEBRANCH\" not supported!" ++ r*) echo $BASEBRANCH;; ++ main) echo r4.3;; + esac + } + ++# hack to support at-root packages ++changed_repos() ++ echo "." ++{ ++ + build_aport() { + local repo="$1" aport="$2" + cd "$APORTSDIR/$repo/$aport" +@@ -101,11 +111,11 @@ set_repositories_for() { + release=$(get_release) + for repo in $REPOS; do + [ "$repo" = "non-free" ] && continue +- [ "$release" != "edge" ] && [ "$repo" == "testing" ] && continue ++ [ "$release" == "edge" ] && [ "$repo" == "backports" ] && continue + repos="$repos $MIRROR/$release/$repo $REPODEST/$repo" + [ "$repo" = "$target_repo" ] && break + done +- doas sh -c "printf '%s\n' $repos > /etc/apk/repositories" ++ doas sh -c "printf '%s\n' $repos >> /etc/apk/repositories" + doas apk update + } + +@@ -118,7 +128,15 @@ apply_offset_limit() { + } + + setup_system() { +- doas sh -c "echo $MIRROR/$(get_release)/main > /etc/apk/repositories" ++ local repos='' repo='' ++ local release ++ ++ release=$(get_release) ++ for repo in $ALPINE_REPOS; do ++ [ "$release" != "edge" ] && [ "$repo" == "testing" ] && continue ++ repos="$repos $ALPINE_MIRROR/$release/$repo" ++ done ++ doas sh -c "printf '%s\n' $repos > /etc/apk/repositories" + doas apk -U upgrade -a || apk fix || die "Failed to up/downgrade system" + abuild-keygen -ain + doas sed -i -E 's/export JOBS=[0-9]+$/export JOBS=$(nproc)/' /etc/abuild.conf diff --git a/.forgejo/workflows/build-edge.yaml b/.forgejo/workflows/build-edge.yaml new file mode 100644 index 0000000..a9d5757 --- /dev/null +++ b/.forgejo/workflows/build-edge.yaml @@ -0,0 +1,51 @@ +on: + pull_request: + types: [ assigned, opened, synchronize, reopened ] + +jobs: + build-edge: + runs-on: edge + container: + image: alpinelinux/alpine-gitlab-ci:latest + env: + CI_PROJECT_DIR: ${{ github.workspace }} + CI_DEBUG_BUILD: ${{ runner.debug }} + CI_MERGE_REQUEST_PROJECT_URL: ${{ github.server_url }}/${{ github.repository }} + CI_MERGE_REQUEST_TARGET_BRANCH_NAME: ${{ github.base_ref }} + steps: + - name: Environment setup + run: | + doas apk add nodejs git patch + doas wget -P /etc/apk/keys 'https://ayakael.net/pkgs/apk/raw/branch/edge/antoine.martin@protonmail.com-5b3109ad.rsa.pub' + - name: Repo pull + uses: actions/checkout@v4 + with: + fetch-depth: 500 + - name: Package build + run: | + doas patch -d / -p1 -i ${{ github.workspace }}/.forgejo/patches/build.patch + build.sh + - name: Package upload + uses: forgejo/upload-artifact@v3 + with: + name: package + path: packages + + deploy-edge: + needs: [build-edge] + runs-on: x86_64 + container: + image: alpine:latest + env: + CI_ALPINE_REPO: 'https://ayakael.net/api/packages/forge/alpine' + FORGE_REPO_TOKEN: ${{ secrets.FORGE_REPO_TOKEN }} + FORGE_REPO_USER: ${{ vars.FORGE_REPO_USER }} + steps: + - name: Setting up environment + run: apk add nodejs curl findutils git gawk + - name: Repo pull + uses: actions/checkout@v4 + - name: Package download + uses: forgejo/download-artifact@v3 + - name: Package deployment + run: ${{ github.workspace }}/.forgejo/bin/deploy.sh diff --git a/.forgejo/workflows/lint.yaml b/.forgejo/workflows/lint.yaml new file mode 100644 index 0000000..3614deb --- /dev/null +++ b/.forgejo/workflows/lint.yaml @@ -0,0 +1,21 @@ +on: + pull_request: + types: [ assigned, opened, synchronize, reopened ] + +jobs: + lint: + run-name: lint + runs-on: x86_64 + container: + image: alpinelinux/apkbuild-lint-tools:latest + env: + CI_PROJECT_DIR: ${{ github.workspace }} + CI_DEBUG_BUILD: ${{ runner.debug }} + CI_MERGE_REQUEST_PROJECT_URL: ${{ github.server_url }}/${{ github.repository }} + CI_MERGE_REQUEST_TARGET_BRANCH_NAME: ${{ github.base_ref }} + steps: + - run: doas apk add nodejs git + - uses: actions/checkout@v4 + with: + fetch-depth: 500 + - run: lint