Skip to content

Commit 79df236

Browse files
authored
feat: conditionally run rdme version depending on project status (#5)
* Update sync.yml * run on every sync * chore: copy edits * fix: syntax error * chore: more useful + cleaner debug output * step names * chore: empty commit to trigger build * revert: only do this on `main` * feat: also add legacy id flag * chore: warning syntax, add note to contact us
1 parent 8dc67e6 commit 79df236

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

.github/workflows/sync.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,38 @@ jobs:
1313
- name: Checkout this repo
1414
uses: actions/checkout@v4
1515

16-
# Run GitHub Action to sync OpenAPI file at [path-to-file.json]
17-
- name: GitHub Action
16+
# Fetches the refactored data from the ReadMe API's "Get project metadata" endpoint
17+
# https://docs.readme.com/main/reference/getproject-1
18+
- name: Grab Refactored data
19+
id: refactored
20+
run: |
21+
refactored=$(curl https://api.readme.com/v2/projects/me --header 'Authorization: Bearer ${{ secrets.README_API_KEY }}' | jq -c '.data.refactored')
22+
migrated=$(echo $refactored | jq -r '.migrated')
23+
status=$(echo $refactored | jq -r '.status')
24+
echo "Refactored data: $refactored"
25+
echo "Migrated: $migrated"
26+
echo "Status: $status"
27+
echo migrated=$migrated >> $GITHUB_OUTPUT
28+
echo status=$status >> $GITHUB_OUTPUT
29+
30+
# If project is not yet migrated, run legacy v9 action
31+
- name: Run rdme@9
1832
# We recommend specifying a fixed version, i.e. @v8
1933
# Docs: https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#example-using-versioned-actions
34+
if: ${{ steps.refactored.outputs.status == 'disabled' }}
2035
uses: readmeio/rdme@v9
2136
with:
2237
rdme: openapi petstore.json --key=${{ secrets.README_API_KEY }} --id=${{ secrets.README_API_DEFINITION_ID }}
38+
39+
# If project is successfully migrated, run v10 action
40+
- name: Run rdme@10
41+
if: ${{ steps.refactored.outputs.migrated == 'successful' && steps.refactored.outputs.status == 'enabled' }}
42+
uses: readmeio/rdme@v10
43+
with:
44+
rdme: openapi upload petstore.json --key=${{ secrets.README_API_KEY }} --legacy-id=${{ secrets.README_API_DEFINITION_ID }}
45+
46+
# If project is in an unexpected migration state, skip the rdme workflow
47+
- name: Skip due to unexpected migration state
48+
if: ${{ steps.refactored.outputs.migrated != 'successful' && steps.refactored.outputs.status == 'enabled' }}
49+
run: |
50+
echo "::warning::Project is in an unexpected migration state (${{ steps.refactored.outputs.migrated }}). Skipping `rdme` workflow. Please contact us (support@readme.io) if you keep running into this issue."

0 commit comments

Comments
 (0)