Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add test release workflow #105

Merged
merged 2 commits into from
Jan 18, 2025
Merged
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
125 changes: 125 additions & 0 deletions .github/workflows/test-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Compile and release test build

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
get-version:
name: Extract Version from pubspec.yaml
runs-on: ubuntu-latest
if: startsWith(github.head_ref, 'release-v')
outputs:
VERSION_NAME: ${{ steps.extract_version.outputs.VERSION_NAME }}
VERSION_NUMBER: ${{ steps.extract_version.outputs.VERSION_NUMBER }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract version from pubspec.yaml
id: extract_version
run: |
VERSION_FULL=$(grep '^version:' pubspec.yaml | sed 's/version: //')
VERSION_NAME=$(echo $VERSION_FULL | cut -d '+' -f 1)
VERSION_NUMBER=$(echo $VERSION_FULL | cut -d '+' -f 2)
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
echo "VERSION_NUMBER=$VERSION_NUMBER" >> $GITHUB_ENV
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_OUTPUT
echo "VERSION_NUMBER=$VERSION_NUMBER" >> $GITHUB_OUTPUT
echo "Extracted Version Name: $VERSION_NAME"
echo "Extracted Version Number: $VERSION_NUMBER"

build-android:
name: Build test Android .apk and .aab
runs-on: ubuntu-latest
needs: get-version
env:
ANDROID_AAB_RELEASE_PATH: build/app/outputs/bundle/release
ANDROID_APK_RELEASE_PATH: build/app/outputs/apk/release
VERSION_NAME: ${{ needs.get-version.outputs.VERSION_NAME }}
VERSION_NUMBER: ${{ needs.get-version.outputs.VERSION_NUMBER }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Decode android/app/keystore.jks
run: echo "${{ secrets.KEYSTORE_JKS }}" | base64 --decode > android/app/keystore.jks

- name: Decode android/key.properties
run: echo "${{ secrets.KEY_PROPERTIES }}" | base64 --decode > android/key.properties

# Enable: take screenshot and output debug log
- name: Decode .env
run: echo "${{ secrets.TEST_ENV }}" | base64 --decode > .env

- name: Setup Java 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
- run: flutter clean
- run: flutter pub get

- name: Build apk
run: flutter build apk --release

- name: Build aab
run: flutter build appbundle --release

- name: Rename apk
run: mv $ANDROID_APK_RELEASE_PATH/app-release.apk PiHoleClient_${{ env.VERSION_NAME }}_Android.apk

- name: Rename aab
run: mv $ANDROID_AAB_RELEASE_PATH/app-release.aab PiHoleClient_${{ env.VERSION_NAME }}_Android.aab

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: android
path: |
PiHoleClient_${{ env.VERSION_NAME }}_Android.apk
PiHoleClient_${{ env.VERSION_NAME }}_Android.aab

test-build-google-play:
name: Release Android test build to the Google Play Store
runs-on: ubuntu-latest
needs: [get-version, build-android]
permissions:
contents: read
id-token: write
env:
VERSION_NAME: ${{ needs.get-version.outputs.VERSION_NAME }}
VERSION_NUMBER: ${{ needs.get-version.outputs.VERSION_NUMBER }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download Android artifacts
uses: actions/download-artifact@v4
with:
name: android

- id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}

- name: Release app to Google Play
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJson: ${{ steps.auth.outputs.credentials_file_path }}
packageName: io.github.tsutsu3.pi_hole_client
releaseFiles: PiHoleClient_${{ env.VERSION_NAME }}_Android.aab
track: alpha # Available tracks are: production,beta,alpha,internal,test
status: draft
releaseName: ${{ env.VERSION_NAME }}
1 change: 1 addition & 0 deletions docs/ci-secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The following secrets contain **encoded files** and must be stored as
| `ENV` | `.env` file containing environment variables |
| `KEYSTORE_JKS` | Keystore file (`.jks`) for signing Android builds |
| `KEY_PROPERTIES` | Key properties file (`key.properties`) for the keystore |
| `TEST_ENV` | test `.env` file containing environment variables |

## 2️⃣ Using Workload Identity Federation through a Service Account

Expand Down
Loading