name: "Generate latest definitions files"

env:
  VS_WORKFLOW_TYPE: "trigger-postman"

on:
  workflow_dispatch:

jobs:
  issue:
    name: "Creating GitHub update issue"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/checkout@v3
        with:
          repository: 'Adyen/adyen-openapi'
          path: 'adyen-openapi'
          fetch-depth: 0
      - name: Get changed files in the yaml folder
        id: changed-files-specific
        uses: tj-actions/changed-files@v35
        with:
          files: yaml/*.yaml
          path: 'adyen-openapi'
      - uses: JasonEtco/create-an-issue@v2
        if: ${{ steps.changed-files-specific.outputs.added_files != '' }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          FILENAMES: ${{ steps.changed-files-specific.outputs.added_files }}
        with:
          filename: .github/ISSUE_TEMPLATE/openapi-changes.yml
  generate:
    name: "Generate latest definitions files"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 2
      - uses: actions/checkout@v3
        with:
          repository: 'Adyen/adyen-openapi'
          fetch-depth: 0
          path: 'adyen-openapi'
      - uses: addnab/docker-run-action@v3
        with:
          image: gcatanese/openapi-generator-postman-v2
          options: -v ${{ github.workspace }}:/usr/src/app
          run: |
            /usr/src/app/generateAll.sh
      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: "Update latest definitions files"
      - name: push-adyen-collections-to-postman-javascript-action
        id: process
        uses: jlengrand/push-adyen-collections-to-postman-javascript-action@main
        with:
          postman-key: ${{ secrets.POSTMAN_API_KEY }}
          workspace-id: ${{ secrets.POSTMAN_WORKSPACE_ID }}
          path-to-process: "./postman"
