name: Publish website
on:
  workflow_dispatch:

permissions:
  # required to retrieve AWS credentials
  id-token: write
  contents: write
  packages: write
  pull-requests: read

# cancel currently running jobs if a new version of the branch is pushed
concurrency:
  group: push-website-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  SetEnv:
    environment: Testing
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # needed to get latest tag

      - name: Get version string
        id: version
        run: |
          echo version=$(git describe --tags --abbrev=0) | tee -a $GITHUB_OUTPUT

  # ----------------------------------------------------------------------------------------------------
  # --- Website Linting -----------------------------------------------------------------------------------
  # ----------------------------------------------------------------------------------------------------

  Website-Linting:
    needs: [SetEnv]
    environment: Testing
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Lint Website
        uses: ./.github/actions/website-linting
        with:
          version: ${{ needs.SetEnv.outputs.version }}

  Publish-Website:
    needs: [Website-Linting]
    environment: Production
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: website

    steps:
      - uses: actions/checkout@v4 # need to checkout to make the action available

      - name: Publish website
        uses: ./.github/actions/publish-website
        with:
          aws-iam-role: ${{ secrets.AWS_IAM_ROLE }}
          bucket: "corsobackup.io"
          cfid: "E1W9NGI9YTVZ1A"