Skip to content

Publish NuGet Package #46

Publish NuGet Package

Publish NuGet Package #46

name: Publish NuGet Package
on:
workflow_dispatch:
push:
tags:
- 'v*'
permissions:
contents: write
packages: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout Repository
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
# Step 2: Set up .NET
- name: Set Up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0'
# Step 3: Generate Version
- name: Generate Version
id: generate_version
run: |
major=1
minor=0
build=$(date +'%Y%m%d')
revision=$(date +'%H%M')
version="$major.$minor.$build.$revision"
echo "version=$version" >> $GITHUB_ENV
# Step 4: Prepare Files
- name: Prepare Files
run: |
mkdir -p Scripts-PowerShell
cp LICENSE README.md Scripts-PowerShell/
for dir in */ ; do
dir=${dir%/}
if [[ "$dir" != "Scripts-PowerShell" && "$dir" != ".github" ]]; then
mkdir -p Scripts-PowerShell/"$dir"
cp -r "$dir"/* Scripts-PowerShell/"$dir"/ || echo "Skipping $dir"
fi
done
# Step 5: Create Project File
- name: Create Project File
run: |
echo "Creating nuget.package.csproj..."
cat > nuget.package.csproj <<- EOF
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PackageId>Scripts-PowerShell</PackageId>
<Authors>Luiz Hamilton Silva</Authors>
<Company>Brazilianscriptguy</Company>
<Product>Scripts-PowerShell</Product>
<Description>
Comprehensive suite of PowerShell and VBScript tools automates Active Directory tasks, advances forensic analysis,
and simplifies script creation. Designed for managing Windows Servers and workstations, these tools ensure accuracy,
efficiency, scalability, and adaptability.
</Description>
<PackageTags>PowerShell;Automation;SysAdmin;ActiveDirectory;Forensics</PackageTags>
<RepositoryUrl>https://github.com/brazilianscriptguy/Windows-SysAdmin-ProSuite</RepositoryUrl>
<Version>${{ env.version }}</Version>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoBuild>true</NoBuild>
<PackageOutputPath>./artifacts</PackageOutputPath>
<NoWarn>NU5110;NU5111;NU5123</NoWarn>
</PropertyGroup>
<ItemGroup>
<Content Include="Scripts-PowerShell/**" PackagePath="content/" />
<Content Remove="Scripts-PowerShell/SysAdmin-Tools/GroupPolicyObjects-Templates/**" />
</ItemGroup>
</Project>
EOF
# Step 6: Build and Pack the NuGet Package
- name: Build and Pack
run: |
mkdir -p ./artifacts
dotnet pack nuget.package.csproj --configuration Release --output ./artifacts || exit 1
package_file=$(find ./artifacts -name "Scripts-PowerShell*.nupkg")
if [[ -z "$package_file" ]]; then
echo "Error: Package not found"
ls ./artifacts
exit 1
fi
echo "Package successfully created: $package_file"
# Step 7: Publish to GitHub Packages
- name: Publish to GitHub Packages
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
dotnet nuget push ./artifacts/Scripts-PowerShell*.nupkg --api-key $NUGET_AUTH_TOKEN --source "github" --skip-duplicate