Merge pull request #4 from t3hn3rd/develop #1
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 PowerShell Module | |
| on: | |
| push: | |
| branches: | |
| - master | |
| tags-ignore: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| validate-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install PowerShell | |
| run: | | |
| sudo apt update | |
| sudo apt install -y powershell | |
| - name: Extract Module Version from Manifest | |
| id: get_version | |
| shell: pwsh | |
| run: | | |
| # Load the manifest | |
| $ManifestPath = "PSMultipartFormData/PSMultipartFormData.psd1" | |
| $ModuleData = Import-PowerShellDataFile -Path $ManifestPath | |
| $CurrentVersion = $ModuleData.ModuleVersion | |
| # Fetch the latest tag (assuming tags follow the versioning scheme) | |
| git fetch --tags | |
| $LatestTag = (git tag --sort=-v:refname | Select-Object -First 1) -replace "^v", "" | |
| # Compare versions | |
| Write-Host "Current Module Version: $CurrentVersion" | |
| Write-Host "Latest Git Tag: $LatestTag" | |
| if (-not $LatestTag -or [version]$CurrentVersion -gt [version]$LatestTag) { | |
| Write-Host "✅ Version has been incremented, proceeding with publish..." | |
| echo "SHOULD_PUBLISH=true" >> $env:GITHUB_ENV | |
| echo "version=$CurrentVersion" >> $env:GITHUB_ENV | |
| } else { | |
| Write-Host "⚠️ Module version has not been incremented! Skipping publish..." | |
| echo "SHOULD_PUBLISH=false" >> $env:GITHUB_ENV | |
| } | |
| - name: Publish Module to PSGallery | |
| if: env.SHOULD_PUBLISH == 'true' | |
| shell: pwsh | |
| env: | |
| PS_GALLERY_KEY: ${{ secrets.PS_GALLERY_KEY }} | |
| run: | | |
| if ($env:ACT -eq 'true') { | |
| Write-Host "✅ Would have published module to PSGallery." | |
| } else { | |
| Write-Host "⚙️ Publishing module to PSGallery..." | |
| $NuGetApiKey = "$($env:PS_GALLERY_KEY)" | |
| Publish-Module -Path PSMultipartFormData -NuGetApiKey $NuGetApiKey -Repository PSGallery | |
| Write-Host "✅ Module published to PSGallery." | |
| } | |
| - name: Create Git Tag | |
| if: env.SHOULD_PUBLISH == 'true' | |
| env: | |
| DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} | |
| run: | | |
| if [ "$ACT" = "true" ]; then | |
| echo "✅ Would have created Git tag." | |
| else | |
| echo "🏷️ Creating Git tag..." | |
| DeployKey="$DEPLOY_KEY" | |
| # Configure SSH for GitHub | |
| mkdir -p ~/.ssh | |
| echo "$DeployKey" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| # Disable host key checking | |
| echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config | |
| # Setup Git User Config | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "actions@github.com" | |
| git remote set-url origin git@github.com:t3hn3rd/PSMultipartFormData.git | |
| git tag "v$version" | |
| git push origin "v$version" | |
| echo "✅ Git tag created." | |
| fi | |
| - name: Create GitHub Release | |
| if: env.SHOULD_PUBLISH == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ "$ACT" = "true" ]; then | |
| echo "✅ Would have created GitHub release." | |
| else | |
| echo "📦 Creating GitHub release for v$version..." | |
| gh release create "v$version" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "PSMultipartFormData v$version" \ | |
| --notes "🚀 Released PSMultipartFormData v$version" \ | |
| --generate-notes | |
| echo "✅ GitHub release created." | |
| fi | |
| - name: Skip Message (if not publishing) | |
| if: env.SHOULD_PUBLISH == 'false' | |
| run: echo "✅ No version change detected, skipping publish." | |
| - name: Camo Purge | |
| uses: kevincobain2000/action-camo-purge@v1 |