This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Android package | |
on: | |
workflow_call: | |
inputs: | |
status: | |
description: "Release status" | |
type: string | |
default: "completed" | |
# type: choice | |
# options: | |
# - completed | |
# - inProgress | |
# - halted | |
# - draft | |
release-type: | |
description: "Release type" | |
required: true | |
type: string | |
# type: choice | |
# options: | |
# - major | |
# - minor | |
# - patch | |
# - premajor | |
# - preminor | |
# - prepatch | |
# - prerelease | |
release-notes: | |
description: "Release notes" | |
type: string | |
dist-script: | |
description: "Build script to execute" | |
type: string | |
default: "build" | |
deploy-to-play-store: | |
description: "Deploy to Play Store" | |
type: boolean | |
default: true | |
secrets: | |
GITHUB_ACCESS_TOKEN: | |
required: true | |
ANDROID_RELEASE_KEYSTORE: | |
required: true | |
ANDROID_RELEASE_KEYSTORE_PASSWORD: | |
required: true | |
SERVICE_ACCOUNT_JSON: | |
required: true | |
env: | |
RELEASE_TYPE: ${{ github.event.inputs.release-type }} | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} | |
jobs: | |
Release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
# We must fetch at least the immediate parents so that if this is | |
# a pull request then we can checkout the head. | |
fetch-depth: 2 | |
- name: Set up java 17.0.3 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'microsoft' | |
java-version: '17.0.3' | |
cache: 'gradle' | |
# Setup Node.js environment | |
- name: Set up Node.js 16.17.0 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 16.17.0 | |
# Important! | |
registry-url: 'https://registry.npmjs.org' | |
always-auth: true | |
- name: Set up environment | |
uses: michijs/.github/.github/workflows/runtime/setup.yml@main | |
- name: Install dependencies | |
uses: michijs/.github/.github/workflows/runtime/install.yml@main | |
# Configure Git | |
- name: Git configuration | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "GitHub Actions" | |
# Bump package version | |
# Use tag latest | |
- name: Bump release version | |
if: startsWith(github.event.inputs.release-type, 'pre') != true | |
run: | | |
echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV | |
echo "RELEASE_TRACK=production" >> $GITHUB_ENV | |
# Bump package pre-release version | |
# Use tag beta for pre-release versions | |
- name: Bump pre-release version | |
if: startsWith(github.event.inputs.release-type, 'pre') | |
run: | | |
echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV | |
echo "RELEASE_TRACK=beta" >> $GITHUB_ENV | |
# Build | |
- name: Build | |
uses: michijs/.github/.github/workflows/runtime/run.yml@main | |
with: | |
script-name: ${{ inputs.dist-script }} | |
# Start Android | |
- name: Capacitor Sync | |
run: npx cap sync | |
- name: Make gradlew executable | |
run: chmod +x ./android/gradlew | |
- name: Build app bundle (AAB) | |
run: cd android && ./gradlew bundle | |
- name: Build app APK | |
run: cd android && ./gradlew assembleDebug | |
- name: Extract Android signing key from env | |
run: | | |
echo "${{ secrets.ANDROID_RELEASE_KEYSTORE }}" > android/release.jks.base64 | |
base64 -d android/release.jks.base64 > android/release.decrypted.jks | |
- name: Sign app bundle (AAB) | |
run: jarsigner -keystore android/release.decrypted.jks -storepass "${{ secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD }}" -signedjar ./android/app/build/outputs/bundle/release/app-release-signed.aab ./android/app/build/outputs/bundle/release/app-release.aab play_store | |
- name: Sign app APK | |
run: jarsigner -keystore android/release.decrypted.jks -storepass "${{ secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD }}" -signedjar ./android/app/build/outputs/apk/debug/app-debug-signed.apk ./android/app/build/outputs/apk/debug/app-debug.apk play_store | |
- name: Get Package Name | |
run: | | |
cd android && namespace=$(grep -Po 'namespace\s+"(\S+)"' app/build.gradle | awk -F'"' '{print $2}') | |
echo "ANDROID_PACKAGE_NAME=$namespace" >> $GITHUB_ENV | |
- name: Create whats new directory | |
run: | | |
mkdir whatsnew | |
cd whatsnew && echo "${{ github.event.inputs.release-notes }}" >> "whatsnew-en-US" | |
- name: Deploy to Play Store | |
if: fromJSON(github.event.inputs.deploy-to-play-store) | |
uses: r0adkll/upload-google-play@v1 | |
with: | |
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }} | |
packageName: ${{ env.ANDROID_PACKAGE_NAME }} | |
whatsNewDirectory: "whatsnew" | |
status: ${{ github.event.inputs.STATUS }} | |
releaseFiles: android/app/build/outputs/bundle/release/app-release-signed.aab | |
track: ${{ env.RELEASE_TRACK }} | |
# End Android | |
# Commit changes | |
- name: Commit package.json changes and create tag | |
run: | | |
git add "package.json" | |
git commit -m "chore: release ${{ env.NEW_VERSION }}" | |
git tag ${{ env.NEW_VERSION }} | |
# Push repository changes | |
- name: Push changes to repository | |
run: | | |
git push origin && git push --tags | |
# Update GitHub release with changelog | |
- name: Update GitHub release documentation | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ env.NEW_VERSION }} | |
body: ${{ github.event.inputs.release-notes }} | |
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }} | |
files: | | |
./android/app/build/outputs/apk/debug/app-debug-signed.apk | |
./android/app/build/outputs/apk/debug/app-debug.apk | |
./android/app/build/outputs/bundle/release/app-release.aab | |
./android/app/build/outputs/bundle/release/app-release-signed.aab |