From b5570e4707d4ba151867d8c4fe1e4adb4506b179 Mon Sep 17 00:00:00 2001 From: Gerardo Lecaros Date: Mon, 28 Aug 2023 13:41:14 -0700 Subject: [PATCH] Reestructuring pipeline definitions to future-proof it. --- .azure/pipelines/build.yaml | 106 +++++++++++++++------- .azure/pipelines/scripts/set-variables.sh | 22 ++--- .github/workflows/build-package.yaml | 38 -------- 3 files changed, 82 insertions(+), 84 deletions(-) diff --git a/.azure/pipelines/build.yaml b/.azure/pipelines/build.yaml index e480a657..b1b575cf 100644 --- a/.azure/pipelines/build.yaml +++ b/.azure/pipelines/build.yaml @@ -9,38 +9,74 @@ pr: pool: vmImage: ubuntu-latest -steps: - - task: Bash@3 - inputs: - filePath: ./.azure/pipelines/scripts/set-variables.sh - displayName: 'Set up environment variables' - - task: DotNetCoreCLI@2 - displayName: Restore packages - inputs: - command: restore - projects: 'src/ai/**/*.csproj' - - task: DotNetCoreCLI@2 - displayName: Build - inputs: - command: build - projects: 'src/ai/**/*.csproj' - arguments: '--configuration Release' - - task: DotNetCoreCLI@2 - displayName: Pack - condition: and(succeeded(), eq(variables['ShouldCreateRelease'], 'true')) - env: - AI_VERSION: $(AICLIVersion) - inputs: - command: pack - packagesToPack: 'src/ai/ai-cli.csproj' - versioningScheme: 'byEnvVar' - versionEnvVar: 'AI_VERSION' - arguments: '--configuration Release' - - task: AzureCLI@2 - displayName: Upload package to Azure - condition: and(succeeded(), eq(variables['ShouldCreateRelease'], 'true')) - inputs: - azureSubscription: 'Carbon Dropper (CSSpeechStorage Drop)' - scriptType: 'bash' - arguments: '$(Build.StagingDirectory)/$(AICLINuPkgFileName) private/ai/$(AICLINuPkgFileName)' - scriptPath: './.azure/pipelines/scripts/upload-file.sh' \ No newline at end of file +jobs: + - job: Setup + steps: + - task: Bash@3 + name: Variables + inputs: + filePath: ./.azure/pipelines/scripts/set-variables.sh + displayName: 'Set up environment variables' + + - job: Build + dependsOn: Setup + variables: + AICLIVersion: $[ dependencies.Setup.outputs['Variables.AICLIVersion']] + steps: + - task: DotNetCoreCLI@2 + displayName: Restore packages + inputs: + command: restore + projects: 'src/ai/**/*.csproj' + - task: DotNetCoreCLI@2 + displayName: Build + inputs: + command: build + projects: 'src/ai/**/*.csproj' + arguments: '--configuration Release' + - task: DotNetCoreCLI@2 + displayName: Pack + env: + AI_VERSION: $(AICLIVersion) + inputs: + command: pack + packagesToPack: 'src/ai/ai-cli.csproj' + versioningScheme: 'byEnvVar' + versionEnvVar: 'AI_VERSION' + arguments: '--configuration Release' + - task: PublishPipelineArtifact@1 + displayName: Publish artifacts + inputs: + targetPath: '$(Build.StagingDirectory)' + artifact: 'ai-cli-artifacts' + + - job: Publish + dependsOn: [Setup, Build] + variables: + IsRelease: $[ dependencies.Setup.outputs['Variables.IsRelease']] + AICLIVersion: $[ dependencies.Setup.outputs['Variables.AICLIVersion']] + AICLINuPkgFileName: $[ dependencies.Setup.outputs['Variables.AICLINuPkgFileName']] + condition: and(succeeded(), eq(variables['IsRelease'], 'true')) + steps: + - task: DownloadPipelineArtifact@2 + displayName: Download artifacts + inputs: + artifact: 'ai-cli-artifacts' + targetPath: '$(Build.ArtifactStagingDirectory)' + - task: AzureCLI@2 + displayName: Upload package to Azure + inputs: + azureSubscription: 'Carbon Dropper (CSSpeechStorage Drop)' + scriptType: 'bash' + arguments: '$(Build.ArtifactStagingDirectory)/$(AICLINuPkgFileName) private/ai/$(AICLINuPkgFileName)' + scriptPath: './.azure/pipelines/scripts/upload-file.sh' + - task: GithubRelease@1 + displayName: Create GitHub release + inputs: + gitHubConnection: 'AzureGH' + tagSource: gitTag + title: 'Azure AI CLI $(AICLIVersion)' + releaseNotesSource: inline + addChangeLog: true + releaseNoteInline: | + Version $(AICLIVersion) of the Azure AI CLI. \ No newline at end of file diff --git a/.azure/pipelines/scripts/set-variables.sh b/.azure/pipelines/scripts/set-variables.sh index 9d1aa643..d502c600 100644 --- a/.azure/pipelines/scripts/set-variables.sh +++ b/.azure/pipelines/scripts/set-variables.sh @@ -1,22 +1,22 @@ #!/bin/bash +define_variable () { + echo "##vso[task.setvariable variable=$1;isOutput=true]$2" +} + echo "Source branch: $BUILD_SOURCEBRANCH" # If the build was triggered from a tag, use the tag as the version. Otherwise, set the version to dev. REGEX='^refs\/tags\/v?([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)(-.+)?' # If tag is a release tag, set up release variables. -if [[ $BUILD_SOURCEBRANCH =~ $REGEX ]]; then - echo "##vso[task.setvariable variable=ShouldCreateRelease]true" +[[ $BUILD_SOURCEBRANCH =~ $REGEX ]] && define_variable "IsRelease" "true" || define_variable "IsRelease" "false" - # Extract version from the tag. - VERSION=$(echo $BUILD_SOURCEBRANCH | sed -r 's/'$REGEX'/\1.\2.\3\4/') +# Extract version from the tag. +VERSION=$([[ $BUILD_SOURCEBRANCH =~ $REGEX ]] && echo $(echo $BUILD_SOURCEBRANCH | sed -r 's/'$REGEX'/\1.\2.\3\4/') || echo "0.0.0-dev") - # Set the AICLIVersion variable in the pipeline. - echo "##vso[task.setvariable variable=AICLIVersion]$VERSION" +# Set the AICLIVersion variable in the pipeline. +define_variable "AICLIVersion" "$VERSION" - # Set the AICLINuPkgFileName variable in the pipeline. - echo "##vso[task.setvariable variable=AICLINuPkgFileName]Azure.AI.CLI.$VERSION.nupkg" -else - echo "##vso[task.setvariable variable=ShouldCreateRelease]false" -fi +# Set the AICLINuPkgFileName variable in the pipeline. +define_variable "AICLINuPkgFileName" "Azure.AI.CLI.$VERSION.nupkg" diff --git a/.github/workflows/build-package.yaml b/.github/workflows/build-package.yaml index f2e2bf53..0cd920ac 100644 --- a/.github/workflows/build-package.yaml +++ b/.github/workflows/build-package.yaml @@ -37,41 +37,3 @@ jobs: with: name: cli-tool-artifacts path: ${{env.BUILD_ARTIFACTSTAGINGDIRECTORY}} - - release: - needs: build - runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up .NET Core - uses: actions/setup-dotnet@v2 - with: - dotnet-version: '7.0.x' # Set the desired .NET version - - - name: Download artifacts - uses: actions/download-artifact@v2 - with: - name: cli-tool-artifacts - path: artifacts - - - name: Extract package version - id: extract-version - run: | - echo "Package files: $(ls artifacts/*.nupkg)" - package_path=$(ls artifacts/*.nupkg) - package_version=$(dotnet nuget list source "$package_path" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+") - echo "::set-output name=package_version::$package_version" - - - name: Create GitHub Release - id: create-release - uses: softprops/action-gh-release@v1 - with: - files: artifacts/*.nupkg - tag_name: ${{steps.extract-version.outputs.package_version}} - title: Release ${{steps.extract-version.outputs.package_version}} - body: | - Release of the CLI tool version ${{steps.extract-version.outputs.package_version}}