# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Block merges for EOL

on: pull_request

permissions:
  contents: read

concurrency:
  group: block-merge-eol-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  block-merges-eol:
    name: Block merges for EOL branches

    # Only run on stableXX branches
    if: startsWith( github.base_ref, 'stable')
    runs-on: ubuntu-latest

    steps:
      - name: Download updater config
        run: curl https://raw.githubusercontent.com/nextcloud/updater_server/production/config/config.php --output config.php

      - name: Set server major version environment
        run: |
          # retrieve version number from branch reference
          server_major=$(echo "${{ github.base_ref }}" | sed -En 's/stable//p')
          echo "server_major=$server_major" >> $GITHUB_ENV

      - name: Checking if ${{ env.server_major }} is EOL
        run: |
          php -r 'echo json_encode(require_once "config.php");' | jq --arg version "${{ env.server_major }}" '.stable[$version]["100"].eol // .beta[$version]["100"].eol' | grep --silent -i 'false'
