Skip to content

Merge pull request #3 from Thre4dripper/dev #1

Merge pull request #3 from Thre4dripper/dev

Merge pull request #3 from Thre4dripper/dev #1

Workflow file for this run

name: Build and Release APK
on:
push:
branches:
- main
paths-ignore:
- '**/README.md'
- '**/LICENSE'
- '**/CONTRIBUTING.md'
- '.github/**'
- '.gitignore'
- '.editorconfig'
- '.vscode/**'
- '.idea/**'
workflow_dispatch:
concurrency:
group: ${{ github.actor != 'github-actions[bot]' && format('{0}-{1}', github.workflow, github.ref) || '' }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
packages: write
jobs:
setup:
runs-on: ubuntu-latest
name: Setup
steps:
- name: Create keystore
run: |
mkdir -p app
echo "${{ secrets.RELEASE_KEYSTORE_BASE64 }}" | base64 -d > app/keystore.jks
- name: Create play-services.json
run: |
echo "${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}" | base64 -d > app/play-services.json
- name: Upload config files
uses: actions/upload-artifact@v4
with:
name: config-files
path: |
app/keystore.jks
app/play-services.json
retention-days: 1
version-check:
needs: setup
name: Check Version
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.decision.outputs.should_build }}
version_code: ${{ steps.remote.outputs.versionCode }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Google API Client
run: pip install google-api-python-client google-auth google-auth-oauthlib google-auth-httplib2
- name: Download config files
uses: actions/download-artifact@v4
with:
name: config-files
path: ./app
- name: Get local versionCode
id: local
run: |
code=$(grep -oP 'versionCode\s+\K\d+' app/build.gradle)
echo "versionCode=$code" >> $GITHUB_OUTPUT
- name: Get latest Play Store versionCode
id: remote
run: |
version=$(python3 .github/scripts/check_playstore_version.py | grep "__version_code__" | cut -d '=' -f2)
echo "versionCode=$version" >> $GITHUB_OUTPUT
env:
GOOGLE_APPLICATION_CREDENTIALS: ./app/play-services.json
- name: Decide build or bump
id: decision
run: |
LOCAL=${{ steps.local.outputs.versionCode }}
REMOTE=${{ steps.remote.outputs.versionCode }}
echo "Local: $LOCAL, Play Store: $REMOTE"
if [ "$LOCAL" -gt "$REMOTE" ]; then
echo "should_build=true" >> $GITHUB_OUTPUT
else
echo "should_build=false" >> $GITHUB_OUTPUT
fi
build-apk:
needs: version-check
if: needs.version-check.outputs.should_build == 'true'
name: Build APK
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '17'
cache: gradle
- name: Download configs
uses: actions/download-artifact@v4
with:
name: config-files
path: ./app
- name: Export signing env vars
run: |
echo "RELEASE_STORE_PASSWORD=${{ secrets.RELEASE_STORE_PASSWORD }}" >> $GITHUB_ENV
echo "RELEASE_KEY_ALIAS=${{ secrets.RELEASE_KEY_ALIAS }}" >> $GITHUB_ENV
echo "RELEASE_KEY_PASSWORD=${{ secrets.RELEASE_KEY_PASSWORD }}" >> $GITHUB_ENV
- name: Build APK
run: |
chmod +x gradlew
./gradlew assembleRelease
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: apk-release
path: |
app/build/outputs/apk/release/app-release.apk
retention-days: 1
build-aab:
needs: version-check
if: needs.version-check.outputs.should_build == 'true'
name: Build AAB
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '17'
cache: gradle
- name: Download configs
uses: actions/download-artifact@v4
with:
name: config-files
path: ./app
- name: Export signing env vars
run: |
echo "RELEASE_STORE_PASSWORD=${{ secrets.RELEASE_STORE_PASSWORD }}" >> $GITHUB_ENV
echo "RELEASE_KEY_ALIAS=${{ secrets.RELEASE_KEY_ALIAS }}" >> $GITHUB_ENV
echo "RELEASE_KEY_PASSWORD=${{ secrets.RELEASE_KEY_PASSWORD }}" >> $GITHUB_ENV
- name: Build AAB
run: |
chmod +x gradlew
./gradlew bundleRelease
- name: Upload AAB
uses: actions/upload-artifact@v4
with:
name: aab-release
path: |
app/build/outputs/bundle/release/app-release.aab
app/play-services.json
retention-days: 1
update-version:
needs: version-check
if: needs.version-check.outputs.should_build == 'false'
runs-on: ubuntu-latest
name: Update Version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Get short SHA
id: sha
run: echo "sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Bump versionCode and versionName
id: bump
run: |
local_code=$(grep -oP 'versionCode\s+\K\d+' app/build.gradle)
local_name=$(grep -oP 'versionName\s+"\K[^"]+' app/build.gradle)
remote_code=${{ needs.version-check.outputs.version_code }}
new_code=$((local_code + 1))
while [ $new_code -le $remote_code ]; do
new_code=$((new_code + 1))
done
new_name="1.0-${{ steps.sha.outputs.sha }}"
sed -i "s/versionCode $local_code/versionCode $new_code/" app/build.gradle
sed -i "s/versionName \"$local_name\"/versionName \"$new_name\"/" app/build.gradle
echo "new_code=$new_code" >> $GITHUB_OUTPUT
echo "new_name=$new_name" >> $GITHUB_OUTPUT
- name: Commit and push
run: |
new_code=${{ steps.bump.outputs.new_code }}
new_name=${{ steps.bump.outputs.new_name }}
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add app/build.gradle
git commit -m "chore: bump version code to $new_code and version name to $new_name"
git push
publish:
name: Publish to Play Store
needs: [ build-apk, build-aab ]
runs-on: ubuntu-latest
outputs:
version_name: ${{ steps.get_version_name.outputs.version_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download AAB (if any)
uses: actions/download-artifact@v4
with:
name: aab-release
path: ./app
- name: Get Version Name
id: get_version_name
run: |
version_name=$(grep -oP 'versionName\s+"\K[^"]+' app/build.gradle)
echo "version_name=$version_name" >> $GITHUB_OUTPUT
- name: Create Whats New
run: |
mkdir -p whats-new
echo "Bug fixes and improvements" > whats-new/whatsnew-en-US
echo "Исправления ошибок и улучшения" > whats-new/whatsnew-ru-RU
- name: Upload to Play Store
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJson: app/play-services.json
packageName: com.ByteMechanics.matscape
releaseFiles: app/build/outputs/bundle/release/app-release.aab
track: production
status: completed
releaseName: Release ${{ steps.get_version_name.outputs.version_name }}
whatsNewDirectory: whats-new/
release:
name: Create Release
needs: publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get build artifact
uses: actions/download-artifact@v4
with:
name: apk-release
path: ./app
- name: Get Last Tag
id: get_last_tag
run: |
git fetch --tags
LAST_TAG=$(git describe --abbrev=0 --tags || echo "none")
echo "last_tag=${LAST_TAG}" >> $GITHUB_OUTPUT
- name: Generate New Tag
id: generate_new_tag
run: |
echo "new_tag=${{ needs.publish.outputs.version_name }}" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.generate_new_tag.outputs.new_tag }}
name: "Release ${{ steps.generate_new_tag.outputs.new_tag }}"
generate_release_notes: true
draft: false
prerelease: false
files: |
app/app-release.apk