|
| 1 | +parameters: |
| 2 | + - name: channel |
| 3 | + type: string |
| 4 | + - name: release |
| 5 | + default: 'private' |
| 6 | + |
| 7 | +jobs: |
| 8 | +- job: push |
| 9 | + displayName: Push to ${{ parameters.release }} |
| 10 | + |
| 11 | + pool: |
| 12 | + type: linux |
| 13 | + isCustom: true |
| 14 | + name: $(ubuntuPool) |
| 15 | + demands: |
| 16 | + - ImageOverride -equals PSMMSUbuntu20.04-Secure |
| 17 | + |
| 18 | + variables: |
| 19 | + - name: ReleaseTag |
| 20 | + value: edge/default |
| 21 | + - group: SnapLogin |
| 22 | + - name: channel |
| 23 | + value: ${{ parameters.channel }} |
| 24 | + - name: ob_outputDirectory |
| 25 | + value: '$(Build.ArtifactStagingDirectory)/out' |
| 26 | + - name: DOWNLOAD_DIRECTORY |
| 27 | + value: '$(Build.ArtifactStagingDirectory)/down' |
| 28 | + |
| 29 | + steps: |
| 30 | + - checkout: self |
| 31 | + lfs: false |
| 32 | + |
| 33 | + - template: ./createOutputDirectory-linux.yml |
| 34 | + |
| 35 | + - task: DownloadPipelineArtifact@2 |
| 36 | + displayName: 'Download build files' |
| 37 | + inputs: |
| 38 | + targetPath: $(DOWNLOAD_DIRECTORY) |
| 39 | + artifact: drop_build_$(channel)_build_$(channel) |
| 40 | + |
| 41 | + - pwsh: | |
| 42 | + $snaps = Get-ChildItem $(DOWNLOAD_DIRECTORY)/*.snap -recurse -File |
| 43 | + if($snaps.Count -gt 1) |
| 44 | + { |
| 45 | + $snaps | out-string -width 100 | Write-Verbose -verbose |
| 46 | + Write-Error "***More than one snap found***" -errorAction stop |
| 47 | + } |
| 48 | + displayName: Verify that only one snap was downloaded |
| 49 | +
|
| 50 | + - pwsh: | |
| 51 | + [string]$Branch=$env:BUILD_SOURCEBRANCH |
| 52 | + $branchOnly = $Branch -replace '^refs/heads/'; |
| 53 | + $branchOnly = $branchOnly -replace '[_\-]' |
| 54 | +
|
| 55 | + if('${{ parameters.release }}' -eq 'private') { |
| 56 | + if($branchOnly -eq 'master' -or $branchOnly -like '*dailytest*') |
| 57 | + { |
| 58 | + Write-verbose "release branch: $branchOnly" -verbose |
| 59 | + $generatedBranch = ([guid]::NewGuid()).ToString().Replace('-','') |
| 60 | + $releaseTag = "edge/$generatedBranch" |
| 61 | + } |
| 62 | + else |
| 63 | + { |
| 64 | + Write-verbose "non-release branch" -verbose |
| 65 | + # Branch is named <previewname> |
| 66 | + $releaseTag = "edge/$branchOnly" |
| 67 | + $releaseTag += ([guid]::NewGuid()).ToString().Replace('-','') |
| 68 | + } |
| 69 | + } |
| 70 | + else { |
| 71 | + $releaseTag = "${{ parameters.release }}" |
| 72 | + } |
| 73 | +
|
| 74 | + $vstsCommandString = "vso[task.setvariable variable=ReleaseTag]$releaseTag" |
| 75 | + Write-Verbose -Message "setting ReleaseTag to $releaseTag" -Verbose |
| 76 | + Write-Host -Object "##$vstsCommandString" |
| 77 | + displayName: Set ReleaseTag Variable |
| 78 | +
|
| 79 | + - pwsh: | |
| 80 | + sudo chown root:root / |
| 81 | + displayName: 'Make sure root owns root' |
| 82 | + condition: succeeded() |
| 83 | +
|
| 84 | + - template: ./InstallSnapd.yml |
| 85 | + |
| 86 | + - pwsh: | |
| 87 | + $channel = (Get-Content ./snapcraftConfig.json | ConvertFrom-Json).channel |
| 88 | + Write-Verbose -Verbose -Message "using Channel $channel" |
| 89 | + sudo snap install snapcraft --classic "--channel=$channel" |
| 90 | + condition: succeeded() |
| 91 | + displayName: 'Install snapcraft' |
| 92 | + retryCountOnTaskFailure: 2 |
| 93 | +
|
| 94 | + - pwsh: | |
| 95 | + $track = 'latest' |
| 96 | + if('$(channel)' -eq 'lts') |
| 97 | + { |
| 98 | + $track = 'lts' |
| 99 | + } |
| 100 | +
|
| 101 | + $snaps = Get-ChildItem $(System.ArtifactsDirectory)/*.snap -recurse -File | Select-Object -ExpandProperty FullName |
| 102 | +
|
| 103 | + foreach($snap in $snaps) |
| 104 | + { |
| 105 | + Write-Verbose -Verbose -Message "Uploading $snap to $track/$(ReleaseTag)" |
| 106 | + snapcraft upload --release "$track/$(ReleaseTag)" $snap |
| 107 | + } |
| 108 | + displayName: 'snapcraft upload' |
| 109 | + retryCountOnTaskFailure: 1 |
| 110 | + env: |
| 111 | + SNAPCRAFT_STORE_CREDENTIALS: $(SNAPCRAFT_STORE_CREDENTIALS) |
0 commit comments