name: Raw API

on:
    push:
        branches: [main]
        paths:
            - "domains/*"
            - ".github/workflows/raw-api.yml"
            - "util/raw-api.js"
            - "util/reserved.json"

    workflow_dispatch:

concurrency:
    group: ${{ github.ref }}-raw-api
    cancel-in-progress: true

jobs:
    update:
        name: Update
        runs-on: ubuntu-latest

        steps:
            - uses: actions/checkout@v4

            - uses: actions/setup-node@v4
              with:
                  node-version: 20.x

            - name: Update Data
              run: node util/raw-api.js

            - name: Create CNAME
              run: echo "raw.is-a.dev" > raw-api/CNAME

            - name: Commit
              uses: cpina/github-action-push-to-another-repository@main
              with:
                  source-directory: "raw-api"
                  destination-github-username: is-a-dev
                  destination-repository-name: raw-api
                  user-email: "actions@github.com"
                  user-name: "GitHub Actions"
              env:
                  API_TOKEN_GITHUB: ${{ secrets.BOT }}
