# yaml-language-server: $schema=https://aka.ms/teams-toolkit/1.1.0/yaml.schema.json
# Visit https://aka.ms/teamsfx-v5.0-guide for details on this file
# Visit https://aka.ms/teamsfx-actions for details on actions
version: 1.1.0

projectId: {{projectId}}

environmentFolderPath: ./ {{~environmentFolder}}

provision:
{{#if activePlugins.fx-resource-aad-app-for-teams}}
  - uses: aadApp/create # Creates a new Microsoft Entra app to authenticate users if the environment variable that stores clientId is empty
    with:
      name: {{aadAppName}} # Note: when you run aadApp/update, the Microsoft Entra app name will be updated based on the definition in manifest. If you don't want to change the name, make sure the name in Microsoft Entra manifest is the same with the name defined here.
      generateClientSecret: true # If the value is false, the action will not generate client secret for you
      signInAudience: "AzureADMyOrg" # Authenticate users with a Microsoft work or school account in your organization's Microsoft Entra tenant (for example, single tenant).
    writeToEnvironmentFile: # Write the information of created resources into environment file for the specified environment variable(s).
      clientId: AAD_APP_CLIENT_ID
      clientSecret: SECRET_AAD_APP_CLIENT_SECRET # Environment variable that starts with `SECRET_` will be stored to the .env.{envName}.user environment file
      objectId: AAD_APP_OBJECT_ID
      tenantId: AAD_APP_TENANT_ID
      authority: AAD_APP_OAUTH_AUTHORITY
      authorityHost: AAD_APP_OAUTH_AUTHORITY_HOST
{{/if}}
  - uses: teamsApp/create # Creates a Teams app
    with:
      name: {{teamsAppName}} # Teams app name
    writeToEnvironmentFile:
      # Write the information of created resources into environment file for the specified environment variable(s).
      teamsAppId: TEAMS_APP_ID
{{#if activePlugins.fx-resource-bot}}
  - uses: botAadApp/create # Creates a new Microsoft Entra app for Bot Registration.
    with:
      name: {{appName}}bt$\{{RESOURCE_SUFFIX}}
    writeToEnvironmentFile:
      botId: BOT_ID
      botPassword: SECRET_BOT_PASSWORD
{{/if}}
  - uses: arm/deploy # Deploy given ARM templates parallelly.
    with:
      subscriptionId: $\{{AZURE_SUBSCRIPTION_ID}} # The AZURE_SUBSCRIPTION_ID is a built-in environment variable. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment varialbe here, but TeamsFx will not ask you to select subscription if it's empty in this case.
      resourceGroupName: $\{{AZURE_RESOURCE_GROUP_NAME}} # The AZURE_RESOURCE_GROUP_NAME is a built-in environment variable. TeamsFx will ask you to select or create one resource group if its value is empty. You're free to reference other environment varialbe here, but TeamsFx will not ask you to select or create resource grouop if it's empty in this case.
      templates:
       - path: ./Templates/azure/main.bicep # Relative path to this file
         parameters: ./Templates/azure/azure.parameters.$\{{TEAMSFX_ENV}}.json # Relative path to this file. Placeholders will be replaced with corresponding environment variable before ARM deployment.
         deploymentName: teams_toolkit_deployment # Required when deploy ARM template
      bicepCliVersion: v0.4.613 # Microsoft 365 Agents Toolkit will download this Bicep CLI version from GitHub. If you remove this config, it will use the Bicep CLI in your system's PATH.
{{#if activePlugins.fx-resource-frontend-hosting}}
  - uses: script # Add additional item to .env file
    with:
      run: echo "::set-teamsfx-env {{placeholderMappings.[state.fx-resource-frontend-hosting.indexPath]}}=/" # Used in appPackage/manifest.json file.
{{/if}}
{{#if activePlugins.fx-resource-aad-app-for-teams}}
  - uses: aadApp/update # Apply the Microsoft Entra manifest to an existing Microsoft Entra app. Will use the object id in manifest file to determine which Microsoft Entra app to update.
    with:
      manifestPath: ./aad.manifest.json # Relative path to this file. Environment variables in manifest will be replaced before apply to Microsoft Entra app
      outputFilePath : ./build/aad.manifest.$\{{TEAMSFX_ENV}}.json
{{/if}}
  - uses: teamsApp/validateManifest # Validate using manifest schema
    with:
      manifestPath: ./appPackage/manifest.json # Path to manifest template
  - uses: teamsApp/zipAppPackage # Build Teams app package with latest env value
    with:
      manifestPath: ./appPackage/manifest.json # Path to manifest template
      outputZipPath: ./build/appPackage/appPackage.$\{{TEAMSFX_ENV}}.zip
      outputJsonPath: ./build/appPackage/manifest.$\{{TEAMSFX_ENV}}.json
  - uses: teamsApp/update # Apply the Teams app manifest to an existing Teams app in Teams Developer Portal. Will use the app id in manifest file to determine which Teams app to update.
    with:
      appPackagePath: ./build/appPackage/appPackage.$\{{TEAMSFX_ENV}}.zip # Relative path to this file. This is the path for built zip file.

deploy:
  - uses: cli/runDotnetCommand
    with:
      args: publish --configuration Release --runtime win-x86 --self-contained
{{#if activePlugins.fx-resource-bot}}
  {{#if isFunctionBot}}
  # Deploy your application to Azure Functions using the zip deploy feature.
  # For additional details, see at https://aka.ms/zip-deploy-to-azure-functions
  - uses: azureFunctions/zipDeploy
    with:
      # deploy base folder
      artifactFolder: bin/Release/net6.0/win-x86/publish
      # The resource id of the cloud resource to be deployed to. 
      # This key will be generated by arm/deploy action automatically. 
      # You can replace it with your existing Azure Resource id 
      # or add it to your environment variable file.
      resourceId: $\{{ {{~placeholderMappings.[state.fx-resource-bot.functionAppResourceId]~}} }}
  {{else}}
  # Deploy your application to Azure App Service using the zip deploy feature.
  # For additional details, refer to https://aka.ms/zip-deploy-to-app-services.
  - uses: azureAppService/zipDeploy
    with:
      # deploy base folder
      artifactFolder: bin/Release/net6.0/win-x86/publish
      # The resource id of the cloud resource to be deployed to. 
      # This key will be generated by arm/deploy action automatically. 
      # You can replace it with your existing Azure Resource id 
      # or add it to your environment variable file.
      resourceId: $\{{ {{~placeholderMappings.[state.fx-resource-bot.resourceId]~}} }}
  {{/if}}
{{else if activePlugins.fx-resource-frontend-hosting}}
  # Deploy your application to Azure App Service using the zip deploy feature.
  # For additional details, refer to https://aka.ms/zip-deploy-to-app-services.
  - uses: azureAppService/zipDeploy
    with:
      # deploy base folder
      artifactFolder: bin/Release/net6.0/win-x86/publish
      # The resource id of the cloud resource to be deployed to. 
      # This key will be generated by arm/deploy action automatically. 
      # You can replace it with your existing Azure Resource id 
      # or add it to your environment variable file.
      resourceId: $\{{ {{~placeholderMappings.[state.fx-resource-frontend-hosting.resourceId]~}} }}
{{/if}}