From 928d7a6370b66916a4a587331a9c2bf82f97400b Mon Sep 17 00:00:00 2001 From: Akshay Nikhare Date: Wed, 5 Jun 2024 02:48:59 +0530 Subject: [PATCH] Update android.yml --- .github/workflows/android.yml | 42 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 082b8c4..3365498 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -37,27 +37,41 @@ jobs: echo "version=$version" >> $GITHUB_ENV echo "VERSION: $version" - - name: Create Release - id: create_release - uses: actions/create-release@v1 + - name: Check if Release Exists + id: check_release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: v${{ env.version }} - release_name: Release v${{ env.version }} - draft: false - prerelease: false + run: | + response=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ env.version }}) + release_id=$(echo $response | jq -r '.id') + if [ "$release_id" == "null" ]; then + echo "release_exists=false" >> $GITHUB_ENV + else + echo "release_exists=true" >> $GITHUB_ENV + echo "release_id=$release_id" >> $GITHUB_ENV + fi + + - name: Create or Update Release + id: create_or_update_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_EXISTS: ${{ env.release_exists }} + RELEASE_ID: ${{ env.release_id }} + run: | + if [ "$RELEASE_EXISTS" == "false" ]; then + response=$(curl -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Content-Type: application/json" -d "{\"tag_name\":\"v${{ env.version }}\",\"name\":\"Release v${{ env.version }}\",\"draft\":false,\"prerelease\":false}" https://api.github.com/repos/${{ github.repository }}/releases) + release_id=$(echo $response | jq -r '.id') + echo "release_id=$release_id" >> $GITHUB_ENV + else + echo "Release already exists with ID $RELEASE_ID" + fi - name: Upload Release Asset env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_ID: ${{ env.release_id }} run: | - release_id=$(curl -s \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ env.version }} \ - | jq -r '.id') - - upload_url="https://uploads.github.com/repos/${{ github.repository }}/releases/$release_id/assets?name=app-v${{ env.version }}.apk" + upload_url="https://uploads.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=app-v${{ env.version }}.apk" asset_path=./app/build/outputs/apk/release/app-release.apk curl -X POST \