From 1f0cc10144ba1370f23bbcda2b50ebe4162c3a7a Mon Sep 17 00:00:00 2001 From: Alexander Sack Date: Sat, 17 Aug 2024 17:42:29 +0000 Subject: [PATCH] .github: add updaterelease workflow and scripts --- .github/scripts/makecommit | 104 +++++++++++++++++++++++++++ .github/scripts/makemachines | 32 +++++++++ .github/workflows/buildkas.yaml | 2 +- .github/workflows/onpush.yaml | 3 + .github/workflows/onschedule.yaml | 9 +++ .github/workflows/updaterelease.yaml | 28 ++++++++ kas/bsp-base.yaml | 1 + kas/sourcedir.yaml | 5 ++ 8 files changed, 183 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/makecommit create mode 100755 .github/scripts/makemachines create mode 100644 .github/workflows/onschedule.yaml create mode 100644 .github/workflows/updaterelease.yaml create mode 100644 kas/sourcedir.yaml diff --git a/.github/scripts/makecommit b/.github/scripts/makecommit new file mode 100755 index 0000000..08dbfac --- /dev/null +++ b/.github/scripts/makecommit @@ -0,0 +1,104 @@ +#!/bin/sh + +git add .github/configs/release/ +set -x + +changed=`git diff HEAD | lsdiff | sed 's/.\///'` + +if [ -z "$changed" ]; then + echo "NO changes" + exit 0 +fi + +echo "Changes: $changed" + +gitdirs=$PWD/.github/git-dirs/ +mkdir -p $gitdirs + +commitmsg=`mktemp -t commitmsg.XXXXXXX` + +echo "" > $commitmsg + +echo_cm(){ + echo "$@" >> $commitmsg +} + +for change in $changed; do + original=$change.orig + git diff HEAD -- $change | patch -f -R -p1 -s -o $original + removed= + if [ -f $change ]; then + repos=`cat $change | yq ".repos | keys()[]"` + else + repos=`cat $original | yq ".repos | keys()[]"` + removed=yes + fi + + change_listed= + + for repo in $repos; do + repourl=null + repocommit=null + if [ -f $change ]; then + repourl=`cat $change | yq ".repos.$repo.url"` + repocommit=`cat $change | yq ".repos.$repo.commit"` + fi + repourlorig=null + repocommitorig=null + if [ -f $original ]; then + repourlorig=`cat $original | yq ".repos.$repo.url"` + repocommitorig=`cat $original | yq ".repos.$repo.commit"` + fi + + if [ -n "$repocommit" -a "$repocommit" = "$repocommitorig" ]; then + echo "$change/$repo: no change" + continue + fi + set -x + if [ -z "$change_listed" ]; then + echo_cm "== $change${removed:+ (REMOVED)}==" + change_listed=yes + echo_cm + fi + echo_cm " $repo:" + echo_cm + + origdir=$PWD + export GIT_DIR=$gitdirs/$repo + + if [ "$repocommitorig" = "null" ]; then + echo_cm " Adding repo $repo from $repourl" + echo_cm " commit $repocommit" + echo_cm + elif [ "$repocommit" = "null" ]; then + echo_cm " Removing repo $repo from $repourlorig" + echo_cm " commit $repocommitorig" + echo_cm + else + gittemp=`mktemp -t -d gittemp.XXXXXX` + echo_cm " Changed repo $repourlorig => $repourl" + echo_cm " commit $repocommitorig => $repocommit" + cd $gittemp + git init + git remote remove current + git remote remove orig + git remote add current $repourl + git remote add orig $repourlorig + git fetch --all -v + git log --oneline $repocommitorig..$repocommit | sed 's/^/ * /' >> $commitmsg + echo_cm + cd $origdir + rm -rf $gittemp + fi + unset GIT_DIR + done +done + +echo "Commit msg:" +cat $commitmsg +set -x +pwd +git diff +git commit -a -F $commitmsg +rm -f $commitmsg + diff --git a/.github/scripts/makemachines b/.github/scripts/makemachines new file mode 100755 index 0000000..3901b80 --- /dev/null +++ b/.github/scripts/makemachines @@ -0,0 +1,32 @@ +#!/bin/sh + +targetdir=$1 + +m=`ls kas/machines/*` +configsuffix=:.github/configs/build-base-remix.yaml:.github/configs/shared-vols.yaml + +configs=" \ + kas/machines/sunxi-orange-pi-3lts.yaml:kas/bsp-base.yaml:kas/scarthgap.yaml$configsuffix \ + kas/machines/sunxi-orange-pi-r1.yaml:kas/bsp-base.yaml:kas/scarthgap.yaml$configsuffix \ + kas/machines/sunxi-nanopi-r1.yaml:kas/bsp-base.yaml:kas/scarthgap.yaml$configsuffix \ + kas/machines/imx8qxpc0mek.yaml:kas/bsp-base.yaml:kas/scarthgap.yaml:kas/scarthgap-nxp.yaml$configsuffix \ + kas/machines/raspberrypi-armv8.yaml:kas/bsp-base.yaml:kas/scarthgap.yaml$configsuffix \ +" + +echo "Processing configs: + +$configs" + +rm -f .github/configs/release/*-scarthgap.yaml + +for cc in $configs; do + echo CC: $cc + m=`echo $cc | sed 's/.*machines.//;s/.yaml:.*//'` + KAS_WORK_DIR=. kas dump --resolve-refs "kas/sourcedir.yaml:$sourceyaml:$cc" > .github/configs/release/$m-scarthgap.yaml + echo "new config for machine: $m" + cat .github/configs/release/$m-scarthgap.yaml +done + +git add .github/configs/release/ + + diff --git a/.github/workflows/buildkas.yaml b/.github/workflows/buildkas.yaml index 8916ee3..1c75a6a 100644 --- a/.github/workflows/buildkas.yaml +++ b/.github/workflows/buildkas.yaml @@ -14,7 +14,7 @@ jobs: build-kas: runs-on: ["self-hosted"] container: - image: ghcr.io/pantacor/kas/kas:next-v2 + image: ghcr.io/pantacor/kas/kas:next-v3 volumes: - shared:/shared options: --user root diff --git a/.github/workflows/onpush.yaml b/.github/workflows/onpush.yaml index 1a34458..fbe818b 100644 --- a/.github/workflows/onpush.yaml +++ b/.github/workflows/onpush.yaml @@ -2,6 +2,9 @@ name: 'Build On Push' on: push: + paths-ignore: + - '.github/scripts/**' + - '.github/workflows/updaterelease.yaml' jobs: remix-sunxi-orange-pi-3lts-remix-scarthgap: diff --git a/.github/workflows/onschedule.yaml b/.github/workflows/onschedule.yaml new file mode 100644 index 0000000..3ddf1cf --- /dev/null +++ b/.github/workflows/onschedule.yaml @@ -0,0 +1,9 @@ +name: Do things every 4 hours +on: + schedule: + - cron: "1 */4 * * *" + +jobs: + update-release-machines: + uses: ./.github/workflows/updaterelease.yaml + diff --git a/.github/workflows/updaterelease.yaml b/.github/workflows/updaterelease.yaml new file mode 100644 index 0000000..b75e033 --- /dev/null +++ b/.github/workflows/updaterelease.yaml @@ -0,0 +1,28 @@ +name: 'Update Release Machines' + +on: + workflow_call: + + push: + paths: + - .github/scripts/** + - .github/workflows/updaterelease.yaml + +jobs: + updaterelease: + runs-on: ["self-hosted"] + container: + image: ghcr.io/pantacor/kas/kas:next-v3 + volumes: + - shared:/shared + options: --user root + steps: + - uses: actions/checkout@v4 + - run: ls .github/scripts + - run: pwd + - run: .github/scripts/makemachines + - run: git config --global user.email "pantavisor-meta@ci.pantavisor.io" + - run: git config --global user.name "Pantavisor Meta Layer CI" + - run: .github/scripts/makecommit + - run: git push + diff --git a/kas/bsp-base.yaml b/kas/bsp-base.yaml index 4ea6b32..9b13487 100644 --- a/kas/bsp-base.yaml +++ b/kas/bsp-base.yaml @@ -9,6 +9,7 @@ header: target: pantavisor-bsp build_system: oe +_source_dir: . repos: meta-pantavisor: diff --git a/kas/sourcedir.yaml b/kas/sourcedir.yaml new file mode 100644 index 0000000..04f1347 --- /dev/null +++ b/kas/sourcedir.yaml @@ -0,0 +1,5 @@ +header: + version: 16 + +_source_dir: . +