name: Synchronize Project Config
on:
  push:
    branches-ignore:
      - "devel"
    paths:
      - "_config"
      - ".gitea/workflows/sync_config.yaml"

jobs:
  sync-prjconf:
    name: "Update prjconf in OBS"
    runs-on: tumbleweed
    steps:
      - name: Setup OSC
        run: |
          mkdir -p ~/.config/osc
          cat >~/.config/osc/oscrc <<'EOF'
          [general]
          apiurl = https://api.opensuse.org

          [https://api.opensuse.org]
          user=${{ vars.OBS_USERNAME }}
          pass=${{ secrets.OBS_PASSWORD }}
          EOF
    # Waiting on PR to get merged for support in upstream action/checkout action
      - uses: 'https://github.com/yangskyboxlabs/action-checkout@sha256'
        name: Checkout repository
        with:
          object-format: 'sha256'
      - run: |
          PROJECT="$(grep PROJECT .obs/common.py | sed 's/PROJECT = "\(.*\)"/\1/')"
          if [ "$(osc meta prjconf "${PROJECT}" | sha256sum)" != "$(cat _config | sha256sum)" ] ; then
            osc meta prjconf "${PROJECT}" -F _config
          fi
