name: Build (Reusable)

permissions:
  contents: read

on:
  workflow_call:
    inputs:
      configuration:
        required: true
        type: string
      architecture:
        required: true
        type: string

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    env:
      LANG: en_US.UTF-8

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Set Describe
        run: |
          describe=`git describe --tags --always`
          echo "describe=$describe" >> $GITHUB_ENV

      - name: Setup .NET SDK
        uses: actions/setup-dotnet@v5
        with:
          dotnet-version: 10.0.x

      - name: Build Project
        env:
          PCL_WRITE_SECRET: '1'
          PCL_MS_CLIENT_ID: ${{ secrets.CLIENT_ID }}
          PCL_CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
          PCL_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
          PCL_NAID_CLIENT_ID: ${{ secrets.NAID_CLIENT_ID }}
          PCL_NAID_CLIENT_SECRET: ${{ secrets.NAID_CLIENT_SECRET }}
          PCL_LINK_SERVER_ROOT: ${{ secrets.LINK_SERVER_ROOTS }}
          PCL_LOBBY_DEFAULT_SECRET: ${{ secrets.LOBBY_DEFAULT_SECRET }}
          PCL_GITHUB_SHA: ${{ github.sha }}
        run: |
          dotnet publish "Plain Craft Launcher 2/Plain Craft Launcher 2.csproj" \
          -p:Configuration=${{ inputs.configuration }} -p:Platform=${{ inputs.architecture }} \
          -p:DeleteExistingFiles=true -o ./artifact --no-self-contained

      - name: Upload the Build Artifact
        uses: actions/upload-artifact@v7
        with:
          name: PCL2_CE_${{ inputs.configuration }}_${{ inputs.architecture }}
          path: artifact/**
