name: Secret Provider SetSecret Tests
on: [pull_request, workflow_dispatch]
permissions:
  contents: read
  issues: none
  pull-requests: none
concurrency:
  group: duplicati-ci-secretprovidertests
  cancel-in-progress: false
jobs:
  check_secrets:
    runs-on: ubuntu-latest
    outputs:
      aws_secrets_available: "${{ steps.check_aws.outputs.available }}"
      azure_secrets_available: "${{ steps.check_azure.outputs.available }}"
      gcs_secrets_available: "${{ steps.check_gcs.outputs.available }}"
      hcvault_secrets_available: "${{ steps.check_hcvault.outputs.available }}"
    steps:
      - id: check_aws
        name: Check AWS secrets
        shell: bash
        run: |
          echo "Starting AWS secrets check..."
          if [[ -n "${{ secrets.DUPLICATI_TEST_AWSSM_URL }}" ]]; then
            echo "AWS URL secret found"
            echo "available=true" >> $GITHUB_OUTPUT
          else
            echo "Missing AWS URL secret"
            echo "available=false" >> $GITHUB_OUTPUT
          fi
          echo "AWS check completed"
      - id: check_azure
        name: Check Azure secrets
        shell: bash
        run: |
          echo "Starting Azure secrets check..."
          if [[ -n "${{ secrets.DUPLICATI_TEST_AZKV_URL }}" ]]; then
            echo "Azure URL secret found"
            echo "available=true" >> $GITHUB_OUTPUT
          else
            echo "Missing Azure URL secret"
            echo "available=false" >> $GITHUB_OUTPUT
          fi
          echo "Azure check completed"
      - id: check_gcs
        name: Check GCS secrets
        shell: bash
        run: |
          echo "Starting GCS secrets check..."
          if [[ -n "${{ secrets.DUPLICATI_TEST_GCS_URL }}" ]]; then
            echo "GCS URL secret found"
            echo "available=true" >> $GITHUB_OUTPUT
          else
            echo "Missing GCS URL secret"
            echo "available=false" >> $GITHUB_OUTPUT
          fi
          echo "GCS check completed"
      - id: check_hcvault
        name: Check HashiCorp Vault secrets
        shell: bash
        run: |
          echo "Starting HashiCorp Vault secrets check..."
          if [[ -n "${{ secrets.DUPLICATI_TEST_HCV_URL }}" ]]; then
            echo "HashiCorp Vault URL secret found"
            echo "available=true" >> $GITHUB_OUTPUT
          else
            echo "Missing HashiCorp Vault URL secret"
            echo "available=false" >> $GITHUB_OUTPUT
          fi
          echo "HashiCorp Vault check completed"
      - name: Debug Output
        shell: bash
        run: |
          echo "AWS Available: ${{ steps.check_aws.outputs.available }}"
          echo "Azure Available: ${{ steps.check_azure.outputs.available }}"
          echo "GCS Available: ${{ steps.check_gcs.outputs.available }}"
          echo "HashiCorp Vault Available: ${{ steps.check_hcvault.outputs.available }}"

  test_fileprovider:
    name: File Provider SetSecret Tests
    runs-on: "${{ matrix.os }}"
    strategy:
      fail-fast: false
      max-parallel: 1
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
    steps:
      - name: Set up .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 10.x
      - name: Checkout source
        uses: actions/checkout@v4
      - name: Restore NuGet dependencies
        run: >-
          dotnet restore
          Duplicati.slnx
      - name: Build project
        run: >-
          dotnet build --no-restore
          Duplicati.slnx
      - name: Run FileProvider SetSecret tests
        run: |
          mkdir -p "$GITHUB_WORKSPACE/TestResults/secretprovider/fileprovider"
          dotnet test --no-build --filter="FullyQualifiedName~SecretProviderSetSecretTests.FileProvider_SetSecret_WritesToFile" --collect:"XPlat Code Coverage" --results-directory "$GITHUB_WORKSPACE/TestResults/secretprovider/fileprovider" --logger:"console;verbosity=detailed" Duplicati.slnx

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ github.workspace }}/TestResults/secretprovider/fileprovider/**/coverage.cobertura.xml
          flags: secretprovider-fileprovider,${{ matrix.os }}

  test_aws:
    needs: check_secrets
    if: needs.check_secrets.outputs.aws_secrets_available == 'true'
    name: AWS Secret Provider SetSecret Tests
    runs-on: "${{ matrix.os }}"
    strategy:
      max-parallel: 1
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
    steps:
      - name: Set up .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 10.x
      - name: Checkout source
        uses: actions/checkout@v4
      - name: Restore NuGet dependencies
        run: >-
          dotnet restore
          Duplicati.slnx
      - name: Build project
        run: >-
          dotnet build --no-restore
          Duplicati.slnx
      - name: Run AWS Secret Provider SetSecret tests
        env:
          DUPLICATI_TEST_AWSSM_URL: "${{ secrets.DUPLICATI_TEST_AWSSM_URL }}"
        run: |
          mkdir -p "$GITHUB_WORKSPACE/TestResults/secretprovider/aws"
          dotnet test --no-build --filter="FullyQualifiedName~SecretProviderSetSecretTests.AwsProvider_SetSecret_Works" --collect:"XPlat Code Coverage" --results-directory "$GITHUB_WORKSPACE/TestResults/secretprovider/aws" --logger:"console;verbosity=detailed" Duplicati.slnx

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ github.workspace }}/TestResults/secretprovider/aws/**/coverage.cobertura.xml
          flags: secretprovider-aws,${{ matrix.os }}

  test_azure:
    needs: check_secrets
    if: needs.check_secrets.outputs.azure_secrets_available == 'true'
    name: Azure Secret Provider SetSecret Tests
    runs-on: "${{ matrix.os }}"
    strategy:
      max-parallel: 1
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
    steps:
      - name: Set up .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 10.x
      - name: Checkout source
        uses: actions/checkout@v4
      - name: Restore NuGet dependencies
        run: >-
          dotnet restore
          Duplicati.slnx
      - name: Build project
        run: >-
          dotnet build --no-restore
          Duplicati.slnx
      - name: Run Azure Secret Provider SetSecret tests
        env:
          DUPLICATI_TEST_AZKV_URL: "${{ secrets.DUPLICATI_TEST_AZKV_URL }}"
        run: |
          mkdir -p "$GITHUB_WORKSPACE/TestResults/secretprovider/azure"
          dotnet test --no-build --filter="FullyQualifiedName~SecretProviderSetSecretTests.AzureProvider_SetSecret_Works" --collect:"XPlat Code Coverage" --results-directory "$GITHUB_WORKSPACE/TestResults/secretprovider/azure" --logger:"console;verbosity=detailed" Duplicati.slnx

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ github.workspace }}/TestResults/secretprovider/azure/**/coverage.cobertura.xml
          flags: secretprovider-azure,${{ matrix.os }}

  test_gcs:
    needs: check_secrets
    if: needs.check_secrets.outputs.gcs_secrets_available == 'true'
    name: GCS Secret Provider SetSecret Tests
    runs-on: "${{ matrix.os }}"
    strategy:
      max-parallel: 1
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
    steps:
      - name: Set up .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 10.x
      - name: Checkout source
        uses: actions/checkout@v4
      - name: Restore NuGet dependencies
        run: >-
          dotnet restore
          Duplicati.slnx
      - name: Build project
        run: >-
          dotnet build --no-restore
          Duplicati.slnx
      - name: Run GCS Secret Provider SetSecret tests
        env:
          DUPLICATI_TEST_GCS_URL: "${{ secrets.DUPLICATI_TEST_GCS_URL }}"
        run: |
          mkdir -p "$GITHUB_WORKSPACE/TestResults/secretprovider/gcs"
          dotnet test --no-build --filter="FullyQualifiedName~SecretProviderSetSecretTests.GcsProvider_SetSecret_Works" --collect:"XPlat Code Coverage" --results-directory "$GITHUB_WORKSPACE/TestResults/secretprovider/gcs" --logger:"console;verbosity=detailed" Duplicati.slnx

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ github.workspace }}/TestResults/secretprovider/gcs/**/coverage.cobertura.xml
          flags: secretprovider-gcs,${{ matrix.os }}

  test_hcvault:
    needs: check_secrets
    if: needs.check_secrets.outputs.hcvault_secrets_available == 'true'
    name: HashiCorp Vault Secret Provider SetSecret Tests
    runs-on: "${{ matrix.os }}"
    strategy:
      max-parallel: 1
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
    steps:
      - name: Set up .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 10.x
      - name: Checkout source
        uses: actions/checkout@v4
      - name: Restore NuGet dependencies
        run: >-
          dotnet restore
          Duplicati.slnx
      - name: Build project
        run: >-
          dotnet build --no-restore
          Duplicati.slnx
      - name: Run HashiCorp Vault Secret Provider SetSecret tests
        env:
          DUPLICATI_TEST_HCV_URL: "${{ secrets.DUPLICATI_TEST_HCV_URL }}"
        run: |
          mkdir -p "$GITHUB_WORKSPACE/TestResults/secretprovider/hcvault"
          dotnet test --no-build --filter="FullyQualifiedName~SecretProviderSetSecretTests.HcVaultProvider_SetSecret_Works" --collect:"XPlat Code Coverage" --results-directory "$GITHUB_WORKSPACE/TestResults/secretprovider/hcvault" --logger:"console;verbosity=detailed" Duplicati.slnx

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ github.workspace }}/TestResults/secretprovider/hcvault/**/coverage.cobertura.xml
          flags: secretprovider-hcvault,${{ matrix.os }}

  test_hcvault_testcontainers:
    name: HashiCorp Vault Secret Provider SetSecret Tests (Testcontainers)
    runs-on: ubuntu-latest
    steps:
      - name: Set up .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 10.x
      - name: Checkout source
        uses: actions/checkout@v4
      - name: Restore NuGet dependencies
        run: >-
          dotnet restore
          Duplicati.slnx
      - name: Build project
        run: >-
          dotnet build --no-restore
          Duplicati.slnx
      - name: Run HashiCorp Vault Secret Provider SetSecret tests with Testcontainers
        run: |
          mkdir -p "$GITHUB_WORKSPACE/TestResults/secretprovider/hcvault-testcontainers"
          dotnet test --no-build --filter="FullyQualifiedName~SecretProviderSetSecretTests.HcVaultProvider_SetSecret_Works_WithTestcontainers" --collect:"XPlat Code Coverage" --results-directory "$GITHUB_WORKSPACE/TestResults/secretprovider/hcvault-testcontainers" --logger:"console;verbosity=detailed" Duplicati.slnx

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ${{ github.workspace }}/TestResults/secretprovider/hcvault-testcontainers/**/coverage.cobertura.xml
          flags: secretprovider-hcvault-testcontainers,ubuntu-latest
