From d519208439914c554b9b151aef654faeca23850a 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 | 171 +++++++++++++++++++++++++++++++++++ 1 file changed, 171 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..94c3320 --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -0,0 +1,171 @@ +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 l’APK ?' + 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<> $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 + DESCRIPTION="Changelog:"$'\n'"$COMMITS" + ESCAPED_DESCRIPTION=$(printf '%s\n' "$DESCRIPTION" | 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\", + \"name\": \"Version $TAG_NAME\", + \"body\": $ESCAPED_DESCRIPTION + }") + + echo "$REPONSE" + + ID_RELEASE=$(echo "$REPONSE" | jq -r .id) + echo "id_release=$ID_RELEASE" >> $GITHUB_OUTPUT + + + - name: đŸ”ïž Extraire les informations de l’application + 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 'compileSdk' 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 l’application (APK) + if: ${{ github.event.inputs.build_apk == 'oui' }} + run: ./gradlew assembleRelease + + - name: đŸ·ïž Renommer l’APK avec le nom de l’application 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 l’APK 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