diff --git a/server/azure-pipelines.migrate.yaml b/server/azure-pipelines.migrate.yaml index d071851d7..c9444350a 100644 --- a/server/azure-pipelines.migrate.yaml +++ b/server/azure-pipelines.migrate.yaml @@ -17,21 +17,21 @@ steps: - checkout: none # TODO: Replace $(System.PullRequest.SourceRepositoryUri) with fork's URI. https://stackoverflow.com/q/60188806/2343739 - - displayName: checkout source branch - script: | + - script: | git clone $(System.PullRequest.SourceRepositoryUri) . git checkout $(System.PullRequest.SourceBranch) + displayName: checkout source branch # TODO: validate author of last commit was $(GITHUBNAME) - - displayName: abort if just migrated - name: abortIfJustMigrated - bash: | + - bash: | LASTMSG=$(git log -n 1 --pretty=format:"%s") echo "Last commit message: \"$LASTMSG\"" if [[ $LASTMSG == "migrate PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" ]] ; then echo "Just migrated. Exiting..." echo "##vso[task.setvariable variable=aborted;isOutput=true]true" fi + displayName: abort if just migrated + name: abortIfJustMigrated - task: UseDotNet@2 displayName: use latest dotnet sdk @@ -39,23 +39,21 @@ steps: version: 3.x condition: and(ne(variables['abortIfJustMigrated.aborted'], 'true'), succeeded()) - - displayName: install ef dotnet tool - script: dotnet tool install -g dotnet-ef + - script: dotnet tool install -g dotnet-ef + displayName: install ef dotnet tool condition: and(ne(variables['abortIfJustMigrated.aborted'], 'true'), succeeded()) - - displayName: git config + - bash: | + git config --global user.name "$GITHUBNAME" + git config --global user.email "$GITHUBEMAIL" + displayName: git config env: GITHUBNAME: $(GITHUBNAME) GITHUBEMAIL: $(GITHUBEMAIL) - bash: | - git config --global user.name "$GITHUBNAME" - git config --global user.email "$GITHUBEMAIL" condition: and(ne(variables['abortIfJustMigrated.aborted'], 'true'), succeeded()) # TODO: additionally grep on author of $(GITHUBNAME) when getting $REVERTHASH - - displayName: revert any existing migration for PR - workingDirectory: server/src - bash: | + - bash: | MIGLIST=$(dotnet ef migrations list -p FilterLists.Data.Migrations -s FilterLists.Api) echo "$MIGLIST" if [[ $MIGLIST == *$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER ]] ; then @@ -65,16 +63,18 @@ steps: else echo "No migration exists yet for PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER." fi + displayName: revert any existing migration for PR + workingDirectory: server/src condition: and(ne(variables['abortIfJustMigrated.aborted'], 'true'), succeeded()) # TODO: Merge latest data/* and server/src/FilterLists.Data.Migrations/* from origin/master. - - displayName: add migration + + - script: dotnet ef migrations add $(System.PullRequest.PullRequestNumber) -p FilterLists.Data.Migrations -s FilterLists.Api + displayName: add migration workingDirectory: server/src - script: dotnet ef migrations add $(System.PullRequest.PullRequestNumber) -p FilterLists.Data.Migrations -s FilterLists.Api condition: and(ne(variables['abortIfJustMigrated.aborted'], 'true'), succeeded()) - - displayName: commit or abandon migration - bash: | + - bash: | DIFF=$(git status -s | wc -l) echo "$DIFF file(s) changed" if (( $DIFF != 3 )) ; then @@ -83,13 +83,14 @@ steps: git add . git commit -m "migrate PR #$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" fi + displayName: commit or abandon migration condition: and(ne(variables['abortIfJustMigrated.aborted'], 'true'), succeeded()) - - displayName: git push - env: - GITHUBPAT: $(GITHUBPAT) - bash: | + - bash: | git config --global credential.helper store echo "https://$GITHUBPAT:x-oauth-basic@github.com" >> ~/.git-credentials git push origin "$SYSTEM_PULLREQUEST_SOURCEBRANCH" + displayName: git push + env: + GITHUBPAT: $(GITHUBPAT) condition: and(ne(variables['abortIfJustMigrated.aborted'], 'true'), succeeded())