Deployments

Automate Zuplo API Updates with GitHub Actions

Because Zuplo is OpenAPI native, you can automate the process of udating your Zuplo API when a downstream OpenAPI file changes. For example, if you have an API built in Go that uses Huma you can easily generate an OpenAPI file for your API. Then using that generated OpenAPI file, you can write a script that updates your Zuplo API based on changes in your generated file.

This example shows a GitHub Action that updates a Zuplo API from an OpenAPI file that is generated in your API.

You would run this Github Action in the repository that contains your downstream API. When you push changes to your API, the action will run, generate the OpenAPI file. Then it will clone the Zuplo API repository, update the Zuplo OpenAPI file, commit and push the changes to a new branch, and open a pull request. It will also generate an Action Summary that links to the Pull Request.

name: Update Zuplo API on: push: branches: - main jobs: release: name: Update Zuplo from OpenAPI runs-on: ubuntu-latest env: REPO_OWNER: my-org # the repository with your Zuplo API REPO_NAME: my-zuplo-api # the branch you want to update REPO_BRANCH: main steps: - uses: actions/checkout@v4 with: # Override the default token because the built # in token cannot trigger other workflows # https://github.community/t/github-actions-workflow-not-triggering-with-tag-push/17053/2 token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} - uses: actions/checkout@v4 with: repository: ${{ env.REPO_OWNER }}/${{ env.REPO_NAME }} path: temp ref: ${{ env.REPO_BRANCH }} token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} - name: Use Node.js uses: actions/setup-node@v4 with: node-version: 20.x cache: "npm" # Run your build/generate scripts here to generate the OpenAPI file - run: GENERATE OPEN API FILE HERE # Run your script to update the Zuplo API from the OpenAPI file # NOTE: This script is something you write based on your requirements - name: Update the OpenAPI File run: node ./scripts/update-zup-from-openapi.mjs - run: git config --global user.email "bot@example.com" - run: git config --global user.name "Updater Bot" - name: Commit Changes run: | git checkout -b "zup_${{ github.action_ref}}" git add -A git commit -m "Update OpenAPI File From ${{ github.repository }}" git push origin head - name: Open a Pull Request uses: actions/github-script@v7 with: github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} script: | const result = await github.rest.pulls.create({ title: "Update OpenAPI File From ${{ github.repository }}", owner: "${{ env.REPO_OWNER }}", repo: "${{ env.REPO_NAME }}", head: "zup_${{ github.action_ref}}", base: "${{ env.REPO_BRANCH }}", body: [ 'This PR is auto-generated by a GitHub Action.', 'Add more information here.' ].join('\n') }); // Update the Summary // You can do a lot more with this, see the core toolkit documentation // SEE: https://github.com/actions/toolkit/tree/main/packages/core#populating-job-summary await core.summary.addRaw(`Github Pull Request Opened. [Pull Request](${result.html_url}), true)

This script is a starting point. You will need to modify it to fit your needs. You might want to add more checks, tests, or other steps to ensure the update is correct. You can also add more information to the pull request body to help your team understand the changes.

Previous
Custom CI/CD