Skip to content

Commit

Permalink
cleanup: github actions workflow
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iamdexterpark committed Nov 8, 2022
1 parent f6e3ea3 commit f5072ce
Show file tree
Hide file tree
Showing 28 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build/README.md → .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 43 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,69 @@
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"
git config user.email "<>"
- 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 }}
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

Empty file removed build/generated_at.txt
Empty file.
1 change: 0 additions & 1 deletion build/meraki-openapi-version.txt

This file was deleted.

0 comments on commit f5072ce

Please sign in to comment.