Skip to content

Commit

Permalink
Added a new GitHub Actions job to create google-services.json dynamic…
Browse files Browse the repository at this point in the history
…ally (#26)

* Create json

* Fixed a workflow name

* Upload to artifacs and delet from artifacts

* Remove artifacts even if a previous job is failed

* Download service json

* Echo json

* Check json from secret

* Check json from secret

* Check json from secret

* Last change

* Trigger changes in master only
  • Loading branch information
dmitriy-chernysh authored Oct 10, 2024
1 parent e47486b commit da1ea2c
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-signed-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Download Google Service JSON from GitHub artifacts
uses: actions/download-artifact@v4
with:
name: google_service_json
path: ./app

- name: Update dependencies
run: ./gradlew dependencies

Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/clean-up-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Clean up artifacts

on:
# Enables this workflow to be called from other workflows
workflow_call:

jobs:
remove-artifacs:
runs-on: ubuntu-latest

steps:
- uses: geekyeggo/delete-artifact@v5
with:
name: |
bundles
release_notes
google_service_json
failOnError: false

34 changes: 34 additions & 0 deletions .github/workflows/create-service-json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Create Google Service JSON

on:
# Enables this workflow to be called from other workflows
workflow_call:

jobs:
create-service-json:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Create Google Service JSON
run: |
echo '${{ secrets.GOOGLE_SERVICE_JSON }}' > \
${{ github.workspace }}/app/google-services.json | base64
- name: Check Google Service JSON file is created
run: |
if [ -f ./app/google-services.json ]; then
echo "google-services.json exists."
else
echo "google-services.json does not exist." >&2
exit 1
fi
continue-on-error: false

- name: Upload to artifacts
uses: actions/upload-artifact@v4
with:
name: google_service_json
path: ${{ github.workspace }}/app/google-services.json

15 changes: 14 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ jobs:
uses: ./.github/workflows/create-release-notes.yml
secrets: inherit

create-service-json:
uses: ./.github/workflows/create-service-json.yml
needs: create-release-notes
secrets: inherit

build-signed-bundle:
uses: ./.github/workflows/build-signed-bundle.yml
needs: create-release-notes
needs: create-service-json
secrets: inherit

create-github-release:
Expand All @@ -28,3 +33,11 @@ jobs:
uses: ./.github/workflows/deploy-to-open-track.yml
needs: build-signed-bundle
secrets: inherit

# It allow to remove artifacts created to use between workflows (google service json, bundles, etc)
remove-artifacts:
uses: ./.github/workflows/clean-up-artifacts.yml
needs: deploy-to-production-track
# Run this job even if "needs" job is failed
if: ${{ always() && contains(needs.*.result, 'failure') }}
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ name: Run Unit Tests

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Enables this workflow to be called from other workflows
workflow_call:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
Expand Down Expand Up @@ -43,6 +41,12 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Download Google Service JSON from GitHub artifacts
uses: actions/download-artifact@v4
with:
name: google_service_json
path: ./app

- name: Update dependencies
run: ./gradlew dependencies

Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Tests

on:

# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:

create-service-json:
uses: ./.github/workflows/create-service-json.yml
secrets: inherit

run-tests:
uses: ./.github/workflows/run-tests.yml
needs: create-service-json
secrets: inherit

# It allow to remove artifacts created to use between workflows (google service json, bundles, etc)
remove-artifacts:
uses: ./.github/workflows/clean-up-artifacts.yml
needs: run-tests
# Run this job even if "needs" job is failed
if: ${{ always() && contains(needs.*.result, 'failure') }}
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PeopleListViewModelTest {
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@After
fun finish() = Dispatchers.resetMain()
}

0 comments on commit da1ea2c

Please sign in to comment.