name: Community Project sync

on:
  issues:
    types: [opened, reopened, closed]
  pull_request_target:
    types: [opened, reopened, edited, converted_to_draft, ready_for_review, closed]
  schedule:
    - cron: '43 2 * * *'
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: community-project-sync-${{ github.repository }}-${{ github.event.issue && format('issue-{0}', github.event.issue.number) || github.event.pull_request && format('pull-request-{0}', github.event.pull_request.number) || 'reconcile' }}
  cancel-in-progress: false

jobs:
  sync:
    name: Reconcile Project status
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Check out the trusted default branch
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
        with:
          ref: ${{ github.event.repository.default_branch }}
          persist-credentials: false

      - name: Sync the Community Project
        env:
          GH_PROJECT_TOKEN: ${{ secrets.ACCESS_TOKEN }}
        run: node script/github/sync-community-project.js