-
Notifications
You must be signed in to change notification settings - Fork 4
86 lines (75 loc) · 3.19 KB
/
sync-api-docs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Sync docs in ReadMe 🦉
on:
pull_request:
push:
branches:
# This workflow will run every time changes in the OpenAPI docs are
# pushed to the `main` branch.
- main
paths:
- 'openapi/v2/**'
jobs:
sync-openapi-private-dev:
name: Keep private (dev) docs in sync with latest pull request
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Check out repo 📚
uses: actions/checkout@v3
- name: Sync OpenAPI docs 📜
uses: readmeio/rdme@v8
with:
rdme: openapi openapi/v2/service.swagger.yaml --title "🔮 Instill AI API (PR ${{ github.ref_name }})" --key=${{ secrets.README_API_KEY }} --id=671f3ec63ce9be54bc25adb8
sync-openapi-private-staging:
name: Keep private (staging) docs in sync with `main`
if: github.ref == 'refs/heads/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 OpenAPI docs 📜
uses: readmeio/rdme@v8
with:
rdme: openapi openapi/v2/service.swagger.yaml --key=${{ secrets.README_API_KEY }} --id=671f3f971dc007003da17bbc
- 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=openapi/v2/conf.proto
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-staging]
runs-on: ubuntu-latest
if: needs.sync-openapi-private-staging.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-staging.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-staging.outputs.old_release }}
with:
rdme: versions:delete ${{ env.OldRelease }} --key=${{ secrets.README_API_KEY }}