Skip to content

Commit 2c9ba81

Browse files
committed
Migrate away from fastlane
1 parent c2ecc4f commit 2c9ba81

File tree

13 files changed

+523
-2
lines changed

13 files changed

+523
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'Build APK'
2+
description: 'Build APK for specified variant (assumes environment already set up)'
3+
4+
inputs:
5+
build_variant:
6+
description: 'Build variant (dev, debug, beta, prerelease, release)'
7+
required: true
8+
decode_keystore:
9+
description: 'Whether to decode keystore for signing'
10+
required: false
11+
default: 'false'
12+
13+
runs:
14+
using: 'composite'
15+
steps:
16+
- name: Decode keystore (for release builds)
17+
if: inputs.decode_keystore == 'true'
18+
shell: bash
19+
run: echo "${{ env.KEYSTORE_FILE }}" | base64 -d > keystore.jks
20+
21+
- name: Make gradlew executable
22+
shell: bash
23+
run: chmod +x ./gradlew
24+
25+
- name: Build APK
26+
shell: bash
27+
run: |
28+
VARIANT=$(echo "${{ inputs.build_variant }}" | sed 's/\b\(.\)/\u\1/')
29+
./gradlew clean assemble${VARIANT}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: 'Bump Version Code'
2+
description: 'Bumps the version code in build.gradle, commits, and pushes the change'
3+
inputs:
4+
gradle-file:
5+
description: 'Path to the build.gradle file'
6+
required: false
7+
default: 'app/build.gradle'
8+
git-user-email:
9+
description: 'Git user email for commits'
10+
required: false
11+
default: 'automation@treetracker.org'
12+
git-user-name:
13+
description: 'Git user name for commits'
14+
required: false
15+
default: 'Treetracker Automation'
16+
branch:
17+
description: 'Branch to push to'
18+
required: false
19+
default: 'master'
20+
outputs:
21+
version_code:
22+
description: 'The new version code'
23+
value: ${{ steps.bump.outputs.version_code }}
24+
25+
runs:
26+
using: 'composite'
27+
steps:
28+
- name: Set up git
29+
shell: bash
30+
run: |
31+
git config --local user.email "${{ inputs.git-user-email }}"
32+
git config --local user.name "${{ inputs.git-user-name }}"
33+
34+
- name: Bump version code
35+
id: bump
36+
shell: bash
37+
run: |
38+
# Read current version code
39+
CURRENT_VERSION=$(grep -oP 'versionCode\s+\K\d+' ${{ inputs.gradle-file }})
40+
NEW_VERSION=$((CURRENT_VERSION + 1))
41+
42+
# Update build.gradle
43+
sed -i "s/versionCode $CURRENT_VERSION/versionCode $NEW_VERSION/" ${{ inputs.gradle-file }}
44+
45+
# Output the new version
46+
echo "version_code=$NEW_VERSION" >> $GITHUB_OUTPUT
47+
echo "Bumped version from $CURRENT_VERSION to $NEW_VERSION"
48+
49+
- name: Commit version bump
50+
shell: bash
51+
run: |
52+
git add ${{ inputs.gradle-file }}
53+
git commit -m "Version Bump to ${{ steps.bump.outputs.version_code }}"
54+
git push origin ${{ inputs.branch }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Run Tests'
2+
description: 'Execute Gradle tests (assumes environment already set up)'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Make gradlew executable
8+
shell: bash
9+
run: chmod +x ./gradlew
10+
11+
- name: Run tests
12+
shell: bash
13+
run: ./gradlew test --stacktrace
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Setup Build Environment'
2+
description: 'Setup JDK and generate property file (assumes code already checked out)'
3+
4+
inputs:
5+
use_dummy_keys:
6+
description: 'Whether to use dummy keys instead of real secrets'
7+
required: false
8+
default: 'false'
9+
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- name: Set up JDK 17
14+
uses: actions/setup-java@v4
15+
with:
16+
java-version: 17
17+
distribution: 'temurin'
18+
cache: 'gradle'
19+
20+
- name: Generate property file
21+
uses: ./.github/workflows/actions/setup-property-file
22+
with:
23+
use_dummy_keys: ${{ inputs.use_dummy_keys }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: 'Setup Property File'
2+
description: 'Generate treetracker.keys.properties file with either dummy or real keys from environment variables'
3+
4+
inputs:
5+
use_dummy_keys:
6+
description: 'Whether to use dummy keys instead of real secrets'
7+
required: false
8+
default: 'false'
9+
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- name: Generate property file (dummy)
14+
if: inputs.use_dummy_keys == 'true'
15+
shell: bash
16+
run: |
17+
echo "#Treetracker API Keys" > treetracker.keys.properties
18+
echo "treetracker_client_id=dummy-id" >> treetracker.keys.properties
19+
echo "treetracker_client_secret=dummy-secret" >> treetracker.keys.properties
20+
echo "s3_dev_identity_pool_id=dummy-pool-id-dev" >> treetracker.keys.properties
21+
echo "s3_test_identity_pool_id=dummy-pool-id-test" >> treetracker.keys.properties
22+
echo "prod_treetracker_client_id=dummy-prod-id" >> treetracker.keys.properties
23+
echo "prod_treetracker_client_secret=dummy-prod-secret" >> treetracker.keys.properties
24+
echo "s3_production_identity_pool_id=dummy-pool-id-prod" >> treetracker.keys.properties
25+
26+
- name: Generate property file (real)
27+
if: inputs.use_dummy_keys != 'true'
28+
shell: bash
29+
run: |
30+
echo "#Treetracker API Keys" > treetracker.keys.properties
31+
echo "s3_dev_identity_pool_id=${S3_DEV_IDENTITY_POOL_ID}" >> treetracker.keys.properties
32+
echo "s3_test_identity_pool_id=${S3_TEST_IDENTITY_POOL_ID}" >> treetracker.keys.properties
33+
echo "s3_production_identity_pool_id=${S3_PRODUCTION_IDENTITY_POOL_ID}" >> treetracker.keys.properties
34+
echo "treetracker_client_id=${TREETRACKER_CLIENT_ID}" >> treetracker.keys.properties
35+
echo "treetracker_client_secret=${TREETRACKER_CLIENT_SECRET}" >> treetracker.keys.properties
36+
echo "prod_treetracker_client_id=${PROD_TREETRACKER_CLIENT_ID}" >> treetracker.keys.properties
37+
echo "prod_treetracker_client_secret=${PROD_TREETRACKER_CLIENT_SECRET}" >> treetracker.keys.properties

.github/workflows/build.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build APK
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
build_variant:
7+
description: "Build variant (dev, debug, beta, prerelease, release)"
8+
required: true
9+
type: string
10+
upload_artifact:
11+
description: "Whether to upload the built APK as an artifact"
12+
required: false
13+
type: boolean
14+
default: true
15+
secrets:
16+
S3_DEV_IDENTITY_POOL_ID:
17+
required: false
18+
S3_TEST_IDENTITY_POOL_ID:
19+
required: false
20+
S3_PRODUCTION_IDENTITY_POOL_ID:
21+
required: false
22+
TREETRACKER_CLIENT_ID:
23+
required: false
24+
TREETRACKER_CLIENT_SECRET:
25+
required: false
26+
PROD_TREETRACKER_CLIENT_ID:
27+
required: false
28+
PROD_TREETRACKER_CLIENT_SECRET:
29+
required: false
30+
KEYSTORE_FILE:
31+
required: false
32+
KEYSTORE_PASSWORD:
33+
required: false
34+
KEY_ALIAS:
35+
required: false
36+
KEY_PASSWORD:
37+
required: false
38+
39+
jobs:
40+
build:
41+
runs-on: ubuntu-latest
42+
env:
43+
S3_DEV_IDENTITY_POOL_ID: ${{ secrets.S3_DEV_IDENTITY_POOL_ID }}
44+
S3_TEST_IDENTITY_POOL_ID: ${{ secrets.S3_TEST_IDENTITY_POOL_ID }}
45+
S3_PRODUCTION_IDENTITY_POOL_ID: ${{ secrets.S3_PRODUCTION_IDENTITY_POOL_ID }}
46+
TREETRACKER_CLIENT_ID: ${{ secrets.TREETRACKER_CLIENT_ID }}
47+
TREETRACKER_CLIENT_SECRET: ${{ secrets.TREETRACKER_CLIENT_SECRET }}
48+
PROD_TREETRACKER_CLIENT_ID: ${{ secrets.PROD_TREETRACKER_CLIENT_ID }}
49+
PROD_TREETRACKER_CLIENT_SECRET: ${{ secrets.PROD_TREETRACKER_CLIENT_SECRET }}
50+
KEYSTORE_FILE: ${{ secrets.KEYSTORE_FILE }}
51+
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
52+
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
53+
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
54+
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Setup build environment
60+
uses: ./.github/workflows/actions/setup-build-environment
61+
62+
- name: Build APK
63+
uses: ./.github/workflows/actions/build-apk
64+
with:
65+
build_variant: ${{ inputs.build_variant }}
66+
decode_keystore: ${{ inputs.build_variant == 'release' || inputs.build_variant == 'prerelease' }}
67+
68+
- name: Upload APK artifact
69+
if: inputs.upload_artifact
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: app-${{ inputs.build_variant }}
73+
path: app/build/outputs/apk/${{ inputs.build_variant }}/*.apk
74+
retention-days: 30
75+
76+
- name: Clean up
77+
if: always()
78+
run: |
79+
rm -f treetracker.keys.properties
80+
rm -f keystore.jks
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Bump Version Code Only
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
bump-and-push:
8+
name: Bump version and push
9+
uses: ./.github/workflows/bump-version.yml
10+
secrets: inherit

.github/workflows/bump-version.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Bump Version Code
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
version_code:
7+
description: "The new version code"
8+
value: ${{ jobs.bump.outputs.version_code }}
9+
10+
jobs:
11+
bump:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
version_code: ${{ steps.bump.outputs.version_code }}
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.head_ref || github.ref }}
21+
fetch-depth: 0
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Bump version code
25+
id: bump
26+
uses: ./.github/workflows/actions/bump-version
27+
with:
28+
branch: ${{ github.head_ref || github.ref_name }}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Deploy to Firebase Beta
2+
3+
on:
4+
pull_request:
5+
branches: [ master, release* ]
6+
7+
jobs:
8+
bump-version:
9+
name: Bump version code
10+
runs-on: ubuntu-latest
11+
outputs:
12+
version_code: ${{ steps.bump.outputs.version_code }}
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.head_ref || github.ref }}
19+
fetch-depth: 0
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Bump version code
23+
id: bump
24+
uses: ./.github/workflows/actions/bump-version
25+
with:
26+
branch: ${{ github.head_ref || github.ref_name }}
27+
28+
build:
29+
name: Build beta APK
30+
needs: bump-version
31+
uses: ./.github/workflows/build.yml
32+
with:
33+
build_variant: beta
34+
upload_artifact: true
35+
secrets: inherit
36+
37+
deploy:
38+
name: Deploy to Firebase
39+
runs-on: ubuntu-latest
40+
needs: [bump-version, build]
41+
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
with:
46+
ref: master
47+
48+
- name: Download APK artifact
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: app-beta
52+
53+
- name: Deploy to Firebase App Distribution
54+
uses: wzieba/Firebase-Distribution-Github-Action@v1
55+
with:
56+
appId: 1:422699885542:android:aab16ef8fc4e5968a0ec27
57+
serviceCredentialsFileContent: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
58+
groups: Greenstand
59+
releaseNotes: "A new release! Build ${{ needs.bump-version.outputs.version_code }}"
60+
file: app-beta-release.apk
61+
62+
# notify:
63+
# name: Send Slack notifications
64+
# runs-on: ubuntu-latest
65+
# needs: [bump-version, deploy]
66+
# if: success()
67+
#
68+
# steps:
69+
# - name: Get git branch
70+
# id: git-branch
71+
# run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
72+
#
73+
# - name: Send Slack notification (main)
74+
# uses: slackapi/slack-github-action@v1
75+
# with:
76+
# payload: |
77+
# {
78+
# "text": "A new Greenstand Beta Build has been released on Firebase",
79+
# "blocks": [
80+
# {
81+
# "type": "section",
82+
# "text": {
83+
# "type": "mrkdwn",
84+
# "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 }}"
85+
# }
86+
# }
87+
# ]
88+
# }
89+
# env:
90+
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL }}
91+
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
92+
#
93+
# - name: Send Slack notification (QC)
94+
# uses: slackapi/slack-github-action@v1
95+
# with:
96+
# payload: |
97+
# {
98+
# "text": "A new Greenstand Beta Build has been released on Firebase",
99+
# "blocks": [
100+
# {
101+
# "type": "section",
102+
# "text": {
103+
# "type": "mrkdwn",
104+
# "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 }}"
105+
# }
106+
# }
107+
# ]
108+
# }
109+
# env:
110+
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL_QC }}
111+
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

0 commit comments

Comments
 (0)