diff --git a/.forgejo/workflows/create_release.yml b/.forgejo/workflows/create_release.yml new file mode 100644 index 0000000..63c963a --- /dev/null +++ b/.forgejo/workflows/create_release.yml @@ -0,0 +1,51 @@ +name: Create Release + +on: + push: + paths: + - "releases/*.apk" + +jobs: + create-release: + runs-on: ubuntu-latest + + steps: + # Checkout repository + - name: Checkout Repository + uses: https://data.forgejo.org/actions/checkout@v4 + + # Get latest APK file (highest version number) + - name: Find Latest APK + run: | + LATEST_APK=$(ls releases/*.apk | sort -V | tail -n 1) + APK_NAME=$(basename "$LATEST_APK") + VERSION=$(echo "$APK_NAME" | grep -oP '\d+\.\d+\.\d+\.\d+') + echo "LATEST_APK=$LATEST_APK" >> $GITHUB_ENV + echo "APK_NAME=$APK_NAME" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV + + # Create Forgejo Release and upload APK + - name: Create Release and Upload APK + env: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} + SHA: ${{ github.sha }} + run: | + BODY=$(node -e 'console.log(JSON.stringify({ + tag_name: "v" + process.env.VERSION, + target_commitish: process.env.SHA, + name: "Release v" + process.env.VERSION, + body: "This release contains the latest APK version: **v" + process.env.VERSION + "**", + draft: false, + prerelease: false + }))') + + RELEASE=$(curl -sS --fail-with-body -X POST "$API/releases" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "$BODY") + RELEASE_ID=$(echo "$RELEASE" | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log(JSON.parse(s).id))') + + curl -sS --fail-with-body -X POST "$API/releases/$RELEASE_ID/assets?name=$APK_NAME" \ + -H "Authorization: token $TOKEN" \ + -F "attachment=@$LATEST_APK;type=application/vnd.android.package-archive" diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml deleted file mode 100644 index 6c78652..0000000 --- a/.github/workflows/create_release.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Create Release - -on: - push: - paths: - - "releases/*.apk" - -jobs: - create-release: - runs-on: ubuntu-latest - - steps: - # Checkout repository - - name: Checkout Repository - uses: actions/checkout@v4 - - # Get latest APK file - - name: Find Latest APK - id: find_apk - run: | - LATEST_APK=$(ls -t releases/*.apk | head -n 1) - APK_NAME=$(basename "$LATEST_APK") - VERSION=$(echo "$APK_NAME" | grep -oP '\d+\.\d+\.\d+\.\d+') - echo "LATEST_APK=$LATEST_APK" >> $GITHUB_ENV - echo "APK_NAME=$APK_NAME" >> $GITHUB_ENV - echo "VERSION=$VERSION" >> $GITHUB_ENV - - # Create GitHub Release - - name: Create GitHub Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: v${{ env.VERSION }} - release_name: Release v${{ env.VERSION }} - body: | - This release contains the latest APK version: **v${{ env.VERSION }}** - draft: false - prerelease: false - - # Upload APK to GitHub Release - - name: Upload APK to Release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ${{ env.LATEST_APK }} - asset_name: ${{ env.APK_NAME }} - asset_content_type: application/vnd.android.package-archive