name: Update Release List

on:
  release:
    types: [published]
  #workflow_run:
  #  workflows: ["Build Vim"]
  #  branches: [master]
  #  types: [completed]

permissions:
  contents: write # to update wiki

env:
  # Account for committing
  USER_NAME: "vim-win32-installer CI"
  USER_EMAIL: "k-takata@users.noreply.github.com"

  # Escape sequences
  COL_RED: "\x1b[31m"
  COL_GREEN: "\x1b[32m"
  COL_YELLOW: "\x1b[33m"
  COL_RESET: "\x1b[m"

jobs:
  update:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
      with:
        path: main

    - uses: actions/checkout@v4
      with:
        repository: "${{ github.repository }}.wiki"
        path: wiki

    - name: Update Release List
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        cd main
        latest=$(sed -e 's/\[\([0-9]*\.[0-9]*\.[0-9]*\)\].*/|\1/' -e 's/.*|//' gitlog.txt)
        cd ../wiki
        ../main/scripts/update-release-list.py
        git add Releases-in-*.md
        if git diff HEAD --quiet; then
          echo ${COL_YELLOW}No updates.${COL_RESET}
        else
          git config --local user.name ${USER_NAME}
          git config --local user.email ${USER_EMAIL}
          git commit -a -m "Update Release List to ${latest}"
          git push origin HEAD
        fi
