Skip to content

Update build.yaml

Update build.yaml #35

Workflow file for this run

name: Build and Release APK
on:
push:
branches:
- master # Change this to your main branch
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Restore keystore artifact if exists
id: restore_keystore
run: echo "Keystore exists" # This is a placeholder command, it won't affect the outcome
if: false
- name: Regenerate Keystore if not restored
if: steps.restore_keystore.outputs.return-value != 'Keystore exists'
run: |
keytool -genkey -v -keystore /home/runner/work/reactmap-android/reactmap-android/keystore.jks \
-keyalg RSA -keysize 2048 -validity 10000 -alias ${{ secrets.KEY_ALIAS }} \
-storepass ${{ secrets.KEYSTORE_PASSWORD }} -keypass ${{ secrets.KEY_PASSWORD }} \
-dname "CN=Aco, OU=Pogofuerth, O=Pogofuerth, L=DE, ST=BY, C=DE"
- name: Check if keystore is available
run: ls -a /home/runner/work/reactmap-android/reactmap-android/keystore.jks
- name: Make Gradlew executable
run: chmod +x ./gradlew
- name: Extract versionName from gradle.properties
id: extract_version
run: echo "::set-output name=version::$(grep 'reactmap.versionName' gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')"
- name: Build with Gradle
run: ./gradlew assembleRelease
- name: Save Keystore as Artifact if not restored
if: steps.restore_keystore.outputs.artifact_paths == ''
uses: actions/upload-artifact@v2
with:
name: keystore
path: /home/runner/work/reactmap-android/reactmap-android/keystore.jks
- name: Sign APK and create release
run: |
cd /home/runner/work/reactmap-android/reactmap-android/
./gradlew assembleRelease -Pandroid.injected.signing.store.file=/home/runner/work/reactmap-android/reactmap-android/keystore.jks -Pandroid.injected.signing.store.password=${{ secrets.KEYSTORE_PASSWORD }} -Pandroid.injected.signing.key.alias=${{ secrets.KEY_ALIAS }} -Pandroid.injected.signing.key.password=${{ secrets.KEY_PASSWORD }}
- name: List APK directory - apk
run: ls -R /home/runner/work/reactmap-android/reactmap-android/app/build/outputs/apk/
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: Reactmap-android
path: /home/runner/work/reactmap-android/reactmap-android/app/build/outputs/apk/release/app-release.apk
- name: Check if release already exists
id: check_release
run: |
tag=v${{ steps.extract_version.outputs.version }}
existing_release=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/${{ github.repository }}/releases/tags/$tag)
if [ -z "$existing_release" ]; then
echo "::set-output name=release_exists::false"
else
echo "::set-output name=release_exists::true"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: v${{ steps.extract_version.outputs.version }}
release_name: v${{ steps.extract_version.outputs.version }}
draft: false
prerelease: false
if: steps.check_release.outputs.release_exists == 'false'
- name: Upload Artifact
id: upload-release-asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: /home/runner/work/reactmap-android/reactmap-android/app/build/outputs/apk/release/app-release.apk
asset_name: app-release.apk
asset_content_type: application/octet-stream
if: steps.check_release.outputs.release_exists == 'false'
- name: Send Discord webhook notification
if: steps.check_release.outputs.release_exists == 'false'
run: |
release_url="https://github.com/${{ github.repository }}/releases/tag/v${{ steps.extract_version.outputs.version }}"
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"New release v${{ steps.extract_version.outputs.version }} is available! [View Release]($release_url)\"}" ${{ secrets.DISCORD_WEBHOOK_URL }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}