123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- # Gradle
- # Build your Java project and run tests with Gradle using a Gradle wrapper script.
- # Add steps that analyze code, save build artifacts, deploy, and more:
- # https://docs.microsoft.com/azure/devops/pipelines/languages/java
- pool:
- vmImage: 'ubuntu-20.04'
- container: eclipse-temurin:17.0.3_7-jdk
- variables:
- revision: $[counter('release-number', 0)]
- artifactName: 'Release'
- GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
- steps:
- - bash: |
- loc="/opt/java/openjdk"
- echo "##vso[task.setvariable variable=JAVA_HOME_17_X64]${loc}"
- echo "##vso[task.setvariable variable=JAVA_HOME]${loc}"
- echo "##vso[task.setvariable variable=PATH]${loc}/bin:$(PATH)"
- displayName: Set JAVA_HOME Variable
- - task: Cache@2
- inputs:
- key: 'gradle | "$(Agent.OS)" | build.gradle | gradle.properties | src/main/resources/twilightforest.accesswidener'
- restoreKeys: gradle
- path: $(GRADLE_USER_HOME)
- displayName: Gradle build cache
- - bash: |
- while IFS= read -r line; do
- IFS='='; kvp=(${line}); unset IFS;
- if [[ ${#kvp[@]} -gt 1 ]]
- then
- key=${kvp[0]//"."/"_"}
- val=${kvp[1]}
- echo "##vso[task.setvariable variable=javaprops_${key}]${val}"
- fi
- done < ./gradle.properties
- displayName: Create Azure DevOps variables from gradle properties file
- - task: Gradle@2
- displayName: Create Release Build
- inputs:
- workingDirectory: ''
- options: '--build-cache --max-workers=1 -PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
- gradleWrapperFile: 'gradlew'
- gradleOptions: '-Xmx3072m'
- javaHomeOption: 'JDKVersion'
- jdkVersionOption: '17'
- jdkArchitectureOption: 'x64'
- publishJUnitResults: false
- testResultsFiles: '**/TEST-*.xml'
- tasks: 'build'
- - task: CopyFiles@2
- displayName: Copy Release build to artifact staging
- inputs:
- sourceFolder: './build/libs/'
- contents: 'twilightforest-*.jar'
- targetFolder: $(build.artifactStagingDirectory)
- condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
- - task: PublishPipelineArtifact@1
- displayName: 'Publish Artifacts'
- condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
- inputs:
- targetPath: '$(Build.ArtifactStagingDirectory)'
- artifact: '$(artifactName)'
- publishLocation: 'pipeline'
- - bash: |
- rawpath="pipelineartifact://teamtwilight/projectId/1ef09d39-06cf-41fa-ad98-7258b70c2a72/buildId/${BUILD_BUILDID}/artifactName/Release"
- path=$(echo -ne ${rawpath} | base64)
- path=$(echo -ne ${path} | tr -d ' ')
- jar="twilightforest-fabric-${JAVAPROPS_MINECRAFT_VERSION}-${JAVAPROPS_MOD_VERSION}.${REVISION}.jar"
- 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}"
- jobResult=${AGENT_JOBSTATUS^}
- Colour=65280
- if [ "${jobResult}" != "Succeeded" ]
- then
- Colour=16711680
- fi
- echo "##vso[task.setvariable variable=DiscordMessageColour]${Colour}"
- json="{
- \"title\": \"Build ${jobResult}\",
- \"url\": \"${SYSTEM_TEAMFOUNDATIONSERVERURI}Twilight%20Forest/_build/results?buildId=${BUILD_BUILDID}&view=results\",
- \"color\": ${Colour},
- \"fields\": [
- {
- \"name\": \"Author\",
- \"value\": \"${BUILD_SOURCEVERSIONAUTHOR}\"
- },
- {
- \"name\": \"Minecraft Version\",
- \"value\": \"${JAVAPROPS_MINECRAFT_VERSION}\"
- },
- {
- \"name\": \"Mod Version\",
- \"value\": \"${JAVAPROPS_MOD_VERSION}.${REVISION}\"
- },
- {
- \"name\": \"Fabric API Version\",
- \"value\": \"${JAVAPROPS_FABRIC_VERSION}\"
- },
- {
- \"name\": \"Fabric Loader Version\",
- \"value\": \"${JAVAPROPS_LOADER_VERSION}\"
- },
- {
- \"name\": \"Commit\",
- \"value\": \"[${BUILD_SOURCEVERSION:0:6}]${BUILD_REPOSITORY_URI}/commit/${BUILD_SOURCEVERSION}\"
- }"
- if [ "${jobResult}" = "Succeeded" ]
- then
- json="${json},
- {
- \"name\": \"Download\",
- \"value\": \"${downloadUrl}\"
- }"
- fi
- json="${json}
- ]
- }"
- json=$(echo ${json} | tr -d '\n' | sed 's/ //g')
- echo "##vso[task.setvariable variable=DiscordMessage]${json}"
- displayName: Format discord message
- condition: always()
- env:
- SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- - task: ado-discord-webhook@1
- displayName: Announce Build to discord
- inputs:
- channelId: '$(DiscordChannelID)'
- webhookKey: '$(DiscordChannelSecret)'
- messageType: 'embeds'
- embeds: |
- [$(DiscordMessage)]
- condition: and(always(), eq(variables['CreateArtifacts'], 'True'))
- #- task: Gradle@2
- # displayName: Publish to Maven
- # inputs:
- # workingDirectory: ''
- # options: '-PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
- # gradleWrapperFile: 'gradlew'
- # gradleOptions: '-Xmx3072m'
- # javaHomeOption: 'JDKVersion'
- # jdkVersionOption: '16'
- # jdkArchitectureOption: 'x64'
- # publishJUnitResults: false
- # testResultsFiles: '**/TEST-*.xml'
- # tasks: 'publish'
- # condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
- # env:
- # ARTIFACTORY_USER: $(Artifactory.User)
- # ARTIFACTORY_PASS: $(Artifactory.Password)
- - script: |
- # stop the Gradle daemon to ensure no files are left open (impacting the save cache operation later)
- ./gradlew --stop
- displayName: Kill Daemon
|