From da1ea2cb41e57aaebd9cc10e897313a223cdeb29 Mon Sep 17 00:00:00 2001 From: Dmitri Chernysh Date: Thu, 10 Oct 2024 20:20:15 +0300 Subject: [PATCH] Added a new GitHub Actions job to create google-services.json dynamically (#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 --- .github/workflows/build-signed-bundle.yml | 6 ++++ .github/workflows/clean-up-artifacts.yml | 19 +++++++++++ .github/workflows/create-service-json.yml | 34 +++++++++++++++++++ .github/workflows/deploy.yml | 15 +++++++- .../{run_tests.yml => run-tests.yml} | 14 +++++--- .github/workflows/tests.yml | 31 +++++++++++++++++ .../peoplelist/PeopleListViewModelTest.kt | 1 + 7 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/clean-up-artifacts.yml create mode 100644 .github/workflows/create-service-json.yml rename .github/workflows/{run_tests.yml => run-tests.yml} (89%) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/build-signed-bundle.yml b/.github/workflows/build-signed-bundle.yml index 0e85a7c..c106902 100644 --- a/.github/workflows/build-signed-bundle.yml +++ b/.github/workflows/build-signed-bundle.yml @@ -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 diff --git a/.github/workflows/clean-up-artifacts.yml b/.github/workflows/clean-up-artifacts.yml new file mode 100644 index 0000000..da524ae --- /dev/null +++ b/.github/workflows/clean-up-artifacts.yml @@ -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 + diff --git a/.github/workflows/create-service-json.yml b/.github/workflows/create-service-json.yml new file mode 100644 index 0000000..83bf143 --- /dev/null +++ b/.github/workflows/create-service-json.yml @@ -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 + diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cd88a53..ec91a67 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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: @@ -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 diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run-tests.yml similarity index 89% rename from .github/workflows/run_tests.yml rename to .github/workflows/run-tests.yml index 2006f86..3b1b5bf 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,11 +2,8 @@ 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: @@ -14,6 +11,7 @@ on: 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 @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..f13c8f0 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/feature/people_list/src/test/kotlin/com/mobiledevpro/peoplelist/PeopleListViewModelTest.kt b/feature/people_list/src/test/kotlin/com/mobiledevpro/peoplelist/PeopleListViewModelTest.kt index 4a48f2d..3d7e7bb 100644 --- a/feature/people_list/src/test/kotlin/com/mobiledevpro/peoplelist/PeopleListViewModelTest.kt +++ b/feature/people_list/src/test/kotlin/com/mobiledevpro/peoplelist/PeopleListViewModelTest.kt @@ -64,6 +64,7 @@ class PeopleListViewModelTest { } } + @OptIn(ExperimentalCoroutinesApi::class) @After fun finish() = Dispatchers.resetMain() } \ No newline at end of file