Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to package all of powershell core as a NuGet Package #4363

Merged
merged 20 commits into from
Aug 1, 2017

Conversation

TravisEz13
Copy link
Member

@TravisEz13 TravisEz13 commented Jul 27, 2017

Example usage

function Update-Powershell 
{
    param([string]$target='~/powershell')

    if(!(Get-PackageSource -Name powershell -ErrorAction SilentlyContinue))
    {
        Register-PackageSource -Name powershell -Location https://powershell.myget.org/F/powershell-core-daily  -ProviderName nuget -Trusted
    }

    if($ismacos){
        $package = 'powershell-osx.10.12-x64'
    }
    elseif($iswindows)
    {
        $package = 'powershell-win-x64-win7-x64'
    }
    elseif($islinux)
    {
        $package = 'powershell-linux-x64'
    }

    if(!(test-path $target))
    {
        md $target
    }

    find-package -Source powershell -AllowPrereleaseVersions -name $package |Install-Package -Destination $target -ExcludeVersion
    if(!$isWindows){
        chmod a+x "$target/$package/content/pwsh"
    }
    &"$target/$package/content/pwsh"
}


# Setup staging directory so we don't change the original source directory
$stagingRoot = New-SubFolder -Path $PSScriptRoot -ChildPath 'nugetStaging' -Clean
$toolsFolder = Join-Path -path $stagingRoot -ChildPath 'tools'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the name to 'content'

<metadata>
<id>powershell-$runtime$</id>
<version>$version$</version>
<title>PowerShell CLI for $runtime$</title>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we never use "CLI". Maybe <title>PowerShell Core $runtime$</title>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just PowerShell for $runtime$ :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to PowerShell Core

<version>$version$</version>
<title>PowerShell CLI for $runtime$</title>
<authors>Microsoft PowerShell</authors>
<owners>Microsoft PowerShell</owners>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have #4352 under review - should we use "Microsoft" in community project?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove microsoft

build.psm1 Outdated
@@ -4,6 +4,84 @@ $script:TestModulePathSeparator = [System.IO.Path]::PathSeparator

$dotnetCLIChannel = "preview"
$dotnetCLIRequiredVersion = "2.0.0-preview2-006502"
$tagsUpToDate = $false
function Get-PSTags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use the verb Sync, as Get- usually indicates result(s) will be returned while Sync is an action.

build.psm1 Outdated
}

$lastestTagCommitId = git rev-list --tags --max-count=1
return (git --git-dir="$PSScriptRoot/.git" describe $lastestTagCommitId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about return (git tag --list --sort=-v:refname | Select-Object -First 1)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your proposed implementation depends on version sorting.
The code I wrote gets the latest commit which is a tag, then gets the name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline and git describe --abbrev=0 does what you intended.

build.psm1 Outdated
$latestTag = Get-PSLatestTag
# Get the last commit id in the current branch
$commitId = git log --pretty="%H" -n1
# check in the branch is dirty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: in -> if

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

build.psm1 Outdated
# Get the last commit id in the current branch
$commitId = git log --pretty="%H" -n1
# check in the branch is dirty
$isDirty = (git describe --dirty) -match '-dirty$'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git describe --dirty causes git to crash on my machine. No idea why is that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it could not find the git-dir. I'll update all the commands to specify it.

<metadata>
<id>powershell-$runtime$</id>
<version>$version$</version>
<title>PowerShell CLI for $runtime$</title>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just PowerShell for $runtime$ :)

if($pscmdlet.ShouldProcess("Create NuPkg Package"))
{
New-NugetPackage @Arguments
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there are trailing spaces in this line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#resolved

[string]$Iteration = "1",

[Switch]
$Force
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: same here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#resolved

-->
<PropertyGroup>
<AssemblyName>NotUsed</AssemblyName>
<Description>PowerShell top-level project with .NET CLI host</Description>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description needs to be updated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#resloved

<licenseUrl>https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>https://github.com/powershell/powershell</projectUrl>
<iconUrl>https://github.com/PowerShell/PowerShell/blob/master/assets/Powershell_64.png</iconUrl>
<description>This package contains the PowerShell CLI for $runtime$.</description>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowerShell CLI

Maybe just PowerShell

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to PowerShell Core

build.psm1 Outdated
$commitId+='-dirty'
}

return "$latestTag-x-g$commitId"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we continue to use git describe to get the commit id. It should work as long as we merge the release branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

}
elseif(!$upstreamRemote)
{
Write-Error "Please add a remote to PowerShell\PowerShell. Example: git remote add $upstreamRemoteDefaultName $PowerShellRemoteUrl" -ErrorAction Stop
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we continue to execute the script after the error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not continue executing the script unless you have a remote to PowerShell as the error indicates. The script has always assumed you can fetch the tags. This is just adding a verification.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only occur when someone manually runs the function and it cannot complete the action. So, returning an error and stopping is the correct thing to do.

-->
<PropertyGroup>
<AssemblyName>NotUsed</AssemblyName>
<Description>PowerShell Core nuget packag with .NET CLI host including everything needed to run it.</Description>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo - "packag".

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for a minor comment.

build.psm1 Outdated
@@ -4,6 +4,79 @@ $script:TestModulePathSeparator = [System.IO.Path]::PathSeparator

$dotnetCLIChannel = "preview"
$dotnetCLIRequiredVersion = "2.0.0-preview2-006502"
$tagsUpToDate = $false

function Sync-PSTags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment to explain why we need to run Sync-PSTags before getting the version (tag) and commit ID? It will help people to understand.

@daxian-dbw daxian-dbw merged commit e829053 into PowerShell:master Aug 1, 2017
@TravisEz13 TravisEz13 deleted the AddNugetPackagingV2 branch August 4, 2017 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants