---
name: "Schedule: Sync labels"

on: # yamllint disable-line rule:truthy
  workflow_dispatch:
  schedule:
    - cron: "0 * * * *"

jobs:
  labels:
    name: Sync Labels
    runs-on: ubuntu-latest
    if: github.repository == 'k8s-at-home/charts'
    steps:
      - name: Generate Token
        uses: tibdex/github-app-token@v1
        id: generate-token
        with:
          app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
          private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}

      - name: Checkout
        uses: actions/checkout@v3
        with:
          token: ${{ steps.generate-token.outputs.token }}

      - name: Sync Labels
        uses: EndBug/label-sync@v2
        with:
          config-file: .github/labels.yaml
          token: "${{ steps.generate-token.outputs.token }}"
          delete-other-labels: true
