From f5072ce8d71d1afd7afe7e4025234e3a0bdcc947 Mon Sep 17 00:00:00 2001 From: Dexter Park Date: Tue, 8 Nov 2022 09:07:43 +0900 Subject: [PATCH] cleanup: github actions workflow Split Github actions workflow into two jobs: 1) Version check if a client needs to be generated 2) Generate new client with git tag/release Moved templates into .github folder, and deleted the build folder/files. removed .gitignore from repo. --- {build => .github}/README.md | 2 +- {build => .github}/templates/.travis.yml | 0 {build => .github}/templates/README.mustache | 0 {build => .github}/templates/api.mustache | 0 {build => .github}/templates/api_doc.mustache | 0 .../templates/api_test.mustache | 0 {build => .github}/templates/client.mustache | 0 .../templates/configuration.mustache | 0 .../templates/git_push.sh.mustache | 0 .../templates/gitignore.mustache | 0 {build => .github}/templates/go.mod.mustache | 0 {build => .github}/templates/go.sum | 0 {build => .github}/templates/model.mustache | 0 .../templates/model_anyof.mustache | 0 .../templates/model_doc.mustache | 0 .../templates/model_enum.mustache | 0 .../templates/model_oneof.mustache | 0 .../templates/model_simple.mustache | 0 .../templates/nullable_model.mustache | 0 {build => .github}/templates/openapi.mustache | 0 .../templates/partial_header.mustache | 0 .../templates/response.mustache | 0 {build => .github}/templates/signing.mustache | 0 {build => .github}/templates/utils.mustache | 0 .github/workflows/main.yml | 61 +++++++++++++------ .gitignore | 4 -- build/generated_at.txt | 0 build/meraki-openapi-version.txt | 1 - 28 files changed, 44 insertions(+), 24 deletions(-) rename {build => .github}/README.md (98%) rename {build => .github}/templates/.travis.yml (100%) rename {build => .github}/templates/README.mustache (100%) rename {build => .github}/templates/api.mustache (100%) rename {build => .github}/templates/api_doc.mustache (100%) rename {build => .github}/templates/api_test.mustache (100%) rename {build => .github}/templates/client.mustache (100%) rename {build => .github}/templates/configuration.mustache (100%) rename {build => .github}/templates/git_push.sh.mustache (100%) rename {build => .github}/templates/gitignore.mustache (100%) rename {build => .github}/templates/go.mod.mustache (100%) rename {build => .github}/templates/go.sum (100%) rename {build => .github}/templates/model.mustache (100%) rename {build => .github}/templates/model_anyof.mustache (100%) rename {build => .github}/templates/model_doc.mustache (100%) rename {build => .github}/templates/model_enum.mustache (100%) rename {build => .github}/templates/model_oneof.mustache (100%) rename {build => .github}/templates/model_simple.mustache (100%) rename {build => .github}/templates/nullable_model.mustache (100%) rename {build => .github}/templates/openapi.mustache (100%) rename {build => .github}/templates/partial_header.mustache (100%) rename {build => .github}/templates/response.mustache (100%) rename {build => .github}/templates/signing.mustache (100%) rename {build => .github}/templates/utils.mustache (100%) delete mode 100644 .gitignore delete mode 100644 build/generated_at.txt delete mode 100644 build/meraki-openapi-version.txt diff --git a/build/README.md b/.github/README.md similarity index 98% rename from build/README.md rename to .github/README.md index 5fbcabdda..03d250865 100644 --- a/build/README.md +++ b/.github/README.md @@ -33,7 +33,7 @@ java -jar openapi-generator-cli.jar generate \ -p enumClassPrefix=true \ -p structPrefix=true \ -p packageVersion=$API_VERSION \ - -t build/templates \ + -t .github/templates \ --package-name client \ --git-user-id meraki \ --git-repo-id dashboard-api-go \ diff --git a/build/templates/.travis.yml b/.github/templates/.travis.yml similarity index 100% rename from build/templates/.travis.yml rename to .github/templates/.travis.yml diff --git a/build/templates/README.mustache b/.github/templates/README.mustache similarity index 100% rename from build/templates/README.mustache rename to .github/templates/README.mustache diff --git a/build/templates/api.mustache b/.github/templates/api.mustache similarity index 100% rename from build/templates/api.mustache rename to .github/templates/api.mustache diff --git a/build/templates/api_doc.mustache b/.github/templates/api_doc.mustache similarity index 100% rename from build/templates/api_doc.mustache rename to .github/templates/api_doc.mustache diff --git a/build/templates/api_test.mustache b/.github/templates/api_test.mustache similarity index 100% rename from build/templates/api_test.mustache rename to .github/templates/api_test.mustache diff --git a/build/templates/client.mustache b/.github/templates/client.mustache similarity index 100% rename from build/templates/client.mustache rename to .github/templates/client.mustache diff --git a/build/templates/configuration.mustache b/.github/templates/configuration.mustache similarity index 100% rename from build/templates/configuration.mustache rename to .github/templates/configuration.mustache diff --git a/build/templates/git_push.sh.mustache b/.github/templates/git_push.sh.mustache similarity index 100% rename from build/templates/git_push.sh.mustache rename to .github/templates/git_push.sh.mustache diff --git a/build/templates/gitignore.mustache b/.github/templates/gitignore.mustache similarity index 100% rename from build/templates/gitignore.mustache rename to .github/templates/gitignore.mustache diff --git a/build/templates/go.mod.mustache b/.github/templates/go.mod.mustache similarity index 100% rename from build/templates/go.mod.mustache rename to .github/templates/go.mod.mustache diff --git a/build/templates/go.sum b/.github/templates/go.sum similarity index 100% rename from build/templates/go.sum rename to .github/templates/go.sum diff --git a/build/templates/model.mustache b/.github/templates/model.mustache similarity index 100% rename from build/templates/model.mustache rename to .github/templates/model.mustache diff --git a/build/templates/model_anyof.mustache b/.github/templates/model_anyof.mustache similarity index 100% rename from build/templates/model_anyof.mustache rename to .github/templates/model_anyof.mustache diff --git a/build/templates/model_doc.mustache b/.github/templates/model_doc.mustache similarity index 100% rename from build/templates/model_doc.mustache rename to .github/templates/model_doc.mustache diff --git a/build/templates/model_enum.mustache b/.github/templates/model_enum.mustache similarity index 100% rename from build/templates/model_enum.mustache rename to .github/templates/model_enum.mustache diff --git a/build/templates/model_oneof.mustache b/.github/templates/model_oneof.mustache similarity index 100% rename from build/templates/model_oneof.mustache rename to .github/templates/model_oneof.mustache diff --git a/build/templates/model_simple.mustache b/.github/templates/model_simple.mustache similarity index 100% rename from build/templates/model_simple.mustache rename to .github/templates/model_simple.mustache diff --git a/build/templates/nullable_model.mustache b/.github/templates/nullable_model.mustache similarity index 100% rename from build/templates/nullable_model.mustache rename to .github/templates/nullable_model.mustache diff --git a/build/templates/openapi.mustache b/.github/templates/openapi.mustache similarity index 100% rename from build/templates/openapi.mustache rename to .github/templates/openapi.mustache diff --git a/build/templates/partial_header.mustache b/.github/templates/partial_header.mustache similarity index 100% rename from build/templates/partial_header.mustache rename to .github/templates/partial_header.mustache diff --git a/build/templates/response.mustache b/.github/templates/response.mustache similarity index 100% rename from build/templates/response.mustache rename to .github/templates/response.mustache diff --git a/build/templates/signing.mustache b/.github/templates/signing.mustache similarity index 100% rename from build/templates/signing.mustache rename to .github/templates/signing.mustache diff --git a/build/templates/utils.mustache b/.github/templates/utils.mustache similarity index 100% rename from build/templates/utils.mustache rename to .github/templates/utils.mustache diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5716a8dc5..9d8207888 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,30 +1,55 @@ -name: Generate OpenAPI +name: Generate OpenAPI Client on: push: branches: - main + schedule: ## Schedule the job to run bi-weekly at 8AM. + - cron: '* 8 1,15 * *' jobs: + check-for-updates: + runs-on: ubuntu-latest + env: + OPENAPI_REPO: "https://raw.githubusercontent.com/meraki/openapi/master/openapi/spec2.json" + CLIENT_REPO: "https://api.github.com/repos/meraki/dashboard-api-go/releases/latest" + outputs: + result: ${{ steps.generate-new-client.outputs.RESULT }} + current: ${{ steps.generate-new-client.outputs.CURRENT }} + new: ${{ steps.generate-new-client.outputs.NEW }} + steps: + - name: "Install JSON Parser" + run: sudo apt update && sudo apt install -y jq + - name: "Get Previous API Version" + run: echo "CURRENT_API_VERSION=$(curl -s GET $CLIENT_REPO | jq -r '.tag_name' | head -n1)" >> $GITHUB_ENV + - name: "Get New API Version" + run: echo "NEW_API_VERSION=v$(curl $OPENAPI_REPO | jq '.info.version' | tr -d '\"')" >> $GITHUB_ENV + - name: "Export Results" + id: generate-new-client + run: | + echo "NEW=${{ env.NEW_API_VERSION }}" >> $GITHUB_OUTPUT + echo "CURRENT=${{ env.CURRENT_API_VERSION }}" >> $GITHUB_OUTPUT + if [ "${{ env.NEW_API_VERSION }}" = "${{ env.CURRENT_API_VERSION }}" ]; then + echo "RESULT=false" >> $GITHUB_OUTPUT + else + echo "RESULT=true" >> $GITHUB_OUTPUT + fi + generate-client: + needs: check-for-updates runs-on: ubuntu-latest + if: needs.check-for-updates.outputs.result == 'true' steps: - name: "Checkout Repository" - uses: actions/checkout@v2 - - name: "Set Version" - run: echo "API_VERSION=$(cat meraki-openapi-version.txt | tr -d '\n')" >> $GITHUB_ENV - working-directory: ./build + uses: actions/checkout@v3 + - name: "Fetch Specification" + run: wget https://github.com/meraki/openapi/archive/refs/tags/${{ needs.check-for-updates.outputs.new }}.zip && unzip -j ${{ needs.check-for-updates.outputs.new }}.zip '*/spec2.json' - name: "Install JRE" run: sudo apt update && sudo apt install -y default-jre - - name: "Fetch Specification" - run: wget https://github.com/meraki/openapi/archive/refs/tags/$API_VERSION.zip && unzip -j $API_VERSION.zip '*/spec2.json' - name: "Install OpenAPI Generator" run: wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.3.0/openapi-generator-cli-5.3.0.jar -O openapi-generator-cli.jar - name: "Run OpenAPI Generator" - run: rm -rf client/; java -jar openapi-generator-cli.jar generate -i spec2.json -g go -o client -p enumClassPrefix=true -p structPrefix=true --package-name client -p packageVersion=$API_VERSION --git-user-id meraki --git-repo-id dashboard-api-go/client --git-host github.com - - name: "Timestamp" - run: date > generated_at.txt - working-directory: ./build + run: rm -rf client/; java -jar openapi-generator-cli.jar generate -i spec2.json -g go -o client -p enumClassPrefix=true -p structPrefix=true --package-name client -p packageVersion=${{ needs.check-for-updates.outputs.new }} -t .github/templates --git-user-id meraki --git-repo-id dashboard-api-go/client --git-host github.com - name: "Cleanup" - run: rm openapi-generator-cli.jar; rm spec2.json; rm $API_VERSION.zip + run: rm openapi-generator-cli.jar; rm spec2.json; rm ${{ needs.check-for-updates.outputs.new }}.zip - name: "Git Config" run: | git config user.name "GitHub Actions" @@ -32,13 +57,13 @@ jobs: - name: "Git Commit" run: | git add -A - git commit -m "OpenAPI client generation $API_VERSION" - git tag $API_VERSION + git commit -m "OpenAPI client generation ${{ needs.check-for-updates.outputs.new }}" + git tag ${{ needs.check-for-updates.outputs.new }} git push origin main - git push origin $API_VERSION + git push origin ${{ needs.check-for-updates.outputs.new }} - name: Create a GitHub release uses: ncipollo/release-action@v1 with: - tag: ${{ env.API_VERSION }} - name: Release ${{ env.API_VERSION }} - body: Meraki Golang Dashboard API ${{ env.API_VERSION }} + tag: ${{ needs.check-for-updates.outputs.new }} + name: Release ${{ needs.check-for-updates.outputs.new }} + body: Meraki Golang Dashboard API ${{ needs.check-for-updates.outputs.new }} \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bb85d6ee7..000000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ - -openapi-generator-cli.jar -*.idea/ -.DS_Store diff --git a/build/generated_at.txt b/build/generated_at.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/build/meraki-openapi-version.txt b/build/meraki-openapi-version.txt deleted file mode 100644 index df407721e..000000000 --- a/build/meraki-openapi-version.txt +++ /dev/null @@ -1 +0,0 @@ -v1.27.0