Skip to content

trigger-cloud-api-docs #46

trigger-cloud-api-docs

trigger-cloud-api-docs #46

name: Fetch and Save Cloud API Spec
on:
workflow_dispatch: # Allows manual trigger of the workflow
repository_dispatch: # Allows other repositories to trigger this workflow
types: [trigger-cloud-api-docs]
jobs:
fetch-and-save-cloud-api-spec:
runs-on: ubuntu-latest
steps:
- name: Check out repository (main branch)
uses: actions/checkout@v3
with:
ref: 'main'
path: redpanda-docs
token: ${{ secrets.VBOT_GITHUB_API_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: |
cd ./redpanda-docs/scripts/get-api-specs
npm install
- name: Run the script and save the output
run: node ./redpanda-docs/scripts/get-api-specs/get-cloud-api-spec.js > ./redpanda-docs/cloud-api.yaml
env:
VBOT_GITHUB_API_TOKEN: ${{ secrets.ACTIONS_BOT_TOKEN }}
- name: Check out the api branch
run: |
cd ./redpanda-docs
git fetch --all
git checkout api
# Copy the generated file to the api branch
- name: Copy the file to the api branch
run: |
mv ./redpanda-docs/cloud-api.yaml ./redpanda-docs/modules/ROOT/attachments/cloud-api.yaml
- name: Check if changes were made
id: check_changes
run: |
cd ./redpanda-docs
git status --porcelain
if [ $(git status --porcelain | grep -v 'node_modules\|scripts/' | wc -l) -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_ENV
else
echo "has_changes=false" >> $GITHUB_ENV
fi
- name: Commit changes to the api branch
if: env.has_changes == 'true'
run: |
cd ./redpanda-docs
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add modules/ROOT/attachments/cloud-api.yaml
git commit -m "auto-docs: Update Cloud API spec"
git push origin api
env:
ACCESS_TOKEN: ${{ secrets.VBOT_GITHUB_API_TOKEN }}