{{=<% %>=}}
# This is just an example workflow for provision.
# You should customize it to meet your own requirements.
trigger: none
# Manually trigger this workflow, and you should pick the right branch.

pool:
  vmImage: ubuntu-latest

steps:
# Setup environment.
- task: NodeTool@0
  inputs:
    versionSpec: '14.17.0'
    checkLatest: true

# Check out
- checkout: self
  persistCredentials: true

- task: Bash@3
  env:
    M365_ACCOUNT_NAME: $(M365_ACCOUNT_NAME)
    M365_ACCOUNT_PASSWORD: $(M365_ACCOUNT_PASSWORD)
    M365_TENANT_ID: $(M365_TENANT_ID)
    CI_ENABLED: 'true'
    TEAMSFX_ENV_NAME: <%env_name%>
    # To specify the version of TTK CLI for use.
    TEAMSFX_CLI_VERSION: 1.*
  inputs:
    targetType: 'inline'
    script: |
      set -evuxo pipefail
      
      # Install the TTK CLI for later use.
      npm install @microsoft/teamsfx-cli@${TEAMSFX_CLI_VERSION}
  <%#hosting_type_contains_azure%>
  
      # Login Azure by service principal
      npx teamsfx account login azure --service-principal --username $(AZURE_SERVICE_PRINCIPAL_NAME) --password $(AZURE_SERVICE_PRINCIPAL_PASSWORD) --tenant $(AZURE_TENANT_ID)
  <%/hosting_type_contains_azure%>

      # We suggest to do the `teamsfx provision` step manually or in a separate workflow. The following steps are for your reference.
      # After provisioning, you should commit necessary files under .fx into the repository. 
      npx teamsfx provision<%#hosting_type_contains_azure%> --subscription $(AZURE_SUBSCRIPTION_ID)<%/hosting_type_contains_azure%> --env ${TEAMSFX_ENV_NAME}<%#cloud_resources_contains_sql%> --sql-admin-name $(SQL_ADMIN_NAME) --sql-password $(SQL_PASSWORD)<%/cloud_resources_contains_sql%>

      # Commit provision configs if necessary.
      # To enable scripts to run git commands, check https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml
      git config user.name "azdo-agent"
      git config user.email "azdo-agent@azure.com"
      git add .
      git commit -m "chore: commit provision configs"
      git push origin HEAD:${BUILD_SOURCEBRANCHNAME}