# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
  - "*"

pool:
  vmImage: ubuntu-latest

# Pipeline
steps:
  - checkout: none
  - script: |

      # Install urlencode function to encode reserved characters in passwords
      sudo apt-get install gridsite-clients

      # Create local mirror of Azure DevOps repository
      git clone --mirror https://${AZURE_GIT_USERNAME}:$(urlencode ${AZURE_GIT_PASSWORD})@${AZURE_REPO_URL} repo-mirror

      # Sync AWS CodeCommit repository
      cd repo-mirror
      git push --mirror https://${AWS_GIT_USERNAME}:$(urlencode ${AWS_GIT_PASSWORD})@${AWS_REPO_URL}

    displayName: "Sync repository with AWS CodeCommit"
    env:
      AZURE_REPO_URL: $(AZURE_REPO_URL)
      AZURE_GIT_USERNAME: $(AZURE_GIT_USERNAME)
      AZURE_GIT_PASSWORD: $(AZURE_GIT_PASSWORD)
      AWS_REPO_URL: $(AWS_REPO_URL)
      AWS_GIT_USERNAME: $(AWS_GIT_USERNAME)
      AWS_GIT_PASSWORD: $(AWS_GIT_PASSWORD)
