Add CI workflow
This commit is contained in:
		
							
								
								
									
										168
									
								
								.gitea/workflows/publish.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										168
									
								
								.gitea/workflows/publish.yml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,168 @@ | |||||||
|  | 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<<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 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 '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 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 | ||||||
		Reference in New Issue
	
	Block a user
	 lionel
					lionel