110 lines
4.3 KiB
YAML
110 lines
4.3 KiB
YAML
name: Build and Release .deb
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-deb:
|
|
runs-on: [docker]
|
|
steps:
|
|
- name: Checkout
|
|
env:
|
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
run: |
|
|
git clone "http://x-access-token:${FORGEJO_TOKEN}@10.0.0.4:3000/geronzi/full_updater.git" /workspace/repo
|
|
cd /workspace/repo
|
|
git fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* || true
|
|
|
|
- name: Determine version
|
|
working-directory: /workspace/repo
|
|
env:
|
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
run: |
|
|
set -e
|
|
git checkout master || git checkout -b master origin/master
|
|
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 remote set-url origin "http://x-access-token:${FORGEJO_TOKEN}@10.0.0.4:3000/geronzi/full_updater.git"
|
|
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
|
|
working-directory: /workspace/repo
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
GIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
DATE=$(date -R)
|
|
cat > debian/changelog << 'CHANGELOG'
|
|
full-updater (${VERSION}) unstable; urgency=medium
|
|
|
|
* Auto-built release from commit ${GIT_SHA}
|
|
|
|
-- Forgejo CI <ci@geronzi.fr> ${DATE}
|
|
CHANGELOG
|
|
|
|
- name: Install build dependencies
|
|
working-directory: /workspace/repo
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y debhelper dh-python python3-all python3-venv devscripts
|
|
|
|
- name: Build .deb package
|
|
working-directory: /workspace/repo
|
|
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
|
|
working-directory: /workspace/repo
|
|
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\"}" \
|
|
"http://10.0.0.4:3000/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}" \
|
|
"http://10.0.0.4:3000/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}" \
|
|
"http://10.0.0.4:3000/api/v1/repos/geronzi/full_updater/releases/${RELEASE_ID}/assets?name=$(basename ${FILE})"
|
|
fi
|
|
|
|
- name: Store artifact
|
|
working-directory: /workspace/repo
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: full-updater-deb
|
|
path: /workspace/repo/dist/*.deb
|