File: build-nuget.ps1

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (76 lines) | stat: -rw-r--r-- 2,278 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

# Function returns 4-part 'classic' version string from SemVer 2.0 string
function GenVer4Part([String] $Version)
{
  if ($Version[0] -eq 'v')
  {
    # If tag contains 'v' then strip it
    $Version = $Version.substring(1)
  }
  # Converts from 1.2.3-build4 to 1.2.3.4
  $Version = $Version -replace "-build", "."
  $Version = $Version -replace "-", "."

  $parts = $Version.Split('.');
  # Add missing tuples
  $i = $parts.Count
  while($i -lt 4)
  {
    $parts += "0"
    $i++
  }

  ,$parts
}

function New-TemporaryDirectory
{
  $parent = [System.IO.Path]::GetTempPath()
  [string] $name = [System.Guid]::NewGuid()
  New-Item -ItemType Directory -Path (Join-Path $parent $name)
}

function GetGitWorkTree()
{
  # TODO: presently we assume that GIT_WORK_TREE is 1-level up.
  # Uncomment the following line if this is not the case:
  # $result = (git rev-parse --show-toplevel) -join ''
  $result = ( Get-Item -Path .. ).Fullname
  $result = $result -replace '[\\/]', '\'
  return $result
}

function CopyAll([String] $src, [String] $dest)
{
  $what = @("/COPYALL","/B","/SEC","/MIR")
  $options = @("/R:0","/W:0","/NFL","/NDL","/NJH","/NJS","/NC","/NS")
  $cmdArgs = @("$src","$dest",$what,$options)
  robocopy @cmdArgs
}

$tempDir = New-TemporaryDirectory
$gitWorktree = GetGitWorkTree

$items = Get-ChildItem .\nuget -include *.nuspec -Recurse
foreach ($item in $items)
{
  $nugetName = $item.Basename
  $v = GenVer4Part $env:PackageVersion
  $version = [string]::Join(".", $v, 0, 3)

  Write-Output "Creating nuget $nugetName-$version ..."
  # Copy all files from Git
  CopyAll $gitWorkTree $tempDir.Fullname
  # Append extra nuget package file
  Copy-Item -Path ".\nuget\$nugetName.nuspec" -Destination $tempDir.Fullname
  Copy-Item -Path ".\nuget\opentelemetry-icon-color.png" -Destination $tempDir.Fullname
  # Change to temporary directory
  Push-Location -Path $tempDir.Fullname
  # Pack the nuget package
  nuget pack $nugetName.nuspec -Version $version -NoDefaultExcludes
  Pop-Location
  $nupkgFileName = "$tempDir\$nugetName.$version.nupkg"
  Get-Item $nupkgFileName | Copy-Item -Destination "..\packages"
}