name: Update
"on":
  repository_dispatch:
    types:
      - octokit/openapi release
  push:
    branches:
      - renovate/openapi-typescript-*
  workflow_dispatch:
    inputs:
      version:
        description: Version of https://www.npmjs.com/package/@octokit/openapi
        required: true
jobs:
  update:
    runs-on: ubuntu-latest
    if: >-
      github.event_name == 'workflow_dispatch' ||
      github.event.client_payload.action == 'published'
    steps:
      - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
      - uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
        with:
          cache: npm
          node-version: 16
      - run: npm ci
      - run: >-
          echo "OCTOKIT_OPENAPI_VERSION=${{
          github.event.client_payload.release.tag_name }}" >> $GITHUB_ENV
        if: github.event.client_payload.release.tag_name
      - run: >-
          echo "OCTOKIT_OPENAPI_VERSION=${{ github.event.inputs.version }}" >>
          $GITHUB_ENV
        if: github.event.inputs.version
      - run: echo "OCTOKIT_OPENAPI_VERSION => $OCTOKIT_OPENAPI_VERSION"
      - uses: gr2m/await-npm-package-version-action@v1
        with:
          package: "@octokit/openapi"
          version: ${{ env.OCTOKIT_OPENAPI_VERSION }}
      - name: Update & generate types
        run: |
          npm run download
          npm run generate-types
          npm run update-package
        if: github.event_name != 'push'
      - name: Create Pull Request
        if: github.event_name != 'push'
        uses: gr2m/create-or-update-pull-request-action@v1.x
        env:
          GITHUB_TOKEN: ${{ secrets.OCTOKITBOT_PAT }}
        with:
          title: 🚧 OpenAPI types changed
          body: >
            Make sure to update the commits so that the merge results in helpful
            release notes, see [Merging the Pull Request & releasing a new
            version](https://github.com/octokit/rest.js/blob/master/CONTRIBUTING.md#merging-the-pull-request--releasing-a-new-version).


            In general


            - Avoid breaking changes at all costs

            - If there are no typescript changes, use `build: cache` as commit
            message

            - If there are there are only updates, use `fix: ...`

            - If there are any new additions, use `feat: ...`

            - If there are breaking changes, keep the previous ones and
            deprecate them. Only if there is no other way, add `BREAKING CHANGE:
            ...` to the commit body (not subject!) to trigger a breaking change.
          branch: openapi-update
          commit-message: WIP
          author: Octokit Bot <33075676+octokitbot@users.noreply.github.com>
          labels: maintenance,typescript
      - name: Create Pull Request
        if: github.event_name == 'push'
        uses: gr2m/create-or-update-pull-request-action@v1.x
        env:
          GITHUB_TOKEN: ${{ secrets.OCTOKITBOT_PAT }}
        with:
          title: 🚧 OpenAPI types changed
          body: >
            Make sure to update the commits so that the merge results in helpful
            release notes, see [Merging the Pull Request & releasing a new
            version](https://github.com/octokit/rest.js/blob/master/CONTRIBUTING.md#merging-the-pull-request--releasing-a-new-version).


            In general


            - Avoid breaking changes at all costs

            - If there are no typescript changes, use `build: cache` as commit
            message

            - If there are there are only updates, use `fix: ...`

            - If there are any new additions, use `feat: ...`

            - If there are breaking changes, keep the previous ones and
            deprecate them. Only if there is no other way, add `BREAKING CHANGE:
            ...` to the commit body (not subject!) to trigger a breaking change.
          branch: ${{ github.ref }}
          commit-message: WIP
          author: Octokit Bot <33075676+octokitbot@users.noreply.github.com>
          labels: maintenance,typescript
