Add CI workflow
This commit is contained in:
		
							
								
								
									
										179
									
								
								.gitea/workflows/publish.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										179
									
								
								.gitea/workflows/publish.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,179 @@
 | 
			
		||||
name: 🚀 Créer une nouvelle version
 | 
			
		||||
 | 
			
		||||
on:
 | 
			
		||||
  workflow_dispatch:
 | 
			
		||||
    inputs:
 | 
			
		||||
      tag:
 | 
			
		||||
        description: 'Nom du tag (ex: v1.2.3)'
 | 
			
		||||
        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: 🏷️ 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: 🔖 Détection du tag précédent
 | 
			
		||||
        id: tag-precedent
 | 
			
		||||
        run: |
 | 
			
		||||
          TARGET_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=""
 | 
			
		||||
 | 
			
		||||
          for tag in $TAGS; do
 | 
			
		||||
            if [ "$tag" != "$TARGET_TAG" ]; then
 | 
			
		||||
              PREV_TAG=$tag
 | 
			
		||||
            else
 | 
			
		||||
              break
 | 
			
		||||
            fi
 | 
			
		||||
          done
 | 
			
		||||
 | 
			
		||||
          echo "tag_precedent=$PREV_TAG" | tee -a $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é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 }}"
 | 
			
		||||
          
 | 
			
		||||
          # É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\",
 | 
			
		||||
              \"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"
 | 
			
		||||
            echo "sdk=$COMPILE_SDK_VERSION"
 | 
			
		||||
          } | tee -a $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.sdk }}
 | 
			
		||||
          build-tools-version: ${{ steps.extraire-info-gradle.outputs.sdk }}.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
 | 
			
		||||
        id: renommer-apk
 | 
			
		||||
        if: ${{ github.event.inputs.build_apk == 'oui' }}
 | 
			
		||||
        run: |
 | 
			
		||||
          APP_NAME=${{ steps.extraire-info-gradle.outputs.app_name }}
 | 
			
		||||
          TAG=${{ github.event.inputs.tag }}
 | 
			
		||||
          APK_DIR="app/build/outputs/apk/release"
 | 
			
		||||
          
 | 
			
		||||
          APKs=""
 | 
			
		||||
          for apk in "$APK_DIR"/*.apk; do
 | 
			
		||||
            BASENAME=$(basename "$apk")                          # ex: app-release-unsigned.apk
 | 
			
		||||
            SUFFIX=${BASENAME#app}                              # ex: -release-unsigned.apk
 | 
			
		||||
            NEW_NAME="${APP_NAME}${SUFFIX%\.apk}_${TAG}.apk"   # ex: MonApp-release-unsigned_v1.2.3.apk
 | 
			
		||||
            mv "$apk" "$APK_DIR/$NEW_NAME"
 | 
			
		||||
            APKs+=" $APK_DIR/$NEW_NAME"
 | 
			
		||||
          done
 | 
			
		||||
          echo "📦 Liste des apks : $APKs"
 | 
			
		||||
          echo "apk_files=$APKs" >> $GITHUB_OUTPUT
 | 
			
		||||
 | 
			
		||||
      - name: 📤 Téléversement de l’APK dans la version
 | 
			
		||||
        if: ${{ github.event.inputs.build_apk == 'oui' }}
 | 
			
		||||
        env:
 | 
			
		||||
          REGISTRY_URL: ${{ vars.REGISTRY_URL }}
 | 
			
		||||
          REPO: ${{ vars.REGISTRY_REPOSITORY }}
 | 
			
		||||
          TOKEN: ${{ secrets.REGISTRY_PASSWORD }}
 | 
			
		||||
          RELEASE_ID: ${{ steps.creation-release.outputs.id_release }}
 | 
			
		||||
        run: |
 | 
			
		||||
          for apk in ${{ steps.renommer-apk.outputs.apk_files }}; do
 | 
			
		||||
            curl -s -X POST "https://$REGISTRY_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets" \
 | 
			
		||||
              -H "Authorization: token $TOKEN" \
 | 
			
		||||
              -F attachment=@"$apk"
 | 
			
		||||
          done
 | 
			
		||||
		Reference in New Issue
	
	Block a user