From 4d43d301cc64cc4715d94ed70b14b9543a13f850 Mon Sep 17 00:00:00 2001 From: lionel <.> Date: Wed, 9 Jul 2025 01:44:22 +0200 Subject: [PATCH] Add CI workflow --- .gitea/workflows/publish.yml | 96 ++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .gitea/workflows/publish.yml diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml new file mode 100644 index 0000000..6b7cc6e --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -0,0 +1,96 @@ +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 + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: 📦 Cloner le dépôt + uses: actions/checkout@v3 + + - name: 🔧 Préparation de Git (récupération des tags) + run: git fetch --tags + + - name: 🔖 Détection du dernier tag existant + id: dernier-tag + run: | + TAG=$(git describe --tags --abbrev=0 || echo "") + echo "dernier_tag=$TAG" >> $GITHUB_OUTPUT + + - name: 📝 Liste des modifications depuis le dernier tag + id: changelog + run: | + FROM_TAG=${{ steps.dernier-tag.outputs.dernier_tag }} + if [ -z "$FROM_TAG" ]; then + LOG=$(git log --oneline) + else + LOG=$(git log "$FROM_TAG"..HEAD --oneline) + fi + echo "modifications<> $GITHUB_OUTPUT + echo "$LOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: 📦 Extraire le nom de l’application depuis settings.gradle + id: extraire-nom-appli + run: | + APP_NAME=$(grep 'rootProject.name' settings.gradle | sed -E 's/.*= "(.*)"/\1/') + echo "app_name=$APP_NAME" >> $GITHUB_OUTPUT + + - name: ☕ Configurer Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + + - name: 🛠️ Compilation de l’application (APK) + run: ./gradlew assembleRelease + + - name: 🏷️ Renommer l’APK avec le nom de l’application et le tag + run: | + mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/${{ steps.extraire-nom-appli.outputs.app_name }}_${{ github.event.inputs.tag }}.apk + + - 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 }}" + + 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": "'"$COMMITS"'" + }') + + ID_RELEASE=$(echo "$REPONSE" | jq -r .id) + echo "id_release=$ID_RELEASE" >> $GITHUB_OUTPUT + + - name: 📤 Téléversement de l’APK dans la version + 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-nom-appli.outputs.app_name }}_${{ github.event.inputs.tag }}.apk