From 6998a75ae920c67c740e3134acb0cf50359a859f Mon Sep 17 00:00:00 2001 From: piotradamczyk5 <65554637+piotradamczyk5@users.noreply.github.com> Date: Mon, 28 Dec 2020 06:46:00 +0100 Subject: [PATCH] ci: Auto update firebase api client (#1424) Fixes #1420 ## Test Plan > How do we know the code works? Every Monday morning together with dependencies update ( but on separate PR) pull request with google client library update is created. Under the hood it use commands (python 2.7 required) ```yaml pip install google-apis-client-generator flankScripts shell firebase updateApiJson flankScripts shell firebase generateJavaClient ``` so you could test this PR locally with them ## Checklist - [x] Fixed issues with update client - [x] Create Github Action to update client --- .github/workflows/update_dependencies.yml | 46 --------- .../update_dependencies_and_client.yml | 96 +++++++++++++++++++ flank-scripts/build.gradle.kts | 2 +- .../firebase/GenerateJavaClientCommand.kt | 5 +- .../shell/firebase/UpdateApiJsonCommand.kt | 2 +- .../flank/scripts/utils/DownloadSoftware.kt | 3 +- 6 files changed, 102 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/update_dependencies.yml create mode 100644 .github/workflows/update_dependencies_and_client.yml diff --git a/.github/workflows/update_dependencies.yml b/.github/workflows/update_dependencies.yml deleted file mode 100644 index a23b267649..0000000000 --- a/.github/workflows/update_dependencies.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Update dependencies - -on: - schedule: - - cron: '0 5 * * 1' # At 05:00 on Monday - workflow_dispatch: # or manually - -jobs: - update_dependencies: - runs-on: macos-latest - - steps: - - uses: actions/checkout@v2 - - - name: Gradle dependency updates raport - uses: eskatos/gradle-command-action@v1 - with: - arguments: dependencyUpdates -DoutputFormatter=json -DoutputDir=. - - - name: Download flankScripts and add it to PATH - run: | - ./gradlew :flank-scripts:download - echo "./flank-scripts/bash" >> $GITHUB_PATH - - - name: Update dependencies - run: | - flankScripts dependencies update - - - name: Get current date - id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - - - name: Commit files and create Pull request - id: pr - uses: peter-evans/create-pull-request@v3 - with: - commit-message: "[Automatic PR] Dependencies update" - signoff: false - branch: "dependencies-update-${{ steps.date.outputs.date }}" - title: "build: Dependencies updates [${{ steps.date.outputs.date }}]" - body: "Dependencies updates" - labels: | - automated pr - dependencies - reviewers: bootstraponline,jan-gogo,pawelpasterz,adamfilipow92,piotradamczyk5,Sloox,axelzuziak-gogo - draft: false diff --git a/.github/workflows/update_dependencies_and_client.yml b/.github/workflows/update_dependencies_and_client.yml new file mode 100644 index 0000000000..f54c330ffd --- /dev/null +++ b/.github/workflows/update_dependencies_and_client.yml @@ -0,0 +1,96 @@ +name: Update dependencies + +on: + schedule: + - cron: '0 5 * * 1' # At 05:00 on Monday + workflow_dispatch: # or manually + +jobs: + get_token_and_date: + runs-on: ubuntu-latest + outputs: + github_token: ${{ steps.generate-token.outputs.token }} + date: ${{ steps.date.outputs.date }} + steps: + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.FLANK_RELEASE_APP_ID }} + private_key: ${{ secrets.FLANK_RELEASE_PRIVATE_KEY }} + + - name: Get current date + id: date + run: echo "::set-output name=date::$(date +'%Y-%m-%d')" + + update_dependencies: + runs-on: macos-latest + needs: [ get_token_and_date ] + steps: + - uses: actions/checkout@v2 + + - name: Gradle dependency updates raport + uses: eskatos/gradle-command-action@v1 + with: + arguments: dependencyUpdates -DoutputFormatter=json -DoutputDir=. + + - name: Download flankScripts and add it to PATH + run: | + ./gradlew :flank-scripts:download + echo "./flank-scripts/bash" >> $GITHUB_PATH + + - name: Update dependencies + run: | + flankScripts dependencies update + + - name: Commit files and create Pull request + id: pr + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ needs.get_token_and_date.outputs.github_token }} + commit-message: "[Automatic PR] Dependencies update" + signoff: false + branch: "dependencies-update-${{ needs.get_token_and_date.outputs.date }}" + title: "build: Dependencies updates [${{ needs.get_token_and_date.outputs.date }}]" + body: "Dependencies updates" + labels: | + automated pr + dependencies + reviewers: bootstraponline,jan-gogo,pawelpasterz,adamfilipow92,piotradamczyk5,Sloox,axelzuziak-gogo + draft: false + + update_firebase_api: + runs-on: macos-latest + needs: [ get_token_and_date ] + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: '2.x' + + - name: Download flankScripts and add it to PATH + run: | + ./gradlew :flank-scripts:download + echo "./flank-scripts/bash" >> $GITHUB_PATH + + - name: Update Java Client + run: | + pip install google-apis-client-generator + flankScripts shell firebase updateApiJson + flankScripts shell firebase generateJavaClient + + - name: Commit files and create Pull request + id: pr + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ needs.get_token_and_date.outputs.github_token }} + commit-message: "[Automatic PR] Firebase API Client update" + signoff: false + branch: "firebase-api-client-update-${{ needs.get_token_and_date.outputs.date }}" + title: "build: Firebase API Client update [${{ needs.get_token_and_date.outputs.date }}]" + body: "Firebase Api update" + labels: | + automated pr + firease_api + reviewers: bootstraponline,jan-gogo,pawelpasterz,adamfilipow92,piotradamczyk5,Sloox,axelzuziak-gogo + draft: false diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index 30f2579d04..dbfe00b0b7 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -29,7 +29,7 @@ shadowJar.apply { } } // .. -version = "1.2.6" +version = "1.2.7" group = "com.github.flank" application { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/GenerateJavaClientCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/GenerateJavaClientCommand.kt index ff7f1ddee5..f4dc94355f 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/GenerateJavaClientCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/GenerateJavaClientCommand.kt @@ -14,9 +14,10 @@ object GenerateJavaClientCommand : CliktCommand(name = "generateJavaClient", hel override fun run() { checkIfPipInstalled() installClientGeneratorIfNeeded() - val apiPath = Paths.get("test_api").toString() + val firebaseApiPath = Paths.get("firebase_apis").toString() + val apiPath = Paths.get(firebaseApiPath, "test_api").toString() val outputDirectory = Paths.get(apiPath, "src", "main", "java").toString() - val testingJsonInput = Paths.get("json", "testing_v1.json").toString() + val testingJsonInput = Paths.get(firebaseApiPath, "json", "testing_v1.json").toString() Paths.get(apiPath, "src").toFile().deleteRecursively() val generateLibraryCommand = "generate_library " + diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/UpdateApiJsonCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/UpdateApiJsonCommand.kt index 88ee241119..3dd0d569b7 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/UpdateApiJsonCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/UpdateApiJsonCommand.kt @@ -9,7 +9,7 @@ import java.nio.file.Paths object UpdateApiJsonCommand : CliktCommand(name = "updateApiJson", help = "Download file for generating client") { override fun run() { - val jsonDirectoryPath = Paths.get(currentPath.toString(), "json") + val jsonDirectoryPath = Paths.get(currentPath.toString(), "firebase_apis", "json") val testingV1Path = Paths.get(jsonDirectoryPath.toString(), "testing_v1.json").toString() val testingV1Beta3Path = Paths.get(jsonDirectoryPath.toString(), "toolresults_v1beta3.json").toString() diff --git a/flank-scripts/src/main/kotlin/flank/scripts/utils/DownloadSoftware.kt b/flank-scripts/src/main/kotlin/flank/scripts/utils/DownloadSoftware.kt index b0ef93e09b..4238f1d539 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/utils/DownloadSoftware.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/utils/DownloadSoftware.kt @@ -26,6 +26,5 @@ fun downloadSortJsonIfNeeded() { } fun installClientGeneratorIfNeeded() { - val generateLibraryCheckCommand = (if (isWindows) "where " else "command -v ") + "generate_library" - generateLibraryCheckCommand.checkAndInstallIfNeed("pip install google-apis-client-generator") + "generate_library".checkAndInstallIfNeed("pip install google-apis-client-generator") }