152 lines
5.8 KiB
YAML
152 lines
5.8 KiB
YAML
name: Update version and publish APK
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: "Version number (must be in x.y.z format)"
|
|
required: true
|
|
release_type:
|
|
description: "Type of release (release or preview)"
|
|
required: true
|
|
default: "preview"
|
|
type: choice
|
|
options:
|
|
- release
|
|
- preview
|
|
|
|
jobs:
|
|
update_version_and_publish:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Get updated version name and version code
|
|
run: |
|
|
# Extract version name from github inputs
|
|
BASE_VERSION="${{ github.event.inputs.version }}"
|
|
BRANCH_NAME="release/v${BASE_VERSION}"
|
|
|
|
git fetch --all
|
|
|
|
if git rev-parse --verify origin/${BRANCH_NAME} >/dev/null 2>&1; then
|
|
echo "Branch ${BRANCH_NAME} exists, checking out..."
|
|
git checkout ${BRANCH_NAME}
|
|
else
|
|
echo "Branch ${BRANCH_NAME} does not exist, creating..."
|
|
git checkout -b ${BRANCH_NAME}
|
|
fi
|
|
|
|
CURRENT_RC=$(git tag -l "v${BASE_VERSION}-rc*" | sort | tail -n 1)
|
|
if [[ -z "$CURRENT_RC" ]]; then
|
|
RC_SUFFIX="-rc01"
|
|
else
|
|
SUFFIX_NUMBER=$(echo $CURRENT_RC | grep -oP '(?<=-rc)\d+')
|
|
NEXT_SUFFIX=$(printf "%02d" $((10#$SUFFIX_NUMBER + 1)))
|
|
RC_SUFFIX="-rc${NEXT_SUFFIX}"
|
|
fi
|
|
|
|
# Version name with rc suffix
|
|
if [[ "${{ github.event.inputs.release_type }}" == "preview" ]]; then
|
|
VERSION_NAME="${BASE_VERSION}${RC_SUFFIX}"
|
|
else
|
|
VERSION_NAME="${BASE_VERSION}"
|
|
fi
|
|
|
|
# Get existing version code from build.gradle
|
|
VERSION_CODE=$(grep "versionCode" app/build.gradle.kts | awk '{print $3}' | tr -d '\n')
|
|
|
|
# Increment existing version code by 1
|
|
VERSION_CODE=$((VERSION_CODE + 1))
|
|
|
|
# Set environment variable for later use
|
|
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
|
|
echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV
|
|
|
|
- name: Update app/build.gradle.kts updated version name and version code
|
|
run: |
|
|
echo "Updating version code to ${{ env.VERSION_CODE }} and version name to ${{ env.VERSION_NAME }}"
|
|
sed -i "s/versionCode = [0-9]\+/versionCode = ${{ env.VERSION_CODE }}/g" app/build.gradle.kts
|
|
sed -i "s/versionName = \"[^\"]*\"/versionName = \"${{ env.VERSION_NAME }}\"/g" app/build.gradle.kts
|
|
|
|
- name: Set up Ruby
|
|
uses: ruby/setup-ruby@v1
|
|
with:
|
|
ruby-version: 3.3.0
|
|
bundler-cache: true
|
|
|
|
- name: Set Up JDK 17
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: 17
|
|
distribution: temurin
|
|
|
|
- name: Setup Gradle
|
|
uses: gradle/actions/setup-gradle@v4
|
|
with:
|
|
validate-wrappers: true
|
|
gradle-home-cache-cleanup: true
|
|
|
|
- name: Decode keystore file
|
|
uses: timheuer/base64-to-file@v1
|
|
id: keystore
|
|
with:
|
|
fileName: 'keystore.jks'
|
|
encodedString: ${{ secrets.KEYSTORE }}
|
|
|
|
- name: Decode Play API credentials file
|
|
uses: timheuer/base64-to-file@v1
|
|
id: play_api_credentials
|
|
with:
|
|
fileName: 'play-api-credentials.json'
|
|
encodedString: ${{ secrets.PLAY_API_CREDENTIALS }}
|
|
|
|
- name: Build app
|
|
run: bundle exec fastlane build
|
|
if: ${{ github.event.inputs.release_type == 'preview' }}
|
|
env:
|
|
KEYSTORE: ${{ steps.keystore.outputs.filePath }}
|
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
|
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
|
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
|
|
|
- name: Build app and publish
|
|
run: bundle exec fastlane build
|
|
if: ${{ github.event.inputs.release_type == 'release' }}
|
|
env:
|
|
KEYSTORE: ${{ steps.keystore.outputs.filePath }}
|
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
|
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
|
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
|
PLAY_API_CREDENTIALS: ${{ steps.play_api_credentials.outputs.filePath }}
|
|
|
|
- name: Rename Files
|
|
run: |
|
|
mv app/build/outputs/apk/release/app-arm64-v8a-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-arm64-v8a.apk
|
|
mv app/build/outputs/apk/release/app-armeabi-v7a-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-armeabi-v7a.apk
|
|
mv app/build/outputs/apk/release/app-universal-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-universal.apk
|
|
mv app/build/outputs/apk/release/app-x86-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-x86.apk
|
|
mv app/build/outputs/apk/release/app-x86_64-release.apk app/build/outputs/apk/release/nextplayer-v${{ env.VERSION_NAME }}-x86_64.apk
|
|
|
|
- name: Commit and Push Changes
|
|
run: |
|
|
git config user.name "GitHub Actions"
|
|
git config user.email "actions@github.com"
|
|
git add .
|
|
git commit -m "Release version ${{ env.VERSION_NAME }}" || echo "No changes to commit"
|
|
git config push.autoSetupRemote true
|
|
git push --set-upstream origin ${BRANCH_NAME}
|
|
|
|
- name: Create Draft Release
|
|
id: create_draft_release
|
|
uses: softprops/action-gh-release@v2
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
files: app/build/outputs/apk/release/nextplayer*
|
|
draft: true
|
|
name: v${{ env.VERSION_NAME }}
|
|
generate_release_notes: true
|
|
prerelease: ${{ github.event.inputs.release_type == 'preview' }}
|
|
tag_name: v${{ env.VERSION_NAME }}
|