Files
ncpfs/.gitea/workflows/source-release.yml
Mario Fetka 6dcc4f69ef
All checks were successful
Source release / source-package (push) Successful in 2m22s
Delete old dev builds
2026-04-29 11:04:08 +02:00

349 lines
11 KiB
YAML

name: Source release
on:
push:
tags:
- "v*"
branches:
- master
workflow_dispatch:
jobs:
source-package:
runs-on: ubuntu-latest
env:
GITEA_API: https://gitea.disconnected-by-peer.at/api/v1
OWNER: mars_nwe
REPO: ncpfs
steps:
- name: Check out source
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.RELEASE_TOKEN }}
- name: Fetch tags explicitly
run: |
git fetch --force --tags
echo "describe:"
git describe --tags --long --match 'v*' --always || true
echo "exact tag:"
git describe --tags --exact-match || true
echo "points-at-head:"
git tag --points-at HEAD || true
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
autoconf \
automake \
autopoint \
gettext \
gettext-base \
make \
gcc \
g++ \
pkg-config \
curl \
jq \
php-dev \
php-cli \
libpam0g-dev
- name: Determine version
id: version
env:
REF_TYPE: ${{ gitea.ref_type || github.ref_type }}
REF_NAME: ${{ gitea.ref_name || github.ref_name }}
SHA: ${{ gitea.sha || github.sha }}
run: |
set -e
BASE_VERSION="$(sed -n 's/^AC_INIT(\[\[ncpfs\]\],\[\[\([^]]*\)\]\].*/\1/p' configure.ac)"
if [ -z "$BASE_VERSION" ]; then
echo "Could not determine version from configure.ac"
exit 1
fi
if [ "$REF_TYPE" = "tag" ]; then
VERSION="$BASE_VERSION"
DISTFILE="ncpfs-${VERSION}.tar.gz"
PREFIX="ncpfs-${VERSION}/"
else
DESCRIBE="$(git describe --tags --long --match 'v*' --always)"
COUNT="$(printf '%s' "$DESCRIBE" | sed -nE 's/^v?[0-9][^-]*-([0-9]+)-g[0-9a-f]+$/\1/p')"
GITID="$(printf '%s' "$DESCRIBE" | sed -nE 's/^v?[0-9][^-]*-[0-9]+-(g[0-9a-f]+)$/\1/p')"
if [ -z "$COUNT" ] || [ -z "$GITID" ]; then
COUNT="$(git rev-list --count HEAD)"
GITID="g$(printf '%s' "$SHA" | cut -c1-7)"
fi
VERSION="${BASE_VERSION}-dev.${COUNT}-${GITID}"
DISTFILE="ncpfs-${VERSION}.tar.gz"
PREFIX="ncpfs-${VERSION}/"
fi
echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "distfile=$DISTFILE" >> "$GITHUB_OUTPUT"
echo "prefix=$PREFIX" >> "$GITHUB_OUTPUT"
echo "Base version: $BASE_VERSION"
echo "Package version: $VERSION"
echo "Distfile: $DISTFILE"
echo "Prefix: $PREFIX"
- name: Regenerate configure files
run: |
set -e
aclocal
autoheader
autoconf
cd contrib/php
rm -rf autom4te.cache
rm -f configure config.h config.h.in config.log config.status config.cache Makefile Makevars libtool
phpize
cd ../..
- name: Configure
run: |
set -e
./configure --with-php-config="$(command -v php-config)"
- name: Build
run: |
set -e
make
- name: Clean build artifacts
run: |
set -e
make clean || true
rm -rf \
autom4te.cache \
.libs \
modules
rm -f \
Makefile \
Make.rules \
config.log \
config.status \
config.cache \
config.nice \
libtool \
stamp-h1
rm -rf \
contrib/php/autom4te.cache \
contrib/php/.deps \
contrib/php/.libs \
contrib/php/modules \
contrib/php/libs
rm -f \
contrib/php/Makefile \
contrib/php/Makefile.fragments \
contrib/php/Makefile.objects \
contrib/php/Makevars \
contrib/php/config.h \
contrib/php/config.log \
contrib/php/config.status \
contrib/php/config.cache \
contrib/php/config.nice \
contrib/php/config_vars.mk \
contrib/php/libs.mk \
contrib/php/libtool \
contrib/php/run-tests.php \
contrib/php/*.lo \
contrib/php/*.la \
contrib/php/*.o \
contrib/php/*.dep \
contrib/php/*.slo
find . \
\( -name '*.o' \
-o -name '*.do' \
-o -name '*.to' \
-o -name '*.lo' \
-o -name '*.la' \
-o -name '*.a' \
-o -name '*.so' \
-o -name '*.so.*' \
-o -name '*.dep' \
-o -name '*.gcno' \
-o -name '*.gcda' \
-o -name '*.orig' \
-o -name '*.rej' \
-o -name '*~' \) \
-delete
find man -name '*.gz' -delete 2>/dev/null || true
find ipx-1.0 -name '*.gz' -delete 2>/dev/null || true
test -f lib/libncp.vers
- name: Build source tarball
id: pkg
run: |
set -e
VERSION="${{ steps.version.outputs.version }}"
DISTFILE="${{ steps.version.outputs.distfile }}"
PREFIX="${{ steps.version.outputs.prefix }}"
git archive \
--format=tar \
--prefix="${PREFIX}" \
HEAD | gzip -9 > "../${DISTFILE}"
FILE="$(realpath "../${DISTFILE}")"
test -s "$FILE"
echo "file=$FILE" >> "$GITHUB_OUTPUT"
echo "name=$DISTFILE" >> "$GITHUB_OUTPUT"
echo "Created: $FILE"
tar -tzf "$FILE" > tarball-list.txt
sed -n '1,20p' tarball-list.txt
echo
echo "Checking archive exclusions..."
if grep -E '(^[^/]+/\.gitea/|^[^/]+/\.github/|^[^/]+/contrib/php/build/|^[^/]+/contrib/php/autom4te.cache/)' tarball-list.txt; then
echo "Archive contains excluded CI/build paths"
exit 1
fi
- name: Decide release target
id: target
env:
REF_TYPE: ${{ gitea.ref_type || github.ref_type }}
REF_NAME: ${{ gitea.ref_name || github.ref_name }}
SHA: ${{ gitea.sha || github.sha }}
run: |
set -e
if [ "$REF_TYPE" = "tag" ]; then
echo "tag=$REF_NAME" >> "$GITHUB_OUTPUT"
echo "name=$REF_NAME" >> "$GITHUB_OUTPUT"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
else
SHORT_SHA="$(printf '%s' "$SHA" | cut -c1-7)"
echo "tag=development" >> "$GITHUB_OUTPUT"
echo "name=development ($REF_NAME @ $SHORT_SHA)" >> "$GITHUB_OUTPUT"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
fi
- name: Create or update release
env:
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
REL_TAG: ${{ steps.target.outputs.tag }}
REL_NAME: ${{ steps.target.outputs.name }}
REL_PRERELEASE: ${{ steps.target.outputs.prerelease }}
run: |
set -e
RELEASE_JSON="$(curl -fsS \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases/tags/${REL_TAG}" || true)"
if [ -z "$RELEASE_JSON" ]; then
RELEASE_JSON="$(curl -fsS -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases" \
-d "$(jq -n \
--arg tag "$REL_TAG" \
--arg name "$REL_NAME" \
--argjson prerelease "$REL_PRERELEASE" \
'{tag_name:$tag,name:$name,draft:false,prerelease:$prerelease}')" )"
else
RELEASE_ID="$(printf '%s' "$RELEASE_JSON" | jq -r '.id')"
RELEASE_JSON="$(curl -fsS -X PATCH \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}" \
-d "$(jq -n \
--arg tag "$REL_TAG" \
--arg name "$REL_NAME" \
--argjson prerelease "$REL_PRERELEASE" \
'{tag_name:$tag,name:$name,draft:false,prerelease:$prerelease}')" )"
fi
echo "$RELEASE_JSON" > release.json
- name: Delete old development assets
if: ${{ steps.target.outputs.tag == 'development' }}
env:
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
set -e
RELEASE_ID="$(jq -r '.id' release.json)"
ASSET_IDS="$(curl -fsS \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}" \
| jq -r '.assets[]? | .id')"
if [ -z "$ASSET_IDS" ]; then
echo "No old development assets to delete."
exit 0
fi
for ASSET_ID in $ASSET_IDS; do
echo "Deleting old development asset id=${ASSET_ID}"
curl -fsS -X DELETE \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}"
done
- name: Delete old asset with same name if present
env:
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
NAME: ${{ steps.pkg.outputs.name }}
run: |
set -e
RELEASE_ID="$(jq -r '.id' release.json)"
ASSET_ID="$(curl -fsS \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}" \
| jq -r --arg NAME "$NAME" '.assets[]? | select(.name==$NAME) | .id' \
| head -n1)"
if [ -n "$ASSET_ID" ]; then
curl -fsS -X DELETE \
-H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}"
fi
- name: Upload tarball to release
env:
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
FILE: ${{ steps.pkg.outputs.file }}
NAME: ${{ steps.pkg.outputs.name }}
run: |
set -e
RELEASE_ID="$(jq -r '.id' release.json)"
curl -fsS -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"${FILE}" \
"${GITEA_API}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=${NAME}"