Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
185 lines (164 sloc) 6.95 KB
# Adds an Entity Framework Core migration to a pull request that changes data in data/*.json
# TODO: sort/lint JSON
# TODO: if data/* or server/src/FilterLists.Data.Migrations/* change in origin/master, re-trigger this Pipeline
trigger: none
pr:
autoCancel: true
branches:
include: [master]
paths:
include: [data/*, server/src/FilterLists.Data.Migrations/Migrations/*]
pool:
vmImage: ubuntu-latest
steps:
- checkout: none
# TODO: switch to using Azure Pipelines Repository Resource to use GitHub service connection rather than PAT
- 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 == "migrate PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" ]] ; then
echo "Just migrated. Aborting..."
else
echo "##vso[task.setvariable variable=aborted;isOutput=true]false"
fi
- task: UseDotNet@2
displayName: use latest dotnet sdk
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
version: 3.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: 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: revert existing PR migration
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
env:
GITHUBNAME: $(GITHUBNAME)
inputs:
targetType: inline
workingDirectory: server/src
script: |
MIGLIST=$(dotnet ef migrations list -p FilterLists.Data.Migrations -s FilterLists.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 --author="$GITHUBNAME" --grep="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/master
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: server/src
script: dotnet ef migrations add $(System.PullRequest.PullRequestNumber) -p FilterLists.Data.Migrations -s FilterLists.Api
- task: Bash@3
displayName: commit or abandon no-op migration
name: commitOrAbandon
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), succeeded())
inputs:
targetType: inline
workingDirectory: server/src/FilterLists.Data.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 "migrate PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
echo "##vso[task.setvariable variable=committed;isOutput=true]true"
fi
- task: DockerCompose@0
displayName: build test-data
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
dockerComposeFile: docker-compose.data.tests.yml
dockerComposeCommand: build api
- task: Docker@2
displayName: create volume test-data-results
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
command: volume
arguments: create test-data-results
- task: DockerCompose@0
displayName: up test-data db
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
dockerComposeFile: docker-compose.data.tests.yml
dockerComposeCommand: up -d mariadb
- task: DockerCompose@0
displayName: run test-data
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeeded())
inputs:
dockerComposeFile: docker-compose.data.tests.yml
dockerComposeCommand: run api
- task: Docker@2
displayName: create container test-data-results
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeededOrFailed())
inputs:
command: container
arguments: create --name test-data-results -v test-data-results:/results hello-world
- task: Docker@2
displayName: copy out test-data results
condition: and(eq(variables['abortJustMigrated.aborted'], 'false'), eq(variables['commitOrAbandon.committed'], 'true'), succeededOrFailed())
inputs:
command: cp
arguments: test-data-results:/results $(System.DefaultWorkingDirectory)
- 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"
You can’t perform that action at this time.