Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/ua-parser-js-0.7.33
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardog authored Feb 20, 2023
2 parents 20abc39 + 2b5aa58 commit 41adac2
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
with:
fetch-depth: 0
- name: Install dependencies
run: choco install GitVersion.Portable ilmerge --confirm --no-progress
run: choco install GitVersion.Portable --version 5.6.11 --confirm --no-progress; choco install il-repack --confirm --no-progress
- name: Update project version
run: gitversion /l console /output buildserver /updateAssemblyInfo /verbosity minimal
- name: Get project version
Expand Down
30 changes: 29 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
contents: write
steps:
- name: Install dependencies
run: choco install GitVersion.Portable wixtoolset --confirm --no-progress
run: choco install GitVersion.Portable --version 5.6.11 --confirm --no-progress; choco install NuGet.CommandLine GitVersion.Portable wixtoolset --confirm --no-progress
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand Down Expand Up @@ -110,6 +110,8 @@ jobs:
path: ./artifacts
- name: Import Chocolatey Api Key
run: choco apikey --key ${{ secrets.CHOCOLATEY_APIKEY }} --source https://push.chocolatey.org/
- name: Import Nuget Api Key
run: nuget setapikey ${{ secrets.NUGET_APIKEY }}
- name: Build Package for Chocolatey & Upload
run: ./build/05-release-Chocolatey.ps1
- name: Upload build artifacts
Expand All @@ -124,6 +126,32 @@ jobs:
identifier: gerardog.gsudo
installers-regex: '\.msi$' # Only .msi files

publishNuget:
name: Push to Nuget
#if: github.ref == 'refs/heads/master' && github.repository == 'gerardog/gsudo'
if: github.repository == 'gerardog/gsudo'
runs-on: windows-latest
needs: [build, release]
permissions:
contents: write
environment:
name: release-nuget
env:
version: ${{ needs.build.outputs.version }}
version_MajorMinorPatch: ${{ needs.build.outputs.version_MajorMinorPatch }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: Binaries
path: ./artifacts
- name: Import Nuget Api Key
run: nuget setapikey ${{ secrets.NUGET_APIKEY }}
- name: Build Package for Nuget & Upload
run: ./build/06-release-Nuget.ps1

docs:
needs: publish
uses: ./.github/workflows/docs.yml
Expand Down
6 changes: 3 additions & 3 deletions build/00-prerequisites.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
choco install ilmerge
choco install il-repack
choco install GitVersion.Portable
choco install wixtoolset
choco install hub
choco install dotnet-7.0-sdk --pre

choco install dotnet-7.0-sdk
choco install NuGet.CommandLine
12 changes: 12 additions & 0 deletions build/01-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\arm64 -f net7
dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x64 -f net7.0 -r win-x64 --sc -p:PublishAot=true -p:IlcOptimizationPreference=Size -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE)
"-- Building net7.0 win-x86"
dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\x86 -f net7.0 -r win-x86 --sc -p:PublishReadyToRun=true -p:PublishSingleFile=true -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE)
"-- Building net4.6 AnyCpu"
dotnet publish .\src\gsudo\gsudo.csproj -c Release -o .\artifacts\net46-AnyCpu\unmerged -f net46 -p:Platform=AnyCpu -v minimal -p:WarningLevel=0 || $(exit $LASTEXITCODE)

"-- Repacking net4.6 AnyCpu into a single EXE"

ilrepack .\artifacts\net46-AnyCpu\unmerged\gsudo.exe .\artifacts\net46-AnyCpu\unmerged\*.dll /out:.\artifacts\net46-AnyCpu\gsudo.exe /target:exe /targetplatform:v4 /ndebug /wildcards || $(exit $LASTEXITCODE)

if ($?) {
rm artifacts\net46-AnyCpu\unmerged -Recurse
echo "artifacts\net46-AnyCpu\unmerged -> ilmerge -> artifacts\net46-AnyCpu\"
}

cp .\src\gsudo.Wrappers\* .\artifacts\x86
cp .\src\gsudo.Wrappers\* .\artifacts\x64
cp .\src\gsudo.Wrappers\* .\artifacts\arm64
cp .\src\gsudo.Wrappers\* .\artifacts\net46-AnyCpu

popd
2 changes: 2 additions & 0 deletions build/03-sign.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ $files = @(
"artifacts\x64\*.p*1"
"artifacts\x86\*.exe",
"artifacts\x86\*.p*1",
"artifacts\net46-AnyCpu\*.exe",
"artifacts\net46-AnyCpu\*.p*1",
"artifacts\arm64\*.exe",
"artifacts\arm64\*.p*1"
) -join " "
Expand Down
2 changes: 1 addition & 1 deletion build/04-release-GitHub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ($env:version) {
Get-ChildItem .\artifacts\ -File | Remove-Item # Remove files on artifacts root
Get-ChildItem .\artifacts\ -Filter *.pdb -Recurse | Remove-Item # Remove *.pdb on subfolders

Compress-Archive -Path ./artifacts/x86,./artifacts/x64,./artifacts/arm64 -DestinationPath "artifacts/gsudo.v$($version).zip" -force -CompressionLevel Optimal
Compress-Archive -Path ./artifacts/x86,./artifacts/x64,./artifacts/arm64,./artifacts/net46-AnyCpu -DestinationPath "artifacts/gsudo.v$($version).zip" -force -CompressionLevel Optimal
(Get-FileHash artifacts\gsudo.v$($version).zip).hash > artifacts\gsudo.v$($version).zip.sha256

$msbuild = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
Expand Down
4 changes: 2 additions & 2 deletions build/05-release-Chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ if (! (Test-IsAdmin)) {
throw "Must be admin to properly test generated package"
}

Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts")

pushd $PSScriptRoot\..

Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts")

if ($env:version) {
"- Getting version from env:version"
$version = $env:version
Expand Down
28 changes: 28 additions & 0 deletions build/06-release-Nuget.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pushd $PSScriptRoot\..

Get-Item .\artifacts\x64\gsudo.exe > $null || $(throw "Missing binaries/artifacts")

if ($env:version) {
"- Getting version from env:version"
$version = $env:version
$version_MajorMinorPatch=$env:version_MajorMinorPatch
} else {
"- Getting version using GitVersion"
$version = $(gitversion /showvariable LegacySemVer)
$version_MajorMinorPatch=$(gitversion /showvariable MajorMinorPatch)
}
"- Using version number v$version / v$version_MajorMinorPatch"

"- Cleaning Nuget template folder"
git clean .\Build\Nuget\gsudo -xf

"- Packing v$version to nuget"
dotnet build .\Build\Nuget\gsudo.csproj /p:Version=$version -o artifacts\Nuget || $(throw "Nuget pack failed.")

"`n- Uploading v$version to Nuget"
gi "artifacts\nuget\gsudo.$($version).nupkg" || $(throw "Nuget push failed.")
nuget push artifacts\nuget\gsudo.$($version).nupkg -Source https://api.nuget.org/v3/index.json || $(throw "Nuget push failed.")


"- Success"
popd
1 change: 0 additions & 1 deletion build/06-release-Scoop.ps1

This file was deleted.

40 changes: 40 additions & 0 deletions build/Nuget/gsudo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">

<PropertyGroup>
<Version>1.0.0.0</Version>
<Company>Gerardo Grignoli</Company>
<Authors>Gerardo Grignoli</Authors>
<PackageId>gsudo</PackageId>
<PackageTags>gsudo;sudo;runas</PackageTags>
<Description>gsudo is a sudo for Windows, allows to run commands with elevated permissions in the current console.</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<NoBuild>true</NoBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackFrameworkReferences>false</PackFrameworkReferences>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<Copyright>Gerardo Grignoli and GitHub Contributors</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/gerardog/gsudo</PackageProjectUrl>
<RepositoryUrl>https://github.com/gerardog/gsudo</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
</PropertyGroup>

<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\net46-AnyCpu\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-anycpu\native\gsudo.exe</PackagePath>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\x86\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-x86\native\gsudo.exe</PackagePath>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\x64\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-x64\native\gsudo.exe</PackagePath>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\..\artifacts\arm64\gsudo.exe" Pack="true">
<PackagePath>runtimes\win-arm64\native\gsudo.exe</PackagePath>
</Content>
<Content Include="gsudo.targets" PackagePath="build/gsudo.targets" Pack="true" />
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions build/Nuget/gsudo.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-anycpu\native\gsudo.exe">
<Link>gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-x86\native\gsudo.exe">
<Link>runtimes\win-x86\native\gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-x64\native\gsudo.exe">
<Link>runtimes\win-x64\native\gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\runtimes\win-arm64\native\gsudo.exe">
<Link>runtimes\win-arm64\native\gsudo.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/gsudo.Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

<Product Id="*" Name="gsudo v$(env.version)" Language="1033" Version="$(env.version_MajorMinorPatch)"
UpgradeCode="567b5616-d362-484e-b6ff-7c1875cf0aee" Manufacturer="gerardog">
UpgradeCode="567b5616-d362-484e-b6ff-7c1875cf0aee" Manufacturer="Gerardo Grignoli">

<Package InstallerVersion="200"
Compressed="yes"
Expand Down
58 changes: 58 additions & 0 deletions src/gsudo.Wrappers/gsudoModule.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,64 @@ $c += "}"
iex ($c -join "`n" | Out-String)

function gsudo {
<#
.SYNOPSIS
Runs a command/scriptblock with elevated permissions. If no command is specified, it starts an elevated Powershell session.
.DESCRIPTION
This function will attempt to retrieve a matching registry key for an
already installed application, usually to be used with a
chocolateyUninstall.ps1 automation script.
The function also prevents `Get-ItemProperty` from failing when
handling wrongly encoded registry keys.
.NOTES
Available in 0.9.10+. If you need to maintain compatibility with pre
0.9.10, please add the following to your nuspec (check for minimum
version):
~~~xml
<dependencies>
<dependency id="chocolatey-core.extension" version="1.1.0" />
</dependencies>
~~~
.INPUTS
String
.OUTPUTS
This function searches registry objects and returns an array
of PSCustomObject with the matched key's properties.
Retrieve properties with dot notation, for example:
`$key.UninstallString`
.EXAMPLE
>
# Version match: Software name is "Gpg4Win (2.3.0)"
[array]$key = Get-UninstallRegistryKey -SoftwareName "Gpg4win (*)"
$key.UninstallString
.EXAMPLE
>
# Fuzzy match: Software name is "Launchy 2.5"
[array]$key = Get-UninstallRegistryKey -SoftwareName "Launchy*"
$key.UninstallString
.EXAMPLE
>
# Exact match: Software name in Programs and Features is "VLC media player"
[array]$key = Get-UninstallRegistryKey -SoftwareName "VLC media player"
$key.UninstallString
.EXAMPLE
>
# Elevate your current shell
gsudo
#>

$invocationLine = $MyInvocation.Line -replace "^$($MyInvocation.InvocationName)\s+" # -replace '"','""'

if ($invocationLine -match "(^| )!!( |$)")
Expand Down

0 comments on commit 41adac2

Please sign in to comment.