# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: timezone-update

on:
  workflow_dispatch:
    branches: [ master, stable* ]
  schedule:
  - cron: "0 5 11 * *"

jobs:
  build:
    runs-on: windows-latest

    permissions:
      contents: write
      pull-requests: write
      
    steps:
    - uses: actions/checkout@v4
    - name: Setup .NET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: 8.0.x
    - name: Configure CMake
      run: cmake -G"Visual Studio 17 2022" -Bbuild -Swinpr\libwinpr\timezone\utils
    - name: Restore dependencies
      run: dotnet restore build\tzextract.sln
    - name: Build & Install CMake
      run: cmake --build build --config Release
    - name: Update timezones
      run: build\Release\tzextract.exe winpr\libwinpr\timezone
    - name: Format code
      run: |
        clang-format -i --style=file:.clang-format winpr/libwinpr/timezone/WindowsZones.c
        clang-format -i --style=file:.clang-format winpr/libwinpr/timezone/TimeZoneNameMap.c
        clang-format -i --style=file:.clang-format winpr/libwinpr/timezone/TimeZoneNameMap_static.h
        clang-format -i --style=file:.clang-format winpr/libwinpr/timezone/TimeZoneNameMap.json
    - name: Create Pull Request
      id: cpr
      uses: peter-evans/create-pull-request@v6
      with:
          commit-message: Update timezone definitions
          committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
          author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
          signoff: false
          branch: timezone-patches
          branch-suffix: timestamp
          delete-branch: true
          title: '[timezones] Update definitions'
          body: |
            Timezone update
            - Auto-generated by [create-pull-request][1]

            [1]: https://github.com/peter-evans/create-pull-request
          labels: |
            automated pr
          assignees: akallabeth
          reviewers: akallabeth
          draft: false
