azure-pipelines.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. # Gradle
  2. # Build your Java project and run tests with Gradle using a Gradle wrapper script.
  3. # Add steps that analyze code, save build artifacts, deploy, and more:
  4. # https://docs.microsoft.com/azure/devops/pipelines/languages/java
  5. pool:
  6. vmImage: 'Ubuntu-latest'
  7. variables:
  8. artifactName: 'Release'
  9. GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
  10. SKIP_BUILD: $[contains(variables['Build.SourceBranch'], 'refs/heads/no-build/')]
  11. ${{ if not(contains(variables['Build.SourceBranch'], 'refs/heads/no-build/')) }}:
  12. revision: $[counter('release-number', 0)]
  13. steps:
  14. - task: Cache@2
  15. inputs:
  16. key: 'gradle | "$(Agent.OS)" | build.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
  17. restoreKeys: gradle
  18. path: $(GRADLE_USER_HOME)
  19. displayName: Gradle build cache
  20. condition: eq(variables.SKIP_BUILD, 'false')
  21. - powershell: |
  22. (Get-Content ./gradle.properties).Split([Environment]::NewLine) | % {
  23. $kvp = $_.Split('=')
  24. if ($kvp.Count -gt 1) {
  25. $key = $kvp[0] -replace "\.", "_";
  26. $value = $kvp[1];
  27. Write-Host "##vso[task.setvariable variable=javaprops_$key]$value"
  28. }
  29. }
  30. displayName: Create Azure DevOps variables from gradle properties file
  31. condition: eq(variables.SKIP_BUILD, 'false')
  32. - task: Gradle@2
  33. displayName: Create Release Build
  34. inputs:
  35. workingDirectory: ''
  36. options: '--build-cache --max-workers=1 -PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  37. gradleWrapperFile: 'gradlew'
  38. gradleOptions: '-Xmx3072m'
  39. javaHomeOption: 'JDKVersion'
  40. jdkVersionOption: '1.8'
  41. jdkArchitectureOption: 'x64'
  42. publishJUnitResults: false
  43. testResultsFiles: '**/TEST-*.xml'
  44. tasks: 'build'
  45. condition: eq(variables.SKIP_BUILD, 'false')
  46. - task: CopyFiles@2
  47. displayName: Copy Release build to artifact staging
  48. inputs:
  49. sourceFolder: './build/libs/'
  50. contents: 'twilightforest-*-universal.jar'
  51. targetFolder: $(build.artifactStagingDirectory)
  52. condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  53. - task: PublishPipelineArtifact@1
  54. displayName: 'Publish Artifacts'
  55. condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  56. inputs:
  57. targetPath: '$(Build.ArtifactStagingDirectory)'
  58. artifact: '$(artifactName)'
  59. publishLocation: 'pipeline'
  60. - powershell: |
  61. $rawpath = "pipelineartifact://teamtwilight/projectId/1ef09d39-06cf-41fa-ad98-7258b70c2a72/buildId/$($Env:BUILD_BUILDID)/artifactName/Release"
  62. $path = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($rawpath))
  63. $jar = "twilightforest-$($env:JAVAPROPS_MINECRAFT_SUB_VERSION)-$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)-universal.jar"
  64. $downloadUrl = "https://artprodcus3.artifacts.visualstudio.com/Abaabfa6c-deea-4587-ba05-c308c2597b7a/1ef09d39-06cf-41fa-ad98-7258b70c2a72/_apis/artifact/$($path)0/content?format=file&subPath=%2F$($jar)"
  65. $jobResult = (Get-Culture).TextInfo.ToTitleCase(${env:agent.jobstatus})
  66. $Colour = 65280
  67. if ($jobResult -ne "Succeeded") {
  68. $Colour = 16711680
  69. }
  70. Write-Host "##vso[task.setvariable variable=DiscordMessageColour]$Colour"
  71. $json = [Ordered]@{
  72. title = "Build $jobResult"
  73. url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)Twilight%20Forest/_build/results?buildId=$($Env:BUILD_BUILDID)&view=results"
  74. color = $Colour
  75. fields = (
  76. [Ordered]@{
  77. name = "Author"
  78. value = "$($env:BUILD_SOURCEVERSIONAUTHOR)"
  79. },
  80. [Ordered]@{
  81. name = "Minecraft Version"
  82. value = "$($env:JAVAPROPS_MINECRAFT_SUB_VERSION)"
  83. },
  84. [Ordered]@{
  85. name = "Mod Version"
  86. value = "$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)"
  87. },
  88. [Ordered]@{
  89. name = "Forge Version"
  90. value = "$($env:JAVAPROPS_FORGE_VERSION)"
  91. },
  92. [Ordered]@{
  93. name = "Commit"
  94. value = "[$(($env:BUILD_SOURCEVERSION).Substring(0, 7))]($($env:BUILD_REPOSITORY_URI)/commit/$($env:BUILD_SOURCEVERSION))"
  95. }
  96. )
  97. }
  98. if ($jobResult -eq "Succeeded") {
  99. $json["fields"] += [Ordered]@{
  100. name = "Download"
  101. value = "[$($downloadUrl.Split("subPath=%2F")[1])]($downloadUrl)"
  102. }
  103. }
  104. Write-Host "##vso[task.setvariable variable=DiscordMessage]$($json | ConvertTo-Json -Compress)"
  105. displayName: Format discord message
  106. condition: eq(variables.SKIP_BUILD, 'false')
  107. env:
  108. SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  109. - task: ado-discord-webhook@1
  110. displayName: Announce Build to discord
  111. inputs:
  112. channelId: '$(DiscordChannelID)'
  113. webhookKey: '$(DiscordChannelSecret)'
  114. messageType: 'embeds'
  115. embeds: |
  116. [$(DiscordMessage)]
  117. condition: and(eq(variables.SKIP_BUILD, 'false'), eq(variables['CreateArtifacts'], 'True'))
  118. - task: Gradle@2
  119. displayName: Publish to Maven
  120. inputs:
  121. workingDirectory: ''
  122. options: '-PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  123. gradleWrapperFile: 'gradlew'
  124. gradleOptions: '-Xmx3072m'
  125. javaHomeOption: 'JDKVersion'
  126. jdkVersionOption: '1.8'
  127. jdkArchitectureOption: 'x64'
  128. publishJUnitResults: false
  129. testResultsFiles: '**/TEST-*.xml'
  130. tasks: 'publish'
  131. condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  132. env:
  133. ARTIFACTORY_USER: $(Artifactory.User)
  134. ARTIFACTORY_PASS: $(Artifactory.Password)
  135. - script: |
  136. # stop the Gradle daemon to ensure no files are left open (impacting the save cache operation later)
  137. ./gradlew --stop
  138. displayName: Kill Daemon
  139. condition: eq(variables.SKIP_BUILD, 'false')