trigger:
  branches:
    include:
    - main
  tags:
    include:
    - stage-*

jobs:
- job: initialize
  displayName: Initialize
  pool:
    vmImage: ubuntu-latest
  steps:
  - checkout: self
    clean: true
    fetchDepth: 1
    persistCredentials: true
  - script: |
      git fetch origin main:main
      if git merge-base --is-ancestor $(Build.SourceVersion) main; then
        echo "This commit is in the main branch."
      else
        echo "This commit is not in the main branch."
        exit 1
      fi
    displayName: 'タグが付けられたCommitがmainブランチに存在するか確認'
- job: backend_build
  dependsOn: initialize
  condition: succeeded('initialize')
  displayName: Dictation App Service Deploy
  pool:
    vmImage: ubuntu-latest
  steps:
  - checkout: self
    clean: true
    fetchDepth: 1
- job: frontend_build
  dependsOn: initialize
  condition: succeeded('initialize')
  displayName: Dictation Static App Service Deploy
  pool:
    vmImage: ubuntu-latest
  steps:
  - checkout: self
    clean: true
    fetchDepth: 1
- job: migration
  condition: succeeded('initialize')
  displayName: DB migration
  dependsOn:
  - initialize
  - backend_build
  - frontend_build
  pool:
    name: db-migrate-pipelines
  steps:
  - checkout: self
    clean: true
    fetchDepth: 1