Skip to content

Commit

Permalink
feat(openapi): keep public and private API docs in sync with main bra…
Browse files Browse the repository at this point in the history
…nch (#270)

Because

- OpenAPI changes require manual uploads in ReadMe.com
- We have no staging docs

This commit

- Syncs the `main` branch with the public and private version of the API
    - Changes in main branch update the staging docs
    - Version changes in main branch update the public docs


## Notes

I created [a playground
environment](https://github.com/jvallesm/instill-protobufs) to test the
GitHub actions:

- See the [README](https://github.com/jvallesm/instill-protobufs) for a
more detailed explanation.
- Workflow run [without version
changes](https://github.com/jvallesm/instill-protobufs/actions/runs/7899195585/job/21558124375).
- Workflow run [with version
changes](https://github.com/jvallesm/instill-protobufs/actions/runs/7899206790).

✅  This PR will need:
- [x] Changes in ReadMe.com to have a staging version + adapt existing
version to the naming introduced in this one.
- [x] An update in the workflow to match the staging API reference IDs
to those in the Instill AI organization.
- [x] A `README_API_KEY` repository variable.
  • Loading branch information
jvallesm authored Feb 15, 2024
1 parent a8196c1 commit 36c13f8
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/sync-api-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Sync docs in ReadMe 🦉

on:
push:
branches:
# This workflow will run every time changes in the OpenAPI docs are
# pushed to the `main` branch.
- main
paths:
- 'openapiv2/core/**'
- 'openapiv2/model/**'
- 'openapiv2/vdp/**'

jobs:
sync-openapi-private:
name: Keep private (staging) docs in sync with `main`
runs-on: ubuntu-latest
outputs:
old_release: ${{ steps.check-new-release.outputs.old_release }}
new_release: ${{ steps.check-new-release.outputs.new_release }}
steps:
- name: Check out repo 📚
uses: actions/checkout@v3
with:
# Needed in check-new-release to compare with the previous commit.
fetch-depth: 0

- name: Sync Core 🔮
uses: readmeio/rdme@v8
with:
rdme: openapi openapiv2/core/service.swagger.yaml --key=${{ secrets.README_API_KEY }} --id=65bcfc78e72e300017c0b162

- name: Sync Model ⚗️
uses: readmeio/rdme@v8
with:
rdme: openapi openapiv2/model/service.swagger.yaml --key=${{ secrets.README_API_KEY }} --id=65bcfc78e72e300017c0b163

- name: Sync VDP 💧
uses: readmeio/rdme@v8
with:
rdme: openapi openapiv2/vdp/service.swagger.yaml --key=${{ secrets.README_API_KEY }} --id=65bcfc78e72e300017c0b164

- name: Check new release 🔍
id: check-new-release
run: |
# If the version in the OpenAPI configuration has changed, extract
# the old and new release versions (without the "v" prefix) to
# variables.
version_file=common/openapi/v1beta/api_info.conf
capture_old='^-\s\+\<version:'
capture_new='^+\s\+\<version:'
extract_version='s/.*"v\(.*\)".*/\1/'
old_version=$(git diff ${{ github.event.before }} ${{ github.event.after }} $version_file | grep $capture_old | sed $extract_version)
new_version=$(git diff ${{ github.event.before }} ${{ github.event.after }} $version_file | grep $capture_new | sed $extract_version)
if [[ $new_version ]]; then
echo "new_release=$new_version" >> $GITHUB_OUTPUT
echo "old_release=$old_version" >> $GITHUB_OUTPUT
fi
sync-openapi-public:
name: Sync public docs on new release
needs: [sync-openapi-private]
runs-on: ubuntu-latest
if: needs.sync-openapi-private.outputs.new_release != ''
steps:
- name: Check out repo 📚
uses: actions/checkout@v3

- name: Create new version 🚀
uses: readmeio/rdme@v8
env:
Release: ${{ needs.sync-openapi-private.outputs.new_release }}
with:
rdme: versions:create ${{ env.Release }} --fork 0-beta-staging --codename=${{ env.Release}} --main true --beta true --isPublic true --key=${{ secrets.README_API_KEY }}

- name: Delete old version 🧹
uses: readmeio/rdme@v8
env:
OldRelease: ${{ needs.sync-openapi-private.outputs.old_release }}
with:
rdme: versions:delete ${{ env.OldRelease }} --key=${{ secrets.README_API_KEY }}

0 comments on commit 36c13f8

Please sign in to comment.