name: Update Browserslist Database

on:
  schedule:
    - cron: '0 0 * * 0'

permissions:
  contents: write
  pull-requests: write

jobs:
  update-browserslist-database:
    name: Create PR containing Browserslist updates
    runs-on: ubuntu-latest
    outputs:
      has_pr: ${{ steps.run-update-action.outputs.has_pr }}
      pr_status: ${{ steps.run-update-action.outputs.pr_status }}
      pr_number: ${{ steps.run-update-action.outputs.pr_number }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Configure git
        run: |
          git config --global user.email "action@github.com"
          git config --global user.name "GitHub Action"
      - name: Set legacy-peer-deps
        run: npm config set legacy-peer-deps true
      - name: Update Browserslist database and create PR if applicable
        id: run-update-action
        uses: c2corg/browserslist-update-action@v2
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: update/browserslist-db
          commit_message: 'Update Browserslist database.'
          title: 'Update Browserslist Database'
          body: Auto-generated by [browserslist-update-action](https://github.com/c2corg/browserslist-update-action/)
          base_branch: develop
  move-pr:
    name: Move PR in Zenhub board
    env:
      HAS_PR: ${{ needs.update-browserslist-database.outputs.has_pr }}
      PR_STATUS: ${{ needs.update-browserslist-database.outputs.pr_status }}
      PR_NUMBER: ${{ needs.update-browserslist-database.outputs.pr_number }}
    runs-on: ubuntu-latest
    needs: update-browserslist-database
    steps:
      - name: Move Zenhub card
        if: ${{ env.HAS_PR && env.PR_STATUS == 'created' }}
        uses: fjogeleit/http-request-action@v1
        with:
          url: 'https://api.zenhub.com/p2/workspaces/${{ secrets.ZENHUB_WORKSPACE_ID }}/repositories/${{ secrets.REPOSITORY_ID }}/issues/${{ env.PR_NUMBER }}/moves'
          method: 'POST'
          customHeaders: '{"Content-Type": "application/json", "X-Authentication-Token": "${{ secrets.ZENHUB_TOKEN }}"}'
          data: '{"pipeline_id": "${{ secrets.ZENHUB_MR_PIPELINE_ID }}", "position": "bottom"}'

Add GH workflow to automate Browserslist DB update.
Add GH workflow to automate Browserslist DB update.
