89 lines
3.5 KiB
YAML
89 lines
3.5 KiB
YAML
name: Build and Release .deb
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-deb:
|
|
runs-on: [docker]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # nécessaire pour les tags et le versioning
|
|
|
|
- name: Determine version
|
|
id: version
|
|
run: |
|
|
set -e
|
|
if git describe --tags --exact-match HEAD 2>/dev/null; then
|
|
# Le commit actuel est déjà un tag
|
|
VERSION=$(git describe --tags --exact-match HEAD | sed 's/^v//')
|
|
else
|
|
# Incrémente le patch du dernier tag
|
|
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
VERSION_BASE=${LAST_TAG#v}
|
|
MAJOR=$(echo "$VERSION_BASE" | cut -d. -f1)
|
|
MINOR=$(echo "$VERSION_BASE" | cut -d. -f2)
|
|
PATCH=$(echo "$VERSION_BASE" | cut -d. -f3)
|
|
NEW_PATCH=$((PATCH + 1))
|
|
VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
|
|
# Créer un tag léger pour cette release
|
|
git config user.email "ci@geronzi.fr"
|
|
git config user.name "Forgejo CI"
|
|
git tag -a "v${VERSION}" -m "Release v${VERSION}"
|
|
git push origin "v${VERSION}" || true
|
|
fi
|
|
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "Detected version: ${VERSION}"
|
|
|
|
- name: Update debian changelog
|
|
run: |
|
|
VERSION=${{ steps.version.outputs.version }}
|
|
DATE=$(date -R)
|
|
printf '%s\n' "full-updater (${VERSION}) unstable; urgency=medium" "" " * Auto-built release from commit ${GITHUB_SHA}" "" " -- Forgejo CI <ci@geronzi.fr> ${DATE}" > debian/changelog
|
|
|
|
- name: Install build dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y debhelper dh-python python3-all python3-venv devscripts
|
|
|
|
- name: Build .deb package
|
|
run: |
|
|
dpkg-buildpackage -us -uc -b -tc
|
|
mkdir -p dist
|
|
cp ../*.deb dist/
|
|
# Renommer proprement
|
|
mv dist/full-updater_*.deb "dist/full-updater_${{ steps.version.outputs.version }}_all.deb"
|
|
|
|
- name: Upload release asset
|
|
env:
|
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
run: |
|
|
VERSION=${{ steps.version.outputs.version }}
|
|
TAG="v${VERSION}"
|
|
FILE="dist/full-updater_${VERSION}_all.deb"
|
|
# Créer la release si elle n'existe pas
|
|
curl -s -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\": \"${TAG}\", \"name\": \"Release ${TAG}\", \"body\": \"Automated build from main\"}" \
|
|
"https://git.geronzi.fr/api/v1/repos/geronzi/full_updater/releases" || true
|
|
# Récupérer l'ID de la release
|
|
RELEASE_ID=$(curl -s -H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
"https://git.geronzi.fr/api/v1/repos/geronzi/full_updater/releases/latest" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))")
|
|
if [ -n "$RELEASE_ID" ] && [ "$RELEASE_ID" != "None" ]; then
|
|
curl -s -X POST \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary @"${FILE}" \
|
|
"https://git.geronzi.fr/api/v1/repos/geronzi/full_updater/releases/${RELEASE_ID}/assets?name=$(basename ${FILE})"
|
|
fi
|
|
|
|
- name: Store artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: full-updater-deb
|
|
path: dist/*.deb
|