Merge each upstream release and build an amd64 .deb in Gitea Actions
This commit is contained in:
1 parent
233dfc813c
commit
a81f596217
3 files changed
+251
No files matched your search
@@ -0,0 +1,130 @@
|
||||
# Pull each new upstream MeshTerm release into main, then build the amd64 .deb and attach
|
||||
# it to a release on this server.
|
||||
#
|
||||
# The newest upstream tag vX.Y.Z is the release. When main does not contain it yet, the
|
||||
# job merges the tag, runs the tests, and pushes main. When the release fork-vX.Y.Z does
|
||||
# not exist yet, the job builds the package from main and makes that release. So a run
|
||||
# that failed after the merge builds again on the next run.
|
||||
#
|
||||
# A merge conflict stops the job. Merge that tag by hand and push. The next run builds.
|
||||
#
|
||||
# Secrets (optional): SYNC_TOKEN, a token with write access to this repository, used in
|
||||
# place of the automatic token (for example when main is protected).
|
||||
#
|
||||
# Note: Gitea reads only .gitea/workflows when it exists, so the upstream workflows in
|
||||
# .github/workflows do not run on this server.
|
||||
|
||||
name: Upstream release
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "17 */6 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: upstream-release
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
sync-and-build:
|
||||
runs-on: ubuntu-latest
|
||||
container: debian:trixie
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
LANG: C.UTF-8
|
||||
UPSTREAM: https://github.com/jpmartineau/MeshTerm.git
|
||||
TOKEN: ${{ secrets.SYNC_TOKEN || gitea.token }}
|
||||
SERVER: ${{ gitea.server_url }}
|
||||
REPO: ${{ gitea.repository }}
|
||||
steps:
|
||||
- name: Install the tools
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
git ca-certificates curl jq dpkg-dev \
|
||||
python3 python3-venv python3-dev gcc libc6-dev
|
||||
|
||||
- name: Clone and fetch upstream
|
||||
run: |
|
||||
host=${SERVER#*://}
|
||||
git clone "https://ci:${TOKEN}@${host}/${REPO}.git" src
|
||||
cd src
|
||||
git config user.name "MeshTerm upstream sync"
|
||||
git config user.email "actions@${host%%/*}"
|
||||
git remote add upstream "$UPSTREAM"
|
||||
git fetch --quiet --tags upstream
|
||||
|
||||
- name: Find the newest upstream release
|
||||
id: find
|
||||
working-directory: src
|
||||
run: |
|
||||
tag=$(git tag -l 'v[0-9]*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)
|
||||
[ -n "$tag" ] || { echo "no upstream release tag"; exit 1; }
|
||||
if git merge-base --is-ancestor "$tag" HEAD; then merged=true; else merged=false; fi
|
||||
status=$(curl -s -o /dev/null -w '%{http_code}' --max-time 30 \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
"$SERVER/api/v1/repos/$REPO/releases/tags/fork-$tag")
|
||||
if [ "$status" = 200 ]; then released=true; else released=false; fi
|
||||
echo "upstream $tag, merged=$merged, released=$released"
|
||||
{
|
||||
echo "tag=$tag"
|
||||
echo "merged=$merged"
|
||||
echo "released=$released"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Merge the release
|
||||
if: steps.find.outputs.merged == 'false'
|
||||
working-directory: src
|
||||
run: |
|
||||
tag=${{ steps.find.outputs.tag }}
|
||||
if ! git merge --no-ff --no-edit -m "Merge upstream MeshTerm ${tag#v}" "$tag"; then
|
||||
echo "::error::merge of $tag has conflicts. Merge it by hand and push main."
|
||||
git diff --name-only --diff-filter=U
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Run the tests
|
||||
if: steps.find.outputs.merged == 'false'
|
||||
working-directory: src
|
||||
run: |
|
||||
python3 -m venv /tmp/venv
|
||||
/tmp/venv/bin/pip install --quiet --upgrade pip
|
||||
/tmp/venv/bin/pip install --quiet -e '.[dev]'
|
||||
/tmp/venv/bin/python -m pytest -q -x
|
||||
|
||||
- name: Push main
|
||||
if: steps.find.outputs.merged == 'false'
|
||||
working-directory: src
|
||||
run: git push origin HEAD:main
|
||||
|
||||
- name: Build the package
|
||||
if: steps.find.outputs.released == 'false'
|
||||
working-directory: src
|
||||
run: sh scripts/linux-amd64/build-deb.sh 1
|
||||
|
||||
- name: Make the release
|
||||
if: steps.find.outputs.released == 'false'
|
||||
working-directory: src
|
||||
run: |
|
||||
tag=${{ steps.find.outputs.tag }}
|
||||
rel="fork-$tag"
|
||||
cd dist
|
||||
deb=$(ls meshterm_*_amd64.deb)
|
||||
sha256sum "$deb" > "$deb.sha256"
|
||||
cat "$deb.sha256"
|
||||
cd ..
|
||||
git tag -f "$rel" HEAD
|
||||
git push -f origin "refs/tags/$rel"
|
||||
body=$(jq -n --arg t "$rel" --arg c "$(git rev-parse HEAD)" --arg u "$tag" \
|
||||
'{tag_name:$t, target_commitish:$c, name:("MeshTerm " + ($u|ltrimstr("v")) + " (fork)"),
|
||||
body:("Upstream " + $u + " merged into main, built for amd64 Debian 13.")}')
|
||||
id=$(curl -sf --max-time 60 -X POST -H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/json" -d "$body" \
|
||||
"$SERVER/api/v1/repos/$REPO/releases" | jq -r .id)
|
||||
[ -n "$id" ] && [ "$id" != null ] || { echo "release was not made"; exit 1; }
|
||||
for f in "dist/$deb" "dist/$deb.sha256"; do
|
||||
curl -sf --max-time 300 -X POST -H "Authorization: token $TOKEN" \
|
||||
-F "attachment=@$f" \
|
||||
"$SERVER/api/v1/repos/$REPO/releases/$id/assets?name=$(basename "$f")" >/dev/null
|
||||
echo "attached $(basename "$f")"
|
||||
done
|
||||
@@ -7,6 +7,8 @@ dist/
|
||||
|
||||
# Ignore all dot-directories (.venv, .pytest_cache, .ruff_cache, .vscode, ...)
|
||||
.*/
|
||||
# ...except the Gitea Actions workflows of this fork.
|
||||
!.gitea/
|
||||
# ...except the project's tracked Claude config. Private working notes stay out:
|
||||
# settings.local.json is per-machine, and plans/ + housekeeping.md are internal
|
||||
# planning that names hardware and unshipped ideas.
|
||||
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# build-deb -- build the Debian package of MeshTerm for an amd64 Linux desktop.
|
||||
#
|
||||
# Usage: scripts/linux-amd64/build-deb.sh [REVISION]
|
||||
#
|
||||
# Run it on amd64 Debian 13 ("Trixie") with Python 3.13, for example in a debian:trixie
|
||||
# container. The package holds compiled code, so it must be built on the system that it
|
||||
# is for. The CI workflow .gitea/workflows/upstream-release.yml runs it.
|
||||
#
|
||||
# The package depends only on python3. All else is inside it:
|
||||
#
|
||||
# /usr/lib/meshterm/site MeshTerm and its Python packages, compiled to bytecode
|
||||
# /usr/bin/meshterm the command line and the TUI
|
||||
# /usr/share/doc/meshterm/ LICENSE, NOTICE, THIRD-PARTY-NOTICES.txt, and copyright
|
||||
#
|
||||
# REVISION is the Debian revision, 1 by default. Use letters, digits, ".", "+" and "~".
|
||||
set -eu
|
||||
umask 022
|
||||
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
SOURCE=$(cd "$HERE/../.." && pwd)
|
||||
REVISION=${1:-1}
|
||||
PYTHON=/usr/bin/python3
|
||||
ARCH=amd64
|
||||
|
||||
die() {
|
||||
echo "build-deb: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
command -v dpkg-deb >/dev/null || die "no dpkg-deb here. Run this on Debian."
|
||||
[ "$(dpkg --print-architecture)" = "$ARCH" ] || die "this is not $ARCH. The package holds $ARCH code."
|
||||
[ "$("$PYTHON" -c 'import sys; print("%d.%d" % sys.version_info[:2])')" = 3.13 ] ||
|
||||
die "$PYTHON is not Python 3.13. The package is for Debian 13."
|
||||
case "$REVISION" in
|
||||
"" | [!0-9A-Za-z]* | *[!0-9A-Za-z.+~]*) die "the revision '$REVISION' is not a valid Debian revision" ;;
|
||||
esac
|
||||
|
||||
VERSION=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' "$SOURCE/meshterm/__init__.py")
|
||||
[ -n "$VERSION" ] || die "no __version__ in $SOURCE/meshterm/__init__.py"
|
||||
DEB_VERSION="$VERSION-$REVISION"
|
||||
|
||||
WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
STAGE="$WORK/root"
|
||||
LIB="$STAGE/usr/lib/meshterm"
|
||||
DOC="$STAGE/usr/share/doc/meshterm"
|
||||
|
||||
echo "building meshterm $DEB_VERSION ($ARCH) from $SOURCE"
|
||||
|
||||
# A venv for the tools of the build only. Its base is the system Python, so the compiled
|
||||
# packages that its pip builds are correct for the Python that runs them.
|
||||
"$PYTHON" -m venv "$WORK/venv"
|
||||
"$WORK/venv/bin/pip" install --quiet --upgrade pip packaging
|
||||
|
||||
# MeshTerm and its packages. --no-compile, because the bytecode is compiled below.
|
||||
"$WORK/venv/bin/pip" install --quiet --no-compile --target "$LIB/site" "$SOURCE"
|
||||
rm -rf "$LIB/site/bin"
|
||||
|
||||
# The licences: MeshTerm's own, and the licence of each package in the site directory.
|
||||
mkdir -p "$DOC"
|
||||
cp "$SOURCE/LICENSE" "$SOURCE/NOTICE" "$DOC/"
|
||||
"$WORK/venv/bin/python" "$SOURCE/packaging/notices.py" "$DOC/THIRD-PARTY-NOTICES.txt" "$LIB/site"
|
||||
cat >"$DOC/copyright" <<EOF
|
||||
MeshTerm $VERSION
|
||||
Source: https://github.com/jpmartineau/MeshTerm
|
||||
|
||||
MeshTerm is licensed under the Apache License, Version 2.0. Refer to LICENSE and NOTICE in
|
||||
this directory. The name "MeshTerm" and its logo are trademarks. NOTICE has the terms.
|
||||
|
||||
The Python packages in /usr/lib/meshterm/site have their own licences. Refer to
|
||||
THIRD-PARTY-NOTICES.txt in this directory.
|
||||
|
||||
This package is a build of a fork of MeshTerm. It is not an official release.
|
||||
EOF
|
||||
|
||||
# Bytecode. The user cannot write in /usr/lib, so Python cannot cache bytecode there.
|
||||
"$PYTHON" -m compileall -q -j 0 --invalidation-mode unchecked-hash "$LIB/site" >/dev/null
|
||||
|
||||
# The wrapper. -s keeps the packages of the user's own site directory out.
|
||||
mkdir -p "$STAGE/usr/bin"
|
||||
cat >"$STAGE/usr/bin/meshterm" <<'EOF'
|
||||
#!/bin/sh
|
||||
# MeshTerm's command line and TUI.
|
||||
export PYTHONPATH=/usr/lib/meshterm/site
|
||||
exec /usr/bin/python3 -s -m meshterm "$@"
|
||||
EOF
|
||||
chmod 755 "$STAGE/usr/bin/meshterm"
|
||||
|
||||
# Make sure that the bundle runs before it is packaged.
|
||||
check() {
|
||||
MESHTERM_HOME="$WORK/home" PYTHONPATH="$LIB/site" "$PYTHON" -s "$@" >/dev/null
|
||||
}
|
||||
check -m meshterm --help
|
||||
check -m meshterm contacts --help
|
||||
check -m meshterm specimen
|
||||
|
||||
mkdir -p "$STAGE/DEBIAN"
|
||||
cat >"$STAGE/DEBIAN/control" <<EOF
|
||||
Package: meshterm
|
||||
Version: $DEB_VERSION
|
||||
Architecture: $ARCH
|
||||
Maintainer: ${DEB_MAINTAINER:-MeshTerm fork build <noreply@localhost>}
|
||||
Installed-Size: $(du -sk "$STAGE" | cut -f1)
|
||||
Depends: python3 (>= 3.13), python3 (<< 3.14)
|
||||
Suggests: python3-tk
|
||||
Section: hamradio
|
||||
Priority: optional
|
||||
Homepage: https://meshterm.net
|
||||
Description: full-featured TUI MeshCore client for the terminal
|
||||
MeshTerm is a full-featured TUI MeshCore client. It connects to a companion
|
||||
over USB, Bluetooth, or TCP. This is a build of a fork, not an official release.
|
||||
EOF
|
||||
|
||||
mkdir -p "$SOURCE/dist"
|
||||
OUT="$SOURCE/dist/meshterm_${DEB_VERSION}_${ARCH}.deb"
|
||||
dpkg-deb --root-owner-group -Zxz --build "$STAGE" "$OUT" >/dev/null
|
||||
echo "built $OUT ($(du -h "$OUT" | cut -f1))"
|
||||
Reference in new issue
Block a user