# This configuration allows enables a job based on `posix.yml` to have two modes:
#
# 1. When `[azure parallel]` *is not* in the commit message, then this job will
#    run first. If this job succeeds, then all dependent jobs can run.
# 2. When `[azure parallel]` *is* in the commit message, then this job will
#    run with name `{{ parameters.name }}_Parallel` along with all other jobs.
#
# To enable this template, all dependent jobs should check if this job succeeded
# or skipped by using:
# dependsOn: in(dependencies[{{ parameters.name }}]['result'], 'Succeeded', 'Skipped')

parameters:
  name: ''
  vmImage: ''
  matrix: []
  dependsOn: []
  condition: ''
  commitMessage: ''

jobs:

# When [azure parallel] *is not* in the commit message, this job will run
# first.
- template: posix.yml
  parameters:
    name: ${{ parameters.name }}
    vmImage: ${{ parameters.vmImage }}
    matrix: ${{ parameters.matrix }}
    dependsOn: ${{ parameters.dependsOn }}
    condition: |
      and(
        ${{ parameters.condition }},
        not(contains(${{ parameters.commitMessage }}, '[azure parallel]'))
      )

# When [azure parallel] *is* in the commit message, this job and dependent
# jobs will run in parallel. Implementation-wise, the job above is skipped and
# this job, named ${{ parameters.name }}_Parallel, will run in parallel with
# the other jobs.
- template: posix.yml
  parameters:
    name: ${{ parameters.name }}_Parallel
    vmImage: ${{ parameters.vmImage }}
    matrix: ${{ parameters.matrix }}
    dependsOn: ${{ parameters.dependsOn }}
    condition: |
      and(
        ${{ parameters.condition }},
        contains(${{ parameters.commitMessage }}, '[azure parallel]')
      )
