Skip to content

Commit 6207c93

Browse files
committed
Check that crate is publishable
1 parent 7d721f4 commit 6207c93

File tree

1 file changed

+60
-48
lines changed

1 file changed

+60
-48
lines changed

eng/pipelines/templates/stages/archetype-rust-release.yml

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,29 @@ stages:
3838

3939
jobs:
4040
# TODO: Ensure that CHANGELOG is properly processed
41-
# - job: TagRepository
42-
# displayName: "Create release tag"
43-
# condition: and(succeeded(), ne(variables['Skip.TagRepository'], 'true'))
41+
- job: TagRepository
42+
displayName: "Create release tag"
43+
condition: and(succeeded(), ne(variables['Skip.TagRepository'], 'true'))
4444

45-
# steps:
46-
# - template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
45+
steps:
46+
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
4747

48-
# - download: current
49-
# displayName: Download ${{parameters.PipelineArtifactName}} artifact
50-
# artifact: ${{parameters.PipelineArtifactName}}
48+
- download: current
49+
displayName: Download ${{parameters.PipelineArtifactName}} artifact
50+
artifact: ${{parameters.PipelineArtifactName}}
5151

52-
# - template: /eng/common/pipelines/templates/steps/retain-run.yml
52+
- template: /eng/common/pipelines/templates/steps/retain-run.yml
5353

54-
# - script: |
55-
# echo "##vso[build.addbuildtag]${{artifact.name}}"
56-
# displayName: Add build tag '${{artifact.name}}'
54+
- script: |
55+
echo "##vso[build.addbuildtag]${{artifact.name}}"
56+
displayName: Add build tag '${{artifact.name}}'
5757
58-
# - template: /eng/common/pipelines/templates/steps/create-tags-and-git-release.yml
59-
# parameters:
60-
# ArtifactLocation: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}/${{artifact.name}}
61-
# PackageRepository: Crates.io
62-
# ReleaseSha: $(Build.SourceVersion)
63-
# WorkingDirectory: $(Pipeline.Workspace)/_work
58+
- template: /eng/common/pipelines/templates/steps/create-tags-and-git-release.yml
59+
parameters:
60+
ArtifactLocation: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}/${{artifact.name}}
61+
PackageRepository: Crates.io
62+
ReleaseSha: $(Build.SourceVersion)
63+
WorkingDirectory: $(Pipeline.Workspace)/_work
6464

6565
- deployment: PublishPackage
6666
displayName: "Publish to Crates.io"
@@ -76,7 +76,7 @@ stages:
7676
# This timeout shouldn't be necessary once we're able to parallelize better. Right now,
7777
# this is here to ensure larger areas (30+) libraries don't time out.
7878
timeoutInMinutes: 120
79-
# dependsOn: TagRepository
79+
dependsOn: TagRepository
8080
pool:
8181
name: azsdk-pool
8282
image: ubuntu-24.04
@@ -102,17 +102,53 @@ stages:
102102
$packageVersion = $packageMetadata.version
103103
Write-Host "Package version: $packageVersion"
104104
105+
$cratePath = "$ArtifactRootPath/$ArtifactName/$ArtifactName-$packageVersion.crate"
106+
Write-Host "##vso[task.setvariable variable=CratePath]$cratePath"
107+
105108
New-Item -ItemType Directory -Path $OutDir -Force | Out-Null
106-
# Compress-Archive `
107-
# -Path "$ArtifactRootPath/$ArtifactName/$ArtifactName-$packageVersion.crate" `
108-
# -DestinationPath "$OutDir/release.zip"
109109
Copy-Item `
110-
-Path "$ArtifactRootPath/$ArtifactName/$ArtifactName-$packageVersion.crate" `
110+
-Path $cratePath`
111111
-Destination $OutDir
112112
Write-Host "Contents of $OutDir"
113113
Get-ChildItem -Path $OutDir | ForEach-Object { Write-Host $_.FullName }
114+
displayName: Copy crate for ESRP
114115
115-
displayName: Compress Crate for ESRP
116+
- pwsh: |
117+
$CratePath = '$(CratePath)'
118+
if (!(Test-Path $CratePath)) {
119+
Write-Error "Crate file not found: $CratePath"
120+
exit 1
121+
}
122+
123+
$evaluationDir = (Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()))
124+
125+
New-Item -ItemType Directory -Path $evaluationDir -Force | Out-Null
126+
Invoke-Expression "tar --exclude `"Cargo.toml.orig`" -xzvf $CratePath -C $evaluationDir"
127+
128+
if ($LASTEXITCODE) {
129+
Write-Host "Failed to extract crate $CratePath"
130+
exit 1
131+
}
132+
133+
Set-Location $evaluationDir
134+
Set-Location (Join-Path $evaluationDir $crateName)
135+
136+
$command = @(
137+
"cargo publish",
138+
"--locked",
139+
"--dry-run",
140+
"--package $packageName",
141+
"--allow-dirty"
142+
) -join ' '
143+
Invoke-Expression $command
144+
145+
if ($LASTEXITCODE) {
146+
Write-Host "Crate $crateName is NOT publishable"
147+
exit 1
148+
} else {
149+
Write-Host "Crate $crateName is publishable"
150+
}
151+
displayName: Verify crate is publishable
116152
117153
- task: EsrpRelease@10
118154
displayName: 'ESRP Release'
@@ -133,30 +169,6 @@ stages:
133169
serviceendpointurl: 'https://api.esrp.microsoft.com/'
134170
mainpublisher: 'ESRPRELPACMANTEST'
135171

136-
# - pwsh: |
137-
# $additionalOwners = @('heaths', 'hallipr')
138-
# $token = $env:CARGO_REGISTRY_TOKEN
139-
# $crateName = '${{artifact.name}}'
140-
141-
# $manifestPath = "$(Pipeline.Workspace)/drop/$crateName/contents/Cargo.toml"
142-
# Write-Host "> cargo publish --manifest-path `"$manifestPath`""
143-
# cargo publish --manifest-path $manifestPath
144-
# if (!$?) {
145-
# Write-Error "Failed to publish package: '$crateName'"
146-
# exit 1
147-
# }
148-
149-
# $existingOwners = (cargo owner --list $crateName) -replace " \(.*", ""
150-
# $missingOwners = $additionalOwners | Where-Object { $existingOwners -notcontains $_ }
151-
152-
# foreach ($owner in $missingOwners) {
153-
# Write-Host "> cargo owner --add $owner $crateName"
154-
# cargo owner --add $owner $crateName
155-
# }
156-
# displayName: Publish Crate
157-
# env:
158-
# CARGO_REGISTRY_TOKEN: $(azure-sdk-cratesio-token)
159-
160172
- job: UpdatePackageVersion
161173
displayName: "API Review and Package Version Update"
162174
condition: and(succeeded(), ne(variables['Skip.UpdatePackageVersion'], 'true'))

0 commit comments

Comments
 (0)