Skip to content

Commit

Permalink
Reestructuring pipeline definitions to future-proof it.
Browse files Browse the repository at this point in the history
  • Loading branch information
glecaros committed Aug 29, 2023
1 parent 8c9f05f commit b5570e4
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 84 deletions.
106 changes: 71 additions & 35 deletions .azure/pipelines/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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.
22 changes: 11 additions & 11 deletions .azure/pipelines/scripts/set-variables.sh
Original file line number Diff line number Diff line change
@@ -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"
38 changes: 0 additions & 38 deletions .github/workflows/build-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

0 comments on commit b5570e4

Please sign in to comment.