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

Optimize GitHub Actions Workflow for Android CI #16

Closed
wants to merge 2 commits into from
Closed
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
24 changes: 23 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch: # allows manual triggering


concurrency:
group: build-${{ github.ref }}
Expand All @@ -24,6 +26,11 @@ jobs:
distribution: 'temurin'
cache: gradle

- name: Decode and write google service json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we can reuse steps by defining a yaml anchor before, e.g before jobs:

firebase-setup: &firebase-setup
  - name: Decode and write google service json
    env:
      GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
    run: echo $GOOGLE_SERVICES_JSON | base64 --decode >./app/google-services.json

and reuse it here: - <<: *firebase-setup and in other jobs.

Also, we need to inject the json only for jobs that require a project build (gradlew build). Do dokka, lint and test depend on build? Maybe test yes, but not sure whether it is needed for the others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really cool idea; I have not used that before.
Unfortunately, according to this issue actions/runner/#1182 this syntax doesn't seem to be supported in the GitHub Action YAML.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had also assumed that only build and test needed the google json, but the github action only went through when I added the google-services.json at every single step

env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo $GOOGLE_SERVICES_JSON | base64 --decode >./app/google-services.json

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
Expand All @@ -47,6 +54,11 @@ jobs:
distribution: 'adopt'
java-version: '17'

- name: decode and write google service json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo $GOOGLE_SERVICES_JSON | base64 --decode >./app/google-services.json

- name: Grant execute permissions for gradlew
run: chmod +x ./gradlew

Expand All @@ -66,6 +78,11 @@ jobs:
java-version: '17'
cache: gradle

- name: decode and write google service json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo $GOOGLE_SERVICES_JSON | base64 --decode >./app/google-services.json

- name: Grant execute permissions for gradlew
run: chmod +x ./gradlew
- name: Run Lint with Gradle
Expand All @@ -90,6 +107,11 @@ jobs:
java-version: '17'
cache: gradle

- name: decode and write google service json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo $GOOGLE_SERVICES_JSON | base64 --decode >./app/google-services.json

- name: Grant execute permissions for gradlew
run: chmod +x ./gradlew
- name: Run Dokka with Gradle
Expand All @@ -99,4 +121,4 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: build/dokka/htmlMultiModule
folder: build/dokka/htmlMultiModule
Loading