name: schema-publish

# author: @ralfhandl
# issue: https://github.com/OAI/OpenAPI-Specification/issues/3715

#
# This workflow creates a pull request for publishing schema iterations to the gh-pages branch
#

# run this on push to vX.Y-dev branches or manually
on:
  push:
    branches:
      - 'v[0-9].[0-9]-dev'
    paths:
      - 'src/schemas/validation/*.yaml'
      - 'scripts/schema-publish.sh'
      - '.github/workflows/schema-publish.yaml'
  workflow_dispatch: {}

jobs:
  publish:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v5 # checkout main branch
      with:
        fetch-depth: 0

    - uses: actions/setup-node@v5 # setup Node.js
      with:
        node-version: '22.x'

    - name: Install dependencies
      run: npm ci

    - uses: actions/checkout@v5 # checkout gh-pages branch
      with:
        ref: gh-pages
        path: deploy

    - name: run main script
      run: scripts/schema-publish.sh

    - name: Create Pull Request
      uses: peter-evans/create-pull-request@v6
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.ref_name }}-publish-schema-iteration
        base: gh-pages
        delete-branch: true
        path: deploy
        labels: Housekeeping,Schema
        reviewers: darrelmiller,webron,earth2marsh,lornajane,mikekistler,miqui,ralfhandl,handrews,karenetheridge
        title: '${{ github.ref_name }}: publish OpenAPI schema iterations'
        commit-message: New OpenAPI schema iterations
        signoff: true
        body: |
          This pull request is automatically generated by GitHub action `schema-publish`.
          The `src/schemas/validation/*.yaml` files have changed and JSON files are automatically generated.
