Files
androidApp/.gitea/workflows/publish.yml
2025-07-09 12:57:20 +02:00

169 lines
5.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 🚀 Créer une nouvelle version
on:
workflow_dispatch:
inputs:
tag:
description: 'Nom du tag (ex: v1.2.3)'
required: true
branche:
description: 'Branche cible (ex: master)'
default: 'master'
required: true
build_apk:
description: 'Compiler et publier lAPK ?'
required: true
default: 'oui'
type: choice
options:
- oui
- non
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: 📦 Cloner le dépôt
uses: actions/checkout@v3
with:
fetch-depth: 0 # important pour récupérer tout l'historique
- name: 🔧 Préparation de Git (tags)
run: git fetch --tags
- name: 🔖 Détection du tag précédent
id: tag-precedent
run: |
CURRENT_TAG="${{ github.event.inputs.tag }}"
TAGS=$(git tag --sort=-creatordate)
if [ -z "$TAGS" ]; then
echo "Aucun tag existant détecté."
echo "tag_precedent=" >> $GITHUB_OUTPUT
exit 0
fi
PREV_TAG=""
FOUND=false
for tag in $TAGS; do
if [ "$FOUND" = true ]; then
PREV_TAG=$tag
break
fi
if [ "$tag" = "$CURRENT_TAG" ]; then
FOUND=true
fi
done
echo "tag_precedent=$PREV_TAG" >> $GITHUB_OUTPUT
- name: 📝 Liste des modifications
id: changelog
run: |
PREV_TAG="${{ steps.tag-precedent.outputs.tag_precedent }}"
TARGET_TAG="${{ github.event.inputs.tag }}"
if [ -z "$PREV_TAG" ]; then
LOG=$(git log --oneline)
else
if git rev-parse "$TARGET_TAG" >/dev/null 2>&1; then
LOG=$(git log "$PREV_TAG".."$TARGET_TAG" --oneline)
else
LOG=$(git log "$PREV_TAG"..HEAD --oneline)
fi
fi
echo "$LOG"
echo "modifications<<EOF" >> $GITHUB_OUTPUT
echo "$LOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: 🏷️ Créer le tag si nécessaire
run: |
TAG="${{ github.event.inputs.tag }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Le tag $TAG existe déjà, pas besoin de le créer."
else
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag "$TAG"
git push origin "$TAG"
fi
- name: 📦 Création de la version sur Gitea
id: creation-release
env:
REGISTRY_URL: ${{ vars.REGISTRY_URL }}
REPO: ${{ vars.REGISTRY_REPOSITORY }}
TOKEN: ${{ secrets.REGISTRY_PASSWORD }}
COMMITS: ${{ steps.changelog.outputs.modifications }}
run: |
TAG_NAME="${{ github.event.inputs.tag }}"
BRANCHE="${{ github.event.inputs.branche }}"
# Échappement du contenu pour JSON
ESCAPED_COMMITS=$(printf '%s\n' "$COMMITS" | jq -Rsa .)
REPONSE=$(curl -s -X POST "https://$REGISTRY_URL/api/v1/repos/$REPO/releases" \
-H "Content-Type: application/json" \
-H "Authorization: token $TOKEN" \
-d "{
\"tag_name\": \"$TAG_NAME\",
\"target\": \"$BRANCHE\",
\"title\": \"Version $TAG_NAME\",
\"note\": $ESCAPED_COMMITS
}")
ID_RELEASE=$(echo "$REPONSE" | jq -r .id)
echo "id_release=$ID_RELEASE" >> $GITHUB_OUTPUT
- name: 🔍️ Extraire les informations de lapplication
id: extraire-info-gradle
if: ${{ github.event.inputs.build_apk == 'oui' }}
run: |
APP_NAME=$(grep 'rootProject.name' settings.gradle | sed -E 's/.*= "(.*)"/\1/')
COMPILE_SDK_VERSION=$(grep 'compileSdkVersion' app/build.gradle | grep -oE '[0-9]+')
echo "app_name=$APP_NAME" >> $GITHUB_OUTPUT
echo "compile_sdk_version=$COMPILE_SDK_VERSION" >> $GITHUB_OUTPUT
- name: ☕ Configurer Java
if: ${{ github.event.inputs.build_apk == 'oui' }}
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: 🤖 Installer Android SDK
if: ${{ github.event.inputs.build_apk == 'oui' }}
uses: android-actions/setup-android@v3
with:
api-level: ${{ steps.extraire-info-gradle.outputs.compile_sdk_version }}
build-tools-version: ${{ steps.extraire-info-gradle.outputs.compile_sdk_version }}.0.3
- name: 🛠️ Compilation de lapplication (APK)
if: ${{ github.event.inputs.build_apk == 'oui' }}
run: ./gradlew assembleRelease
- name: 🏷️ Renommer lAPK avec le nom de lapplication et le tag
if: ${{ github.event.inputs.build_apk == 'oui' }}
run: |
mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/${{ steps.extraire-info-gradle.outputs.app_name }}_${{ github.event.inputs.tag }}.apk
- name: 📤 Téléversement de lAPK dans la version
if: ${{ github.event.inputs.build_apk == 'oui' }}
env:
GITEA_URL: ${{ vars.REGISTRY_URL }}
REPO: ${{ vars.REGISTRY_REPOSITORY }}
TOKEN: ${{ secrets.REGISTRY_PASSWORD }}
RELEASE_ID: ${{ steps.creation-release.outputs.id_release }}
run: |
curl -s -X POST "$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets" \
-H "Authorization: token $TOKEN" \
-F attachment=@app/build/outputs/apk/release/${{ steps.extraire-info-gradle.outputs.app_name }}_${{ github.event.inputs.tag }}.apk