Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# Adds an Entity Framework Core migration to a pull request that changes data in data/*.json
trigger: none
pr:
autoCancel: true
branches:
include: [main]
paths:
include: [services/Directory/data/*]
pool:
vmImage: ubuntu-latest
variables:
DOTNET_CLI_TELEMETRY_OPTOUT: true
steps:
- checkout: none
- task: Bash@3
displayName: checkout source branch
inputs:
targetType: inline
script: |
FORKURI=$(curl -X GET "https://api.github.com/repos/$BUILD_REPOSITORY_NAME/pulls/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" | jq -r '.head.repo.clone_url')
git clone --single-branch -b "$SYSTEM_PULLREQUEST_SOURCEBRANCH" "$FORKURI" .
- task: Bash@3
displayName: abort if just migrated
name: abortJustMigrated
env:
GITHUBNAME: $(GITHUBNAME)
inputs:
targetType: inline
script: |
LASTAUTHOR=$(git log -n 1 --pretty=format:"%an")
LASTMSG=$(git log -n 1 --pretty=format:"%s")
if [[ $LASTAUTHOR == "$GITHUBNAME" ]] && [[ $LASTMSG == "feat(data): migrate PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" ]] ; then
echo "Just migrated. Aborting..."
else
echo "##vso[task.setvariable variable=aborted;isOutput=true]false"
fi
- task: ShellScript@2
displayName: lint json
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
scriptPath: services/Directory/data/lint.sh
- task: Bash@3
displayName: git config
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
env:
GITHUBNAME: $(GITHUBNAME)
GITHUBEMAIL: $(GITHUBEMAIL)
inputs:
targetType: inline
script: |
git config --global user.name "$GITHUBNAME"
git config --global user.email "$GITHUBEMAIL"
- task: Bash@3
displayName: commit lint results
name: commitLint
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
targetType: inline
workingDirectory: services/Directory/data
script: |
DIFF=$(git status -s -- . | wc -l)
echo "$DIFF file(s) required linting"
if (( $DIFF > 0 )) ; then
git add .
git commit -m "refactor(data): lint PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
fi
- task: UseDotNet@2
displayName: use latest dotnet sdk
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
version: 6.x
- task: CmdLine@2
displayName: install ef dotnet tool
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
script: dotnet tool install -g dotnet-ef
- task: Bash@3
displayName: revert existing PR migration
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
targetType: inline
workingDirectory: services/Directory
script: |
MIGLIST=$(dotnet ef migrations list -p FilterLists.Directory.Infrastructure.Migrations -s FilterLists.Directory.Api)
echo "$MIGLIST"
if [[ $MIGLIST == *$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER ]] ; then
echo "A migration already exists for PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER. Reverting..."
REVERTHASH=$(git log -n 1 --grep="feat(data): migrate PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" --pretty=format:"%H")
git revert --no-edit "$REVERTHASH"
fi
- task: Bash@3
displayName: sync with upstream
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
targetType: inline
script: |
git remote add upstream https://github.com/collinbarrett/FilterLists.git
git fetch upstream
git merge upstream/main
CONFLICTS=$(git ls-files -u | wc -l)
if [ "$CONFLICTS" -gt 0 ] ; then
echo "Conflicts with upstream repository. Aborting..."
exit 1
fi
- task: CmdLine@2
displayName: add migration
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
workingDirectory: services/Directory
script: dotnet ef migrations add $(System.PullRequest.PullRequestNumber) -p FilterLists.Directory.Infrastructure.Migrations -s FilterLists.Directory.Api --context QueryDbContext
- task: Bash@3
displayName: commit or abandon no-op migration
name: commitOrAbandon
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
targetType: inline
workingDirectory: services/Directory/FilterLists.Directory.Infrastructure.Migrations
script: |
DIFF=$(git status -s -- . | wc -l)
echo "$DIFF file(s) changed"
if (( $DIFF != 3 )) ; then
echo "No-op migration. Effective EF migrations add/change 3 files (.Designer.cs, .cs, and *ModelSnapshot.cs). Abandoning..."
else
git add .
git commit -m "feat(data): migrate PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
echo "##vso[task.setvariable variable=committed;isOutput=true]true"
fi
- task: DockerCompose@0
displayName: build test-migrations
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
dockerComposeFile: ./docker-compose/docker-compose.directory.migrations.tests.yml
dockerComposeCommand: build directory-migrations-tests
env:
COMPOSE_DOCKER_CLI_BUILD: 1
- task: Docker@2
displayName: create volume directory-migrations-tests-results
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
command: volume
arguments: create directory-migrations-tests-results
env:
DOCKER_BUILDKIT: 1
- task: DockerCompose@0
displayName: up test-migrations db
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
dockerComposeFile: ./docker-compose/docker-compose.directory.migrations.tests.yml
dockerComposeCommand: up -d directory-db
env:
COMPOSE_DOCKER_CLI_BUILD: 1
- task: DockerCompose@0
displayName: run test-migrations
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
dockerComposeFile: ./docker-compose/docker-compose.directory.migrations.tests.yml
dockerComposeCommand: run directory-migrations-tests
env:
COMPOSE_DOCKER_CLI_BUILD: 1
- task: Docker@2
displayName: create container directory-migrations-tests-results
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeededOrFailed())
inputs:
command: container
arguments: create --name directory-migrations-tests-results -v directory-migrations-tests-results:/results hello-world
env:
DOCKER_BUILDKIT: 1
- task: Docker@2
displayName: copy out test-migrations results
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeededOrFailed())
inputs:
command: cp
arguments: directory-migrations-tests-results:/results $(System.DefaultWorkingDirectory)
env:
DOCKER_BUILDKIT: 1
- task: PublishTestResults@2
displayName: publish test results
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeededOrFailed())
inputs:
testResultsFormat: VSTest
testResultsFiles: "**/*.trx"
- task: Bash@3
displayName: push
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
env:
GITHUBPAT: $(GITHUBPAT)
inputs:
targetType: inline
script: |
git config --global credential.helper store
echo "https://$GITHUBPAT:x-oauth-basic@github.com" >> ~/.git-credentials
git push origin "$SYSTEM_PULLREQUEST_SOURCEBRANCH"