Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/actions/build-apk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Build APK'
description: 'Build APK for specified variant (assumes environment already set up)'

inputs:
build_variant:
description: 'Build variant (dev, debug, beta, prerelease, release)'
required: true
decode_keystore:
description: 'Whether to decode keystore for signing'
required: false
default: 'false'

runs:
using: 'composite'
steps:
- name: Decode keystore (for release builds)
if: inputs.decode_keystore == 'true'
shell: bash
run: echo "${{ env.KEYSTORE_FILE }}" | base64 -d > keystore.jks

- name: Make gradlew executable
shell: bash
run: chmod +x ./gradlew

- name: Build APK
shell: bash
run: |
VARIANT=$(echo "${{ inputs.build_variant }}" | sed 's/\b\(.\)/\u\1/')
./gradlew clean assemble${VARIANT}
54 changes: 54 additions & 0 deletions .github/workflows/actions/bump-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: 'Bump Version Code'
description: 'Bumps the version code in build.gradle, commits, and pushes the change'
inputs:
gradle-file:
description: 'Path to the build.gradle file'
required: false
default: 'app/build.gradle'
git-user-email:
description: 'Git user email for commits'
required: false
default: 'automation@treetracker.org'
git-user-name:
description: 'Git user name for commits'
required: false
default: 'Treetracker Automation'
branch:
description: 'Branch to push to'
required: false
default: 'master'
outputs:
version_code:
description: 'The new version code'
value: ${{ steps.bump.outputs.version_code }}

runs:
using: 'composite'
steps:
- name: Set up git
shell: bash
run: |
git config --local user.email "${{ inputs.git-user-email }}"
git config --local user.name "${{ inputs.git-user-name }}"

- name: Bump version code
id: bump
shell: bash
run: |
# Read current version code
CURRENT_VERSION=$(grep -oP 'versionCode\s+\K\d+' ${{ inputs.gradle-file }})
NEW_VERSION=$((CURRENT_VERSION + 1))

# Update build.gradle
sed -i "s/versionCode $CURRENT_VERSION/versionCode $NEW_VERSION/" ${{ inputs.gradle-file }}

# Output the new version
echo "version_code=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumped version from $CURRENT_VERSION to $NEW_VERSION"

- name: Commit version bump
shell: bash
run: |
git add ${{ inputs.gradle-file }}
git commit -m "Version Bump to ${{ steps.bump.outputs.version_code }}"
git push origin ${{ inputs.branch }}
13 changes: 13 additions & 0 deletions .github/workflows/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'Run Tests'
description: 'Execute Gradle tests (assumes environment already set up)'

runs:
using: 'composite'
steps:
- name: Make gradlew executable
shell: bash
run: chmod +x ./gradlew

- name: Run tests
shell: bash
run: ./gradlew test --stacktrace
23 changes: 23 additions & 0 deletions .github/workflows/actions/setup-build-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'Setup Build Environment'
description: 'Setup JDK and generate property file (assumes code already checked out)'

inputs:
use_dummy_keys:
description: 'Whether to use dummy keys instead of real secrets'
required: false
default: 'false'

runs:
using: 'composite'
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'

- name: Generate property file
uses: ./.github/workflows/actions/setup-property-file
with:
use_dummy_keys: ${{ inputs.use_dummy_keys }}
37 changes: 37 additions & 0 deletions .github/workflows/actions/setup-property-file/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Setup Property File'
description: 'Generate treetracker.keys.properties file with either dummy or real keys from environment variables'

inputs:
use_dummy_keys:
description: 'Whether to use dummy keys instead of real secrets'
required: false
default: 'false'

runs:
using: 'composite'
steps:
- name: Generate property file (dummy)
if: inputs.use_dummy_keys == 'true'
shell: bash
run: |
echo "#Treetracker API Keys" > treetracker.keys.properties
echo "treetracker_client_id=dummy-id" >> treetracker.keys.properties
echo "treetracker_client_secret=dummy-secret" >> treetracker.keys.properties
echo "s3_dev_identity_pool_id=dummy-pool-id-dev" >> treetracker.keys.properties
echo "s3_test_identity_pool_id=dummy-pool-id-test" >> treetracker.keys.properties
echo "prod_treetracker_client_id=dummy-prod-id" >> treetracker.keys.properties
echo "prod_treetracker_client_secret=dummy-prod-secret" >> treetracker.keys.properties
echo "s3_production_identity_pool_id=dummy-pool-id-prod" >> treetracker.keys.properties

- name: Generate property file (real)
if: inputs.use_dummy_keys != 'true'
shell: bash
run: |
echo "#Treetracker API Keys" > treetracker.keys.properties
echo "s3_dev_identity_pool_id=${S3_DEV_IDENTITY_POOL_ID}" >> treetracker.keys.properties
echo "s3_test_identity_pool_id=${S3_TEST_IDENTITY_POOL_ID}" >> treetracker.keys.properties
echo "s3_production_identity_pool_id=${S3_PRODUCTION_IDENTITY_POOL_ID}" >> treetracker.keys.properties
echo "treetracker_client_id=${TREETRACKER_CLIENT_ID}" >> treetracker.keys.properties
echo "treetracker_client_secret=${TREETRACKER_CLIENT_SECRET}" >> treetracker.keys.properties
echo "prod_treetracker_client_id=${PROD_TREETRACKER_CLIENT_ID}" >> treetracker.keys.properties
echo "prod_treetracker_client_secret=${PROD_TREETRACKER_CLIENT_SECRET}" >> treetracker.keys.properties
80 changes: 80 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build APK

on:
workflow_call:
inputs:
build_variant:
description: "Build variant (dev, debug, beta, prerelease, release)"
required: true
type: string
upload_artifact:
description: "Whether to upload the built APK as an artifact"
required: false
type: boolean
default: true
secrets:
S3_DEV_IDENTITY_POOL_ID:
required: false
S3_TEST_IDENTITY_POOL_ID:
required: false
S3_PRODUCTION_IDENTITY_POOL_ID:
required: false
TREETRACKER_CLIENT_ID:
required: false
TREETRACKER_CLIENT_SECRET:
required: false
PROD_TREETRACKER_CLIENT_ID:
required: false
PROD_TREETRACKER_CLIENT_SECRET:
required: false
KEYSTORE_FILE:
required: false
KEYSTORE_PASSWORD:
required: false
KEY_ALIAS:
required: false
KEY_PASSWORD:
required: false

jobs:
build:
runs-on: ubuntu-latest
env:
S3_DEV_IDENTITY_POOL_ID: ${{ secrets.S3_DEV_IDENTITY_POOL_ID }}
S3_TEST_IDENTITY_POOL_ID: ${{ secrets.S3_TEST_IDENTITY_POOL_ID }}
S3_PRODUCTION_IDENTITY_POOL_ID: ${{ secrets.S3_PRODUCTION_IDENTITY_POOL_ID }}
TREETRACKER_CLIENT_ID: ${{ secrets.TREETRACKER_CLIENT_ID }}
TREETRACKER_CLIENT_SECRET: ${{ secrets.TREETRACKER_CLIENT_SECRET }}
PROD_TREETRACKER_CLIENT_ID: ${{ secrets.PROD_TREETRACKER_CLIENT_ID }}
PROD_TREETRACKER_CLIENT_SECRET: ${{ secrets.PROD_TREETRACKER_CLIENT_SECRET }}
KEYSTORE_FILE: ${{ secrets.KEYSTORE_FILE }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup build environment
uses: ./.github/workflows/actions/setup-build-environment

- name: Build APK
uses: ./.github/workflows/actions/build-apk
with:
build_variant: ${{ inputs.build_variant }}
decode_keystore: ${{ inputs.build_variant == 'release' || inputs.build_variant == 'prerelease' }}

- name: Upload APK artifact
if: inputs.upload_artifact
uses: actions/upload-artifact@v4
with:
name: app-${{ inputs.build_variant }}
path: app/build/outputs/apk/${{ inputs.build_variant }}/*.apk
retention-days: 30

- name: Clean up
if: always()
run: |
rm -f treetracker.keys.properties
rm -f keystore.jks
10 changes: 10 additions & 0 deletions .github/workflows/bump-version-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Bump Version Code Only

on:
workflow_dispatch:

jobs:
bump-and-push:
name: Bump version and push
uses: ./.github/workflows/bump-version.yml
secrets: inherit
28 changes: 28 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Bump Version Code

on:
workflow_call:
outputs:
version_code:
description: "The new version code"
value: ${{ jobs.bump.outputs.version_code }}

jobs:
bump:
runs-on: ubuntu-latest
outputs:
version_code: ${{ steps.bump.outputs.version_code }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Bump version code
id: bump
uses: ./.github/workflows/actions/bump-version
with:
branch: ${{ github.head_ref || github.ref_name }}
111 changes: 111 additions & 0 deletions .github/workflows/deploy-firebase-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Deploy to Firebase Beta

on:
pull_request:
branches: [ master, release* ]

jobs:
bump-version:
name: Bump version code
runs-on: ubuntu-latest
outputs:
version_code: ${{ steps.bump.outputs.version_code }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Bump version code
id: bump
uses: ./.github/workflows/actions/bump-version
with:
branch: ${{ github.head_ref || github.ref_name }}

build:
name: Build beta APK
needs: bump-version
uses: ./.github/workflows/build.yml
with:
build_variant: beta
upload_artifact: true
secrets: inherit

deploy:
name: Deploy to Firebase
runs-on: ubuntu-latest
needs: [bump-version, build]

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: master

- name: Download APK artifact
uses: actions/download-artifact@v4
with:
name: app-beta

- name: Deploy to Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: 1:422699885542:android:aab16ef8fc4e5968a0ec27
serviceCredentialsFileContent: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
groups: Greenstand
releaseNotes: "A new release! Build ${{ needs.bump-version.outputs.version_code }}"
file: app-beta-release.apk

# notify:
# name: Send Slack notifications
# runs-on: ubuntu-latest
# needs: [bump-version, deploy]
# if: success()
#
# steps:
# - name: Get git branch
# id: git-branch
# run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
#
# - name: Send Slack notification (main)
# uses: slackapi/slack-github-action@v1
# with:
# payload: |
# {
# "text": "A new Greenstand Beta Build has been released on Firebase",
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": "A new Greenstand Beta Build has been released on Firebase\n*Build Number:* ${{ needs.bump-version.outputs.version_code }}\n*Branch:* ${{ steps.git-branch.outputs.branch }}"
# }
# }
# ]
# }
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL }}
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
#
# - name: Send Slack notification (QC)
# uses: slackapi/slack-github-action@v1
# with:
# payload: |
# {
# "text": "A new Greenstand Beta Build has been released on Firebase",
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": "A new Greenstand Beta Build has been released on Firebase\n*Build Number:* ${{ needs.bump-version.outputs.version_code }}\n*Branch:* ${{ steps.git-branch.outputs.branch }}"
# }
# }
# ]
# }
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL_QC }}
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
Loading