Skip to content

Publish NuGet Package #51

Publish NuGet Package

Publish NuGet Package #51

name: Publish NuGet Package
on:
workflow_dispatch:
push:
tags:
- 'v*'
permissions:
contents: write
packages: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Set Up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0'
- 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
- name: Prepare Files
run: |
echo "Preparing Scripts-PowerShell folder..."
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
echo "Prepared files:"
ls -R Scripts-PowerShell
- 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>
<None Include="Scripts-PowerShell/**" PackagePath="content/" />
<None Remove="Scripts-PowerShell/SysAdmin-Tools/GroupPolicyObjects-Templates/**" />
</ItemGroup>
</Project>
EOF
- name: Restore Dependencies
run: |
echo "Restoring NuGet packages..."
dotnet restore nuget.package.csproj || exit 1
- name: Build and Pack
run: |
echo "Packing the NuGet package..."
mkdir -p ./artifacts
dotnet pack nuget.package.csproj --configuration Release --output ./artifacts --no-build || exit 1
echo "Checking artifacts directory..."
ls ./artifacts
package_file=$(find ./artifacts -name "Scripts-PowerShell*.nupkg")
if [[ -z "$package_file" ]]; then
echo "Error: Package not found in ./artifacts"
exit 1
fi
echo "Package successfully created: $package_file"
- name: Publish to GitHub Packages
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Publishing package to GitHub Packages..."
dotnet nuget push ./artifacts/Scripts-PowerShell*.nupkg --api-key $NUGET_AUTH_TOKEN --source "github" --skip-duplicate