Skip to content

Commit

Permalink
ci: Auto update firebase api client (#1424)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piotradamczyk5 authored Dec 28, 2020
1 parent 3b4bd90 commit 6998a75
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 52 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/update_dependencies.yml

This file was deleted.

96 changes: 96 additions & 0 deletions .github/workflows/update_dependencies_and_client.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.2.6"
version = "1.2.7"
group = "com.github.flank"

application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 6998a75

Please sign in to comment.