Skip to content

Commit

Permalink
[CI] Fix the API diff failing (#20601)
Browse files Browse the repository at this point in the history
The API diff command fials due to the fact that it creates the comment
file inside sources, by moving the file to the artifacts staging
directory we fix the problem and ensure that the comment is removed
after each build.

Ps: I also fixed all the indentation issues in the file that were
reported by yamllint.
  • Loading branch information
mandel-macaque committed May 15, 2024
1 parent 35bcda3 commit 9b64421
Showing 1 changed file with 86 additions and 86 deletions.
172 changes: 86 additions & 86 deletions tools/devops/automation/templates/build/api-diff-process-results.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
# Job that downloads the change detection artifact and:
# * Uploads the results to VSDrops
# * Publishes results (as a comment) to GitHub

# yamllint disable rule:line-length
parameters:

- name: isPR
type: boolean
- name: isPR
type: boolean

- name: repositoryAlias
type: string
default: self
- name: repositoryAlias
type: string
default: self

- name: commit
type: string
default: HEAD
- name: commit
type: string
default: HEAD

- name: uploadPrefix
type: string
default: '$(MaciosUploadPrefix)'
- name: uploadPrefix
type: string
default: '$(MaciosUploadPrefix)'

steps:

- template: ../common/checkout.yml
parameters:
isPR: ${{ parameters.isPR }}
repositoryAlias: ${{ parameters.repositoryAlias }}
commit: ${{ parameters.commit }}

- pwsh: $(System.DefaultWorkingDirectory)/xamarin-macios/tools/devops/automation/scripts/show_env.ps1
displayName: 'Show Environment'

- pwsh: |
if (Test-Path "$Env:SYSTEM_DEFAULTWORKINGDIRECTORY/Artifacts" -PathType Container) {
Remove-Item -Path "$Env:SYSTEM_DEFAULTWORKINGDIRECTORY/Artifacts" -Force -Recurse
}
displayName: "Remove artifacts"
condition: always()

# Download the change detection artifact
- task: DownloadPipelineArtifact@2
displayName: 'Download change detection artifacts'
inputs:
patterns: '${{ parameters.uploadPrefix }}change-detection/change-detection.zip'
allowFailedBuilds: true
path: $(System.DefaultWorkingDirectory)/Artifacts

# Unzip the change detection artifact
- task: ExtractFiles@1
displayName: 'Decompress change detection artifacts'
inputs:
archiveFilePatterns: '$(System.DefaultWorkingDirectory)/Artifacts/${{ parameters.uploadPrefix }}change-detection/change-detection.zip'
destinationFolder: '$(System.DefaultWorkingDirectory)/change-detection'

# Upload the change detection results to vsdrops
- task: ms-vscs-artifact.build-tasks.artifactDropTask-1.artifactDropTask@0
displayName: 'Publish change detection results to Artifact Services Drop'
continueOnError: true # don't let any failures here stop us
inputs:
dropServiceURI: 'https://devdiv.artifacts.visualstudio.com/DefaultCollection'
dropMetadataContainerName: '${{ parameters.uploadPrefix }}DropMetadata-ChangeDetection-$(System.JobAttempt)'
buildNumber: 'xamarin-macios/detected-changes/$(Build.BuildNumber)/$(Build.BuildId)-$(System.JobAttempt)'
sourcePath: '$(System.DefaultWorkingDirectory)/change-detection/results/'
detailedLog: true
usePat: true

# Process the github comment and publish it
- pwsh: |
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\xamarin-macios\tools\devops\automation\scripts\MaciosCI.psd1
$vsdropsChangeDetectionPrefix = "https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/$Env:BUILD_BUILDNUMBER/$Env:BUILD_BUILDID-$Env:SYSTEM_JOBATTEMPT/;/"
$rootDirectory = Join-Path "$Env:SYSTEM_DEFAULTWORKINGDIRECTORY" "change-detection" "results"
$inputContentsPath = Join-Path -Path $rootDirectory -ChildPath "gh-comment.md"
if (Test-Path $inputContentsPath -PathType leaf) {
$inputContents = Get-Content -Path $inputContentsPath -Raw
} else {
$inputContents = ":fire: Unable to find the contents for the comment: $inputContentsPath does not exist :fire"
}
try {
$converted = Convert-Markdown -RootDirectory $rootDirectory -InputContents $inputContents -VSDropsPrefix $vsdropsChangeDetectionPrefix
} catch {
$converted = $inputContents + "`n`nUnable to convert markdown: $_`n`n"
}
$githubComments = New-GitHubCommentsObjectFromUrl -Url "$(Build.Repository.Uri)" -Token $Env:GITHUB_TOKEN -Hash $Env:COMMENT_HASH
$result = $githubComments.NewCommentFromMessage("", "", $converted)
displayName: 'Publish GitHub comment for change detection'
timeoutInMinutes: 10
continueOnError: true # don't let any failures here stop us
condition: always() # We always want to post something on github
env:
GITHUB_TOKEN: $(GitHub.Token)
${{ if eq(parameters.repositoryAlias, 'self') }}:
COMMENT_HASH: $(GIT_HASH)
${{ else }}:
COMMENT_HASH: $(Build.SourceVersion)
- template: ../common/checkout.yml
parameters:
isPR: ${{ parameters.isPR }}
repositoryAlias: ${{ parameters.repositoryAlias }}
commit: ${{ parameters.commit }}

- pwsh: $(System.DefaultWorkingDirectory)/xamarin-macios/tools/devops/automation/scripts/show_env.ps1
displayName: 'Show Environment'

- pwsh: |
if (Test-Path "$Env:SYSTEM_DEFAULTWORKINGDIRECTORY/Artifacts" -PathType Container) {
Remove-Item -Path "$Env:SYSTEM_DEFAULTWORKINGDIRECTORY/Artifacts" -Force -Recurse
}
displayName: "Remove artifacts"
condition: always()
# Download the change detection artifact
- task: DownloadPipelineArtifact@2
displayName: 'Download change detection artifacts'
inputs:
patterns: '${{ parameters.uploadPrefix }}change-detection/change-detection.zip'
allowFailedBuilds: true
path: $(System.DefaultWorkingDirectory)/Artifacts

# Unzip the change detection artifact
- task: ExtractFiles@1
displayName: 'Decompress change detection artifacts'
inputs:
archiveFilePatterns: '$(System.DefaultWorkingDirectory)/Artifacts/${{ parameters.uploadPrefix }}change-detection/change-detection.zip'
destinationFolder: '$(System.DefaultWorkingDirectory)/change-detection'

# Upload the change detection results to vsdrops
- task: ms-vscs-artifact.build-tasks.artifactDropTask-1.artifactDropTask@0
displayName: 'Publish change detection results to Artifact Services Drop'
continueOnError: true # don't let any failures here stop us
inputs:
dropServiceURI: 'https://devdiv.artifacts.visualstudio.com/DefaultCollection'
dropMetadataContainerName: '${{ parameters.uploadPrefix }}DropMetadata-ChangeDetection-$(System.JobAttempt)'
buildNumber: 'xamarin-macios/detected-changes/$(Build.BuildNumber)/$(Build.BuildId)-$(System.JobAttempt)'
sourcePath: '$(System.DefaultWorkingDirectory)/change-detection/results/'
detailedLog: true
usePat: true

# Process the github comment and publish it
- pwsh: |
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\xamarin-macios\tools\devops\automation\scripts\MaciosCI.psd1
$vsdropsChangeDetectionPrefix = "https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/$Env:BUILD_BUILDNUMBER/$Env:BUILD_BUILDID-$Env:SYSTEM_JOBATTEMPT/;/"
$rootDirectory = Join-Path "$Env:BUILD_ARTIFACTSTAGINGDIRECTORY" "change-detection" "results"
$inputContentsPath = Join-Path -Path $rootDirectory -ChildPath "gh-comment.md"
if (Test-Path $inputContentsPath -PathType leaf) {
$inputContents = Get-Content -Path $inputContentsPath -Raw
} else {
$inputContents = ":fire: Unable to find the contents for the comment: $inputContentsPath does not exist :fire"
}
try {
$converted = Convert-Markdown -RootDirectory $rootDirectory -InputContents $inputContents -VSDropsPrefix $vsdropsChangeDetectionPrefix
} catch {
$converted = $inputContents + "`n`nUnable to convert markdown: $_`n`n"
}
$githubComments = New-GitHubCommentsObjectFromUrl -Url "$(Build.Repository.Uri)" -Token $Env:GITHUB_TOKEN -Hash $Env:COMMENT_HASH
$result = $githubComments.NewCommentFromMessage("", "", $converted)
displayName: 'Publish GitHub comment for change detection'
timeoutInMinutes: 10
continueOnError: true # don't let any failures here stop us
condition: always() # We always want to post something on github
env:
GITHUB_TOKEN: $(GitHub.Token)
${{ if eq(parameters.repositoryAlias, 'self') }}:
COMMENT_HASH: $(GIT_HASH)
${{ else }}:
COMMENT_HASH: $(Build.SourceVersion)

12 comments on commit 9b64421

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.