#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: deploy-site

on:
  push:
    branches:
      - "2.x"
      - "2.x-site-pro"
      - "release/2*"
    paths-ignore:
      - "**.md"
      - "**.txt"

permissions: read-all

jobs:

  deploy-site-stg:
    if: github.repository == 'apache/logging-log4j2' && github.ref_name == '2.x'
    uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@gha/v0
    # Secrets for committing the generated site
    secrets:
      GPG_SECRET_KEY: ${{ secrets.LOGGING_GPG_SECRET_KEY }}
    # Write permissions for committing the generated site
    permissions:
      contents: write
    with:
      asf-yaml-content: |
        staging:
          profile: ~
          whoami: ${{ github.ref_name }}-site-stg-out
          subdir: content/log4j/2.x
      install-required: true
      target-branch: ${{ github.ref_name }}-site-stg-out

  deploy-site-pro:
    if: github.repository == 'apache/logging-log4j2' && github.ref_name == '2.x-site-pro'
    uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@gha/v0
    # Secrets for committing the generated site
    secrets:
      GPG_SECRET_KEY: ${{ secrets.LOGGING_GPG_SECRET_KEY }}
    # Write permissions for committing the generated site
    permissions:
      contents: write
    with:
      asf-yaml-content: |
        publish:
          whoami: ${{ github.ref_name }}-out
          subdir: content/log4j/2.x
      install-required: true
      target-branch: ${{ github.ref_name }}-out

  export-version:
    if: github.repository == 'apache/logging-log4j2' && startsWith(github.ref_name, 'release/')
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.export-version.outputs.version }}
    steps:
      - name: Export version
        id: export-version
        run: |
          version=$(echo "${{ github.ref_name }}" | sed 's/^release\///')
          echo "version=$version" >> "$GITHUB_OUTPUT"

  deploy-site-rel:
    needs: export-version
    uses: apache/logging-parent/.github/workflows/deploy-site-reusable.yaml@gha/v0
    # Secrets for committing the generated site
    secrets:
      GPG_SECRET_KEY: ${{ secrets.LOGGING_GPG_SECRET_KEY }}
    # Write permissions for committing the generated site
    permissions:
      contents: write
    with:
      asf-yaml-content: |
        staging:
          profile: ~
          whoami: ${{ github.ref_name }}-site-stg-out
          subdir: content/log4j/${{ needs.export-version.outputs.version }}
      install-required: true
      target-branch: ${{ github.ref_name }}-site-stg-out
