Publish NuGet Package #53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish NuGet Package | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Checkout 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 for Packaging | |
| - name: Prepare Files | |
| run: | | |
| echo "Preparing Scripts-PowerShell directory..." | |
| 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: Restore Dependencies (Optional for Project Structure) | |
| - name: Restore Dependencies | |
| run: dotnet restore || echo "Skipping restore." | |
| # Step 6: Build and Pack NuGet Package | |
| - name: Build and Pack | |
| run: | | |
| echo "Packing the NuGet package..." | |
| mkdir -p ./artifacts | |
| dotnet pack nuget.package.csproj --configuration Release --output ./artifacts || 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" | |
| # Step 7: Publish Package 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 |