Skip to content

Commit eb4b43b

Browse files
committed
[gh-actions] publishing nuget package on release
1 parent 9e90cdd commit eb4b43b

5 files changed

Lines changed: 181 additions & 63 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: 🚀 release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
release:
9+
name: 🚀 release
10+
runs-on: windows-latest
11+
permissions:
12+
contents: read
13+
id-token: write # enable GitHub OIDC token issuance for this job
14+
15+
steps:
16+
- name: 📚 checkout
17+
uses: actions/checkout@v4
18+
19+
- name: ⚙️ Setup .NET
20+
uses: actions/setup-dotnet@v4
21+
with:
22+
dotnet-version: "6.0.x"
23+
24+
- name: 🔓 Decrypt strong-name key
25+
run: bin/EncryptDecryptFile.PS1
26+
shell: pwsh
27+
env:
28+
SN_PASSPHRASE: ${{ secrets.SN_PASSPHRASE }}
29+
SN_SALT: ${{ secrets.SN_SALT }}
30+
SN_INIT: ${{ secrets.SN_INIT }}
31+
32+
- name: 📝 Update version
33+
run: bin/Update-Version.PS1 -Version "$env:VERSION"
34+
shell: pwsh
35+
env:
36+
VERSION: ${{ github.ref_name }}
37+
38+
- name: 📦 Restore dependencies
39+
run: dotnet restore jmespath.net.sln
40+
41+
- name: 🔨 Build
42+
run: dotnet build jmespath.net.sln --configuration Release --no-restore
43+
44+
- name: 🏗️ Create NuGet packages
45+
run: |
46+
dotnet pack --no-build "src/jmespath.net" -c Release
47+
$targetPath = "src/jmespath.net.parser/bin/Release"
48+
cp "src/jmespath.net.parser/JmesPath.Net.Parser.nuspec" $targetPath
49+
mkdir "$targetPath/lib" | Out-Null
50+
mv "$targetPath/netstandard1.3" "$targetPath/lib/netstandard1.3"
51+
mv "$targetPath/netstandard2.1" "$targetPath/lib/netstandard2.1"
52+
mv "$targetPath/net45" "$targetPath/lib/net45"
53+
cd $targetPath
54+
nuget pack
55+
shell: pwsh
56+
57+
# Use the ambient GitHub token to login to NuGet and retrieve an API key
58+
- name: 🔑 NuGet login (OIDC → temp API key)
59+
uses: NuGet/login@v1
60+
id: login
61+
with:
62+
# Secret is your NuGet username, e.g. 'jmespath-community'
63+
user: ${{ secrets.NUGET_USER }}
64+
65+
- name: 📤 Push to NuGet
66+
# Only push to NuGet if we're building a tag (optional)
67+
if: startsWith(github.ref, 'refs/tags/')
68+
shell: pwsh
69+
# Loop through all the packages in the output folder and push them to
70+
# nuget.org, using the NUGET_API_KEY generated by the previous login step
71+
run: |
72+
Get-ChildItem src/ -Filter *.nupkg | ForEach-Object {
73+
dotnet nuget push $_.FullName `
74+
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" `
75+
--source https://api.nuget.org/v3/index.json
76+
}

bin/EncryptDecryptFile.PS1

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
[CmdletBinding()]
2+
param(
3+
[switch]$Encrypt
4+
)
5+
16
#################
27
# Powershell Allows The Loading of .NET Assemblies
3-
# Load the Security assembly to use with this script
8+
# Load the Security assembly to use with this script
49
#################
5-
[Reflection.Assembly]::LoadWithPartialName("System.Security")
10+
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
611

712
#################
813
# This function is to Encrypt A String.
914
# $string is the string to encrypt, $passphrase is a second security "password" that has to be passed to decrypt.
1015
# $salt is used during the generation of the crypto password to prevent password guessing.
1116
# $init is used to compute the crypto hash -- a checksum of the encryption
1217
#################
13-
function Encrypt-File($path, $Passphrase, $salt="SaltCrypto", $init="IV_Password", $outputPath)
18+
Function Encrypt-File
1419
{
20+
param(
21+
[string] $path,
22+
[string] $Passphrase,
23+
[string] $outputPath,
24+
[string] $salt="SaltCrypto",
25+
[string] $init="IV_Password"
26+
)
27+
1528
# Create a COM Object for RijndaelManaged Cryptography
1629
$r = new-Object System.Security.Cryptography.RijndaelManaged
1730
# Convert the Passphrase to UTF8 Bytes
@@ -23,8 +36,8 @@ function Encrypt-File($path, $Passphrase, $salt="SaltCrypto", $init="IV_Password
2336
$r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32) #256/8
2437
# Create the Intersecting Vector Cryptology Hash with the init
2538
$r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
26-
27-
# Starts the New Encryption using the Key and IV
39+
40+
# Starts the New Encryption using the Key and IV
2841
$c = $r.CreateEncryptor()
2942
# Creates a MemoryStream to do the encryption in
3043
$ms = new-Object IO.MemoryStream
@@ -48,8 +61,16 @@ function Encrypt-File($path, $Passphrase, $salt="SaltCrypto", $init="IV_Password
4861
$os.Close();
4962
}
5063

51-
function Decrypt-File($path, $Passphrase, $salt="SaltCrypto", $init="IV_Password", $OutputPath)
64+
Function Decrypt-File
5265
{
66+
param(
67+
[string] $path,
68+
[string] $Passphrase,
69+
[string] $OutputPath,
70+
[string] $salt="SaltCrypto",
71+
[string] $init="IV_Password"
72+
)
73+
5374
# Create a COM Object for RijndaelManaged Cryptography
5475
$r = new-Object System.Security.Cryptography.RijndaelManaged
5576
# Convert the Passphrase to UTF8 Bytes
@@ -63,33 +84,50 @@ function Decrypt-File($path, $Passphrase, $salt="SaltCrypto", $init="IV_Password
6384
$r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
6485

6586
$fs = [IO.File]::OpenRead($path)
66-
87+
6788
# Create a new Decryptor
6889
$d = $r.CreateDecryptor()
6990
# Create a New memory stream with the encrypted value.
70-
91+
7192
# Read the new memory stream and read it in the cryptology stream
7293
$cs = new-Object Security.Cryptography.CryptoStream $fs,$d,"Read"
7394
# Read the new decrypted stream
7495

7596
# Return from the function the stream
76-
97+
7798
$os = [IO.File]::Open($outputPath, [IO.FileMode]::Truncate, [IO.FileAccess]::Write);
7899
$cs.CopyTo($os);
79100

80101
$os.Close();
81102
# Stops the crypology stream
82103
$cs.Close()
83-
104+
84105
# Stops the memory stream
85106
$fs.Close()
86107
# Clears the RijndaelManaged Cryptology IV and Key
87108
$r.Clear()
88109
}
89110

90-
Decrypt-File `
91-
-path "C:\projects\jmespath-net\src\jmespath.net.snk.crypted" `
92-
-Passphrase $env:SNK_PASSPHRASE `
93-
-salt $env:SNK_SALT `
94-
-init $env:SNK_INIT `
95-
-outputPath "C:\projects\jmespath-net\src\jmespath.net.snk"
111+
$SRC_DIR = (Resolve-Path -Path (
112+
Join-Path -Path $PSScriptRoot -ChildPath "..")).Path
113+
114+
$STRONG_NAME_PLAINTEXT_KEY_PATH="$($SRC_DIR)/src/jmespath.net.snk"
115+
$STRONG_NAME_ENCRYPTED_KEY_PATH="$($SRC_DIR)/src/jmespath.net.snk.crypted"
116+
117+
if ($Encrypt.IsPresent) {
118+
Encrypt-File `
119+
-path $STRONG_NAME_PLAINTEXT_KEY_PATH `
120+
-Passphrase $env:SNK_PASSPHRASE `
121+
-salt $env:SNK_SALT `
122+
-init $env:SNK_INIT `
123+
-outputPath $STRONG_NAME_ENCRYPTED_KEY_PATH
124+
}
125+
126+
else {
127+
Decrypt-File `
128+
-path $STRONG_NAME_ENCRYPTED_KEY_PATH `
129+
-Passphrase $env:SNK_PASSPHRASE `
130+
-salt $env:SNK_SALT `
131+
-init $env:SNK_INIT `
132+
-outputPath $STRONG_NAME_PLAINTEXT_KEY_PATH
133+
}

bin/Update-Version.ps1

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,54 @@
11
[CmdletBinding()]
22
param(
33
[Parameter(Mandatory = $true)]
4-
$version = $ENV:appveyor_build_version
4+
[string]$version
55
)
66

77
BEGIN {
88

9-
if (-not $version -or [String]::IsNullOrWhitespace($version))
10-
{
11-
Write-Host "Please, specify a valid version number." -ForegroundColor Red
12-
throw;
13-
}
14-
15-
Function Get-ScriptDirectory { Split-Path -parent $PSCommandPath }
16-
Function Update-CsprojVersion {
17-
param([string]$path, [string]$version)
18-
[xml]$document = Get-Content -Path $path -Raw
19-
$newPrefix = $document.Project.PropertyGroup.VersionPrefix.Replace("42.43.44", $version)
20-
$document.Project.PropertyGroup.VersionPrefix = $newPrefix
21-
$document.Save($path)
22-
23-
Write-Host "Updated version of $path to $version." -ForegroundColor Cyan
24-
}
25-
Function Update-NuspecVersion {
26-
param([string]$path, [string]$version)
27-
[xml]$document = Get-Content -Path $path -Raw
28-
$newPrefix = $document.package.metadata.version.Replace("42.43.44", $version)
29-
$document.package.metadata.version = $newPrefix
30-
$document.Save($path)
31-
32-
Write-Host "Updated version of $path to $version." -ForegroundColor Cyan
33-
}
9+
if (-not $version -or [String]::IsNullOrWhitespace($version))
10+
{
11+
Write-Host "Please, specify a valid version number." -ForegroundColor Red
12+
throw;
13+
}
14+
15+
Function Update-CsprojVersion {
16+
param([string]$path, [string]$version)
17+
[xml]$document = Get-Content -Path $path -Raw
18+
$newPrefix = $document.Project.PropertyGroup.VersionPrefix.Replace("42.43.44", $version)
19+
$document.Project.PropertyGroup.VersionPrefix = $newPrefix
20+
$document.Save($path)
21+
22+
Write-Host "Updated version of $path to $version." -ForegroundColor Cyan
23+
}
24+
Function Update-NuspecVersion {
25+
param([string]$path, [string]$version)
26+
[xml]$document = Get-Content -Path $path -Raw
27+
$newPrefix = $document.package.metadata.version.Replace("42.43.44", $version)
28+
$document.package.metadata.version = $newPrefix
29+
$document.Save($path)
30+
31+
Write-Host "Updated version of $path to $version." -ForegroundColor Cyan
32+
}
3433
}
3534

3635
PROCESS {
3736

38-
"../src/jmespath.net/jmespath.net.csproj", `
39-
"../src/jmespath.net.parser/jmespath.net.parser.csproj" |% {
40-
41-
Update-CsprojVersion `
42-
-Version $version `
43-
(Join-Path `
44-
-Path (Get-ScriptDirectory) `
45-
-ChildPath $_ `
46-
)
47-
}
48-
49-
"../src/jmespath.net.parser/jmespath.net.parser.nuspec" |% {
50-
51-
Update-NuspecVersion `
52-
-Version $version `
53-
(Join-Path `
54-
-Path (Get-ScriptDirectory) `
55-
-ChildPath $_ `
56-
)
57-
}
58-
}
37+
$SRC_DIR = (Resolve-Path -Path (
38+
Join-Path -Path $PSScriptRoot -ChildPath "..")).Path
39+
40+
"$SRC_DIR/src/jmespath.net/jmespath.net.csproj", `
41+
"$SRC_DIR/src/jmespath.net.parser/jmespath.net.parser.csproj" |% {
42+
43+
Update-CsprojVersion `
44+
-Version $version `
45+
-Path $_
46+
}
47+
48+
"$SRC_DIR/src/jmespath.net.parser/jmespath.net.parser.nuspec" |% {
49+
50+
Update-NuspecVersion `
51+
-Version $version `
52+
-Path $_
53+
}
54+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
using System.Runtime.CompilerServices;
22

3+
#if DEBUG
34
[assembly: InternalsVisibleTo("jmespathnet.tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100055796df0ae0f975fabb3455d92c9edfef1e266fe66273a7f42c298406335fef71fdf99f46033f5f1e890fa2c6a5f230bfdd5832aa16eb45af02ad70ff716f97a51ff955abaaa2490da59ece7f2474dd43695c6bc8f1c82d1bb38f166fdfa7716e11291bda347bc8689d5435e68401a9ab5b4e8e49c1074173d21edf4fbda1b1")]
5+
#else
6+
[assembly: InternalsVisibleTo("jmespathnet.tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010055709b8bb177721db5eb5a9e7437bfa5f46251aef5dcf91f4a36a7dcb98e51a8ecf5a37284004fa6694f3471f5dfc82244c9672eb085cd65c7cb75d8251aa971a349d4641b492ca0963b74fd9878a5872d6ccbb7b7ceff82aa3687c240a70b4d5565c7cff5df0a12cdbde58e937320fb302b7ccedff72008f3bec0bee8384dc5")]
7+
#endif
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
using System.Runtime.CompilerServices;
22

3+
#if DEBUG
34
[assembly: InternalsVisibleTo("jmespathnet.tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100055796df0ae0f975fabb3455d92c9edfef1e266fe66273a7f42c298406335fef71fdf99f46033f5f1e890fa2c6a5f230bfdd5832aa16eb45af02ad70ff716f97a51ff955abaaa2490da59ece7f2474dd43695c6bc8f1c82d1bb38f166fdfa7716e11291bda347bc8689d5435e68401a9ab5b4e8e49c1074173d21edf4fbda1b1")]
5+
#else
6+
[assembly: InternalsVisibleTo("jmespathnet.tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010055709b8bb177721db5eb5a9e7437bfa5f46251aef5dcf91f4a36a7dcb98e51a8ecf5a37284004fa6694f3471f5dfc82244c9672eb085cd65c7cb75d8251aa971a349d4641b492ca0963b74fd9878a5872d6ccbb7b7ceff82aa3687c240a70b4d5565c7cff5df0a12cdbde58e937320fb302b7ccedff72008f3bec0bee8384dc5")]
7+
#endif

0 commit comments

Comments
 (0)