Skip to content

Commit 404b37e

Browse files
committed
Migrate away from fastlane
1 parent c2ecc4f commit 404b37e

File tree

12 files changed

+476
-2
lines changed

12 files changed

+476
-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: 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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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: master
21+
fetch-depth: 0
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Set up git
25+
run: |
26+
git config --local user.email "automation@treetracker.org"
27+
git config --local user.name "Treetracker Automation"
28+
29+
- name: Bump version code
30+
id: bump
31+
run: |
32+
# Read current version code
33+
CURRENT_VERSION=$(grep -oP 'versionCode\s+\K\d+' app/build.gradle)
34+
NEW_VERSION=$((CURRENT_VERSION + 1))
35+
36+
# Update build.gradle
37+
sed -i "s/versionCode $CURRENT_VERSION/versionCode $NEW_VERSION/" app/build.gradle
38+
39+
# Output the new version
40+
echo "version_code=$NEW_VERSION" >> $GITHUB_OUTPUT
41+
echo "Bumped version from $CURRENT_VERSION to $NEW_VERSION"
42+
43+
- name: Commit version bump
44+
run: |
45+
git add app/build.gradle
46+
git commit -m "Version Bump to ${{ steps.bump.outputs.version_code }}"
47+
git push origin master
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Deploy to Firebase Beta
2+
3+
#on:
4+
# workflow_dispatch:
5+
6+
on:
7+
pull_request:
8+
branches: [ master, release* ]
9+
10+
jobs:
11+
bump-version:
12+
name: Bump version code
13+
uses: ./.github/workflows/bump-version.yml
14+
secrets: inherit
15+
16+
build:
17+
name: Build beta APK
18+
needs: bump-version
19+
uses: ./.github/workflows/build.yml
20+
with:
21+
build_variant: beta
22+
upload_artifact: true
23+
secrets: inherit
24+
25+
deploy:
26+
name: Deploy to Firebase
27+
runs-on: ubuntu-latest
28+
needs: [bump-version, build]
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
with:
34+
ref: master
35+
36+
- name: Download APK artifact
37+
uses: actions/download-artifact@v4
38+
with:
39+
name: app-beta
40+
41+
- name: Deploy to Firebase App Distribution
42+
uses: wzieba/Firebase-Distribution-Github-Action@v1
43+
with:
44+
appId: 1:422699885542:android:aab16ef8fc4e5968a0ec27
45+
serviceCredentialsFileContent: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
46+
groups: Greenstand
47+
releaseNotes: "A new release! Build ${{ needs.bump-version.outputs.version_code }}"
48+
file: app-beta-release.apk
49+
50+
notify:
51+
name: Send Slack notifications
52+
runs-on: ubuntu-latest
53+
needs: [bump-version, deploy]
54+
if: success()
55+
56+
steps:
57+
- name: Get git branch
58+
id: git-branch
59+
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
60+
61+
- name: Send Slack notification (main)
62+
uses: slackapi/slack-github-action@v1
63+
with:
64+
payload: |
65+
{
66+
"text": "A new Greenstand Beta Build has been released on Firebase",
67+
"blocks": [
68+
{
69+
"type": "section",
70+
"text": {
71+
"type": "mrkdwn",
72+
"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 }}"
73+
}
74+
}
75+
]
76+
}
77+
env:
78+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL }}
79+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
80+
81+
- name: Send Slack notification (QC)
82+
uses: slackapi/slack-github-action@v1
83+
with:
84+
payload: |
85+
{
86+
"text": "A new Greenstand Beta Build has been released on Firebase",
87+
"blocks": [
88+
{
89+
"type": "section",
90+
"text": {
91+
"type": "mrkdwn",
92+
"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 }}"
93+
}
94+
}
95+
]
96+
}
97+
env:
98+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL_QC }}
99+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Deploy to Google Play Store
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
bump-version:
8+
name: Bump version code
9+
uses: ./.github/workflows/bump-version.yml
10+
secrets: inherit
11+
12+
build:
13+
name: Build release APK
14+
needs: bump-version
15+
uses: ./.github/workflows/build.yml
16+
with:
17+
build_variant: release
18+
upload_artifact: true
19+
secrets: inherit
20+
21+
deploy:
22+
name: Upload to Play Store
23+
runs-on: ubuntu-latest
24+
needs: [bump-version, build]
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
ref: master
31+
32+
- name: Download APK artifact
33+
uses: actions/download-artifact@v4
34+
with:
35+
name: app-release
36+
37+
- name: Upload to Play Store
38+
uses: r0adkll/upload-google-play@v1
39+
with:
40+
serviceAccountJsonPlainText: ${{ secrets.PLAY_STORE_SERVICE_ACCOUNT }}
41+
packageName: org.greenstand.android.TreeTracker
42+
releaseFiles: app-release-release.apk
43+
track: production
44+
status: completed

0 commit comments

Comments
 (0)