name: tld-update
on:
  schedule:
    # Run every hour, at the 15 minute mark. E.g.
    # 2020-11-29 00:15:00 UTC, 2020-11-29 01:15:00 UTC, 2020-11-29 02:15:00 UTC
    - cron:  '15 * * * *'
jobs:
  zlint-gtld-update:
    name: Check for TLD data updates
    runs-on: ubuntu-latest
    steps:

      - name: Check out code
        uses: actions/checkout@v2

      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: ^1.18

      - name: Set current date
        id: get-date
        run: echo "::set-output name=now::$(date +'%Y-%m-%dT%H:%M:%S %Z')"

      - name: Install zlint-gtld-update
        run: go install ./cmd/zlint-gtld-update/...
        working-directory: v3

      - name: Run go-generate
        run: go generate ./...
        working-directory: v3

      - name: Build
        run: make
        working-directory: v3

      - name: Test
        run: make test
        working-directory: v3

      - name: Create pull-request
        id: cpr
        uses: peter-evans/create-pull-request@v3
        with:
          commit-message: "util: gtld_map autopull updates for ${{ steps.get-date.outputs.now }}"
          title: "util: gtld_map autopull updates for ${{ steps.get-date.outputs.now }}"
          body: "ZLint gTLD data updates from `go generate ./...` for ${{ steps.get-date.outputs.now }}."
          committer: "GitHub <noreply@github.com>"
          author: "GitHub <noreply@github.com>"
          labels: tld-update
          branch: zlint-gtld-update
          delete-branch: true

      - name: Check outputs
        run: |
          echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
          echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
