# triggered on commit to rep
# triggers specific workflow in curl enpoint (that workflow needs workflow_disptach)

name: CommitToBSEndToEnd

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on: push
 
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  bump-pub:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          registry-url: https://registry.npmjs.org/
      - run: npm ci

     # bumps minor version
      - run: echo "Token ${{ secrets.GITHUB_TOKEN }}"
      - run: echo "Repo ${{ github.repository }}"
      - run: echo "Head ${{ github.head_ref }}"
      - run: npm version patch
      - run: git push "https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"

      # publishes with credentials
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
  
  


  trigger-BStest:
   runs-on: ubuntu-latest
   steps:
   
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - name: Trigger Tests
      
      run: |
        curl -L \
        -X POST \
        -H "Accept: application/vnd.github+json" \
        -u "StephanLuis:${{secrets.PAT_KEY}}" \
        -H "X-GitHub-Api-Version: 2022-11-28" \
        https://api.github.com/repos/StephanLuis/BrowserStackSelenium/actions/workflows/78546395/dispatches \
        -d '{"ref":"main"}'
