Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update solution changes detected method in PR/pipelines #99

Open
Dave-Robertson92 opened this issue Jan 16, 2023 · 2 comments
Open

Update solution changes detected method in PR/pipelines #99

Dave-Robertson92 opened this issue Jan 16, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@Dave-Robertson92
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Looking at the powershell script File here for how we detect which solutions have changed to manage incrementing the solution/s versioning.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

the current method uses "$resultArray = git show --name-only" , git show generally looks at commit/s in our use.
A Pull request can have multiple commits which I understand can limit your merge options to "squash merge"
if run post Pull request (build), solution/s version will not be tracked in the repo.

Describe the solution you'd like

A separate "Build" as part of the PR policy to manage solution versioning (reason below) .

Note, in the event, two active PRs with the same solution/s there is a chance of them both incrementing to the same version number without being detected, this will prevent the last one to merge into master/main from being deployed succesfully as they could have the same version number. to prevent this, the pull request build policy should be set to "Build expiration" "Immediately when master is updated" so that for the last one to merge into master/main versioning build will be re-ran and incremented

Replace "$resultArray = git show --name-only" with the below, which will instead highlight changes between the pull request source branch and the target branch

$targetbranch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH.replace('refs/heads/', '')
$resultArray = git diff --name-only origin/$targetbranch

add to update solution version number in extracted solutions Solution.xml (source branch) (making sure it does not loop, for example when updated on source branch, it does not re-trigger and increment)

@Dave-Robertson92 Dave-Robertson92 added the enhancement New feature or request label Jan 16, 2023
@Dave-Robertson92
Copy link
Contributor Author

@tdashworth been working on versioning for my own use/implementation of this and have a suggestion on a improvement for solution change detection (in GIT).

What do you think about the solution approach?

cc @ewingjm

@Dave-Robertson92
Copy link
Contributor Author

Dave-Robertson92 commented Jan 18, 2023

managed to get a solution working, some further tweaks to make (naming & simplicity):

Azure DevOps Config:
Pull request build policy on the default branch
image

  • run's anytime the source branch is updated
  • expires if the default branch is updated before complete (merged in) say the version number is incremented outside of the PR request on the default branch

(the PowerShell step/ for updating version number will be need removing from the Post PR build for further deployment if used)

Yaml update(add of env:systemtoken for Pushing) :

steps:
        - task: PowerShell@2
          displayName: 'Add build tag for each updated solution'
          inputs:
            targetType: 'filePath'
            errorActionPreference: 'stop'
            filePath: 'pipelines/scripts/Add-BuildTagForEachUpdatedSolution.ps1'
          env:
           SYSTEM_ACCESSTOKEN: $(System.AccessToken)

Script:

$targetbranch =  $env:SYSTEM_PULLREQUEST_TARGETBRANCH.replace('refs/heads/', '')
$resultArray = git diff --name-only  origin/$targetbranch 

[System.Collections.ArrayList]$changedSolutions = @()
$commit = 0

foreach ($_ in $resultArray) {
  if ($_.StartsWith("src/solutions")) {
    $solutionName = $_.Split("/")[2]

    if (!$changedSolutions.Contains($solutionName)) {
      $changedSolutions.Add($solutionName)
      Write-Host "##vso[build.addbuildtag]$solutionName" 
      $solutionxmlPath = 'src/solutions/' + $solutionName + '/Extract/Other/Solution.xml'
      $s = 'origin/' + $targetbranch + ':' + $solutionxmlPath
      [xml]$solutionxmltarget = git show $s
      [xml]$solutionxmlsource = Get-Content -Path  $solutionxmlPath
      $sourceVersion = [version]$solutionxmlsource.ImportExportXml.SolutionManifest.Version
      $tagetVersion = [version]$solutionxmltarget.ImportExportXml.SolutionManifest.Version
      if ($sourceVersion -le $tagetVersion)
      {
       $newVersion  =   [version]::New($tagetVersion.Major,$tagetVersion.Minor,$tagetVersion.Build,$tagetVersion.Revision+1)
       $solutionxmlsource.ImportExportXml.SolutionManifest.Version = [string]$newVersion
       $solutionxmlsource.Save($solutionxmlPath)
        $commit = 1
      }
    }
  }
}
$output = $changedSolutions -Join ','  
Write-Host "##vso[task.setvariable variable=solutionList]$output"
if ( $commit -eq 1 )
{
$un = git show -s --format="<%aN>" 
$ue = git show -s --format="<%aE>" 
git config --global user.email $ue
git config --global user.name $un
git checkout $env:SYSTEM_PULLREQUEST_SOURCEBRANCH.replace('refs/heads/', '')
git add .
git commit  --message "auto-version"
git config --global http.extraheader "AUTHORIZATION: bearer  $env:SYSTEM_ACCESSTOKEN"
git push  
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant