Repository navigation
Expand file tree
/
Copy pathazure-pipelines.migrate.yaml
More file actions
185 lines (164 loc) · 6.95 KB
/
Copy pathazure-pipelines.migrate.yaml
File metadata and controls
185 lines (164 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# 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"