diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 0dcefde..f568a4c 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -11,6 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 0 - uses: actions/setup-python@v5 with: @@ -52,7 +54,7 @@ jobs: ls -la dist tar -tzf "dist/SDSAT-${{ gitea.ref_name }}.tar.gz" | head -n 50 - - name: Create Gitea release (and upload asset) + - name: Create Gitea release (with changelog) + upload asset env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} OWNER: ${{ gitea.repository_owner }} @@ -60,17 +62,56 @@ jobs: TAG: ${{ gitea.ref_name }} GITEA_SERVER_URL: ${{ gitea.server_url }} run: | - set -eux + set -euo pipefail API="${GITEA_SERVER_URL}/api/v1" - # Create release (si existe déjà, on continue) + # 1) Trouver le tag précédent (semver vX.Y.Z), différent du tag courant + PREV_TAG=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "^${TAG}$" | head -n 1 || true) + + if [ -n "${PREV_TAG}" ]; then + RANGE="${PREV_TAG}..${TAG}" + COMMITS=$(git log --pretty=format:"- %s (%h)" "${RANGE}") + FILES=$(git diff --name-status "${RANGE}") + else + RANGE="initial (up to ${TAG})" + COMMITS=$(git log --pretty=format:"- %s (%h)" "${TAG}") + FILES=$(git show --name-status --pretty="" "${TAG}") + fi + + # 2) Construire le body Markdown + cat > /tmp/release_body.md </dev/null 2>&1 || true + python -c 'import json; import pathlib; tag=pathlib.Path("/tmp/tag.txt").read_text().strip() if pathlib.Path("/tmp/tag.txt").exists() else ""' >/dev/null 2>&1 || true + echo "${TAG}" > /tmp/tag.txt + + python -c 'import json, pathlib; tag=pathlib.Path("/tmp/tag.txt").read_text().strip(); body=pathlib.Path("/tmp/release_body.md").read_text(); print(json.dumps({"tag_name":tag,"name":tag,"body":body,"draft":False,"prerelease":False}))' \ + > /tmp/release_payload.json + + # 4) Créer la release (si déjà existante, on continue) curl -sS -X POST "${API}/repos/${OWNER}/${REPO}/releases" \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ - -d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \ - >/tmp/release_create.json || true + -d @/tmp/release_payload.json \ + >/tmp/release.json || true - # Récupère l'id de la release par tag (fiable) + # 5) Récupérer l'ID de la release (par tag) et uploader l'asset curl -sS "${API}/repos/${OWNER}/${REPO}/releases/tags/${TAG}" \ -H "Authorization: token ${GITEA_TOKEN}" \ >/tmp/release_get.json @@ -78,8 +119,6 @@ jobs: RID=$(python -c "import json;print(json.load(open('/tmp/release_get.json'))['id'])") ASSET="dist/SDSAT-${TAG}.tar.gz" - ls -la "${ASSET}" - curl -sS -X POST "${API}/repos/${OWNER}/${REPO}/releases/${RID}/assets?name=$(basename "${ASSET}")" \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/gzip" \