Skip to content

Prod-OpenAPI to CodiveAPI #20

Prod-OpenAPI to CodiveAPI

Prod-OpenAPI to CodiveAPI #20

Workflow file for this run

name: Prod-OpenAPI to CodiveAPI
on:
workflow_run:
workflows: [ "Clokey-Prod CD" ]
types: [ completed ]
workflow_dispatch: {}
permissions:
contents: read
concurrency:
group: sync-openapi
cancel-in-progress: true
jobs:
sync:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
env:
CODIVEAPI_BRANCH: main
TARGET_PATH: Sources/CodiveAPI/openapi.yaml
steps:
- name: Checkout backend repo (for context only)
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Fetch OpenAPI JSON from production
env:
PROD_OPENAPI_URL: ${{ secrets.PROD_OPENAPI_URL }}
run: |
set -euo pipefail
echo "Fetching OpenAPI from: $PROD_OPENAPI_URL"
curl -fsSL --retry 5 --retry-delay 2 --connect-timeout 10 --max-time 30 \
"$PROD_OPENAPI_URL" -o openapi.json
test -s openapi.json
head -c 1 openapi.json | grep -q '{'
- name: Convert OpenAPI JSON -> YAML (swagger-cli)
run: |
set -euo pipefail
npm i -g @apidevtools/swagger-cli@4
swagger-cli bundle openapi.json --type yaml --outfile openapi.yaml
- name: Checkout CodiveAPI repo
uses: actions/checkout@v4
with:
repository: Clokey-dev/CodiveAPI
ref: ${{ env.CODIVEAPI_BRANCH }}
token: ${{ secrets.CODIVEAPI_PAT }}
path: codiveapi
fetch-depth: 1
- name: Copy openapi.yaml into CodiveAPI
run: |
set -euo pipefail
cp openapi.yaml "codiveapi/${TARGET_PATH}"
- name: Detect change (stage openapi)
id: regen
working-directory: codiveapi
run: |
set -euo pipefail
git config user.name "codive-bot"
git config user.email "codive-bot@users.noreply.github.com"
git add "${TARGET_PATH}"
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No changes detected. Skipping commit. (staged)."
exit 0
fi
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "OpenAPI changed."
- name: Run generate script if changed
if: steps.regen.outputs.changed == 'true'
working-directory: codiveapi
run: |
set -euo pipefail
chmod +x ./regenerate-api.sh
./regenerate-api.sh
git add -A
- name: Commit & Push Changes if changed
if: steps.regen.outputs.changed == 'true'
working-directory: codiveapi
run: |
set -euo pipefail
git commit -m "chore: update openapi.yaml and regenerate API"
git push origin "${CODIVEAPI_BRANCH}"