name: weekly-update

on:
  schedule:
    - cron: '0 0 * * 0'
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  weekly_update:
    name: Rubygems weekly update
    runs-on: ${{ matrix.os }}
    if: github.repository == 'rubygems/rubygems'
    strategy:
      matrix:
        os: [ ubuntu-24.04 ]
    steps:
      - name: Config git
        run: |
          git config --global user.name "License Update"
          git config --global user.email license.update@rubygems.org
          git config --global push.autoSetupRemote true

      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Check versions
        run: |
          ruby --version
          rake --version

      - name: Update SPDX license list
        run: |
          rake update_licenses_branch
          git diff --no-ext-diff --ignore-submodules --quiet "${BASE##*/}" -- || {
            git push origin
            gh pr create --base "${BASE##*/}" --fill --label "rubygems: enhancement"
          }
        env:
          BASE: ${{ github.ref }}
          GH_TOKEN: ${{ github.token }}
