Skip to content

Add workflow to generate API specs and clients with a manual trigger #116

Add workflow to generate API specs and clients with a manual trigger

Add workflow to generate API specs and clients with a manual trigger #116

name: OpenAPI
on:
pull_request:
types: [opened, synchronize, labeled, reopened]
paths:
- 'server/application-server/**'
- '.github/workflows/generate-api-client.yml'
push:
paths:
- 'server/application-server/openapi.yaml'
- 'webapp/src/app/core/modules/openapi/**'
branches: [develop]
workflow_dispatch:
jobs:
generate-api-client:
name: Verify API Specs and Client
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Install dependencies
run: npm install
- name: Generate API client
run: npm run generate:api
- name: Check for changes in the API
id: check_changes
run: |
echo "Checking for changes in the API client directory..."
git add .
if git diff --cached --quiet; then
echo "No changes detected in the API client directory."
echo "NO_CHANGES_DETECTED=true" >> $GITHUB_ENV
else
echo "Changes detected in the API client directory."
echo "NO_CHANGES_DETECTED=false" >> $GITHUB_ENV
exit 1
fi
- name: Remove autocommit-openapi label if job succeeds
if: ${{ success() && github.event.label.name == 'autocommit-openapi' }}
run: |
echo "Removing the autocommit-openapi label..."
curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi
commit-changes:
name: Commit and Push API Client Changes
runs-on: ubuntu-latest
needs: generate-api-client
if: ${{ failure() && github.event.label.name == 'autocommit-openapi' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Install dependencies
run: npm install
- name: Generate API client
run: npm run generate:api
- name: Commit and push changes
run: |
echo "Committing and pushing changes..."
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: update API client"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove the label
run: |
echo "Removing the autocommit-api label..."
curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi