Skip to content

Commit 2843add

Browse files
authored
[gh-actions] publishing nuget package on release (#117)
* [gh-actions] publishing nuget package on release * Skip login to nuget.org if not triggerd by a tag * removed appveyor ci definition
1 parent 9e90cdd commit 2843add

6 files changed

Lines changed: 186 additions & 171 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
# Only push to NuGet if we're building a tag (optional)
60+
if: startsWith(github.ref, 'refs/tags/')
61+
uses: NuGet/login@v1
62+
id: login
63+
with:
64+
# Secret is your NuGet username, e.g. 'jmespath-community'
65+
user: ${{ secrets.NUGET_USER }}
66+
67+
- name: 📤 Push to NuGet
68+
# Only push to NuGet if we're building a tag (optional)
69+
if: startsWith(github.ref, 'refs/tags/')
70+
shell: pwsh
71+
# Loop through all the packages in the output folder and push them to
72+
# nuget.org, using the NUGET_API_KEY generated by the previous login step
73+
run: |
74+
Get-ChildItem src/ -Filter *.nupkg | ForEach-Object {
75+
dotnet nuget push $_.FullName `
76+
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" `
77+
--source https://api.nuget.org/v3/index.json
78+
}

appveyor.yml

Lines changed: 0 additions & 108 deletions
This file was deleted.

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+
}

0 commit comments

Comments
 (0)