Skip to content

Commit 3379bc6

Browse files
authored
Merge pull request #4 from t3hn3rd/develop
Develop -> Master: Github Actions Github Actions: Auto Publish Module, Generate Release & Clear Camo Cache - `publish.yml` created to detect if a version change has occured, publish the module, generate a release & tag the master branch if so, and clear the camo cache. - Github action will only run on the master branch. - Icons created for the module. - Module & manifest added to subdirectory as is best practice. - Version incremented to 1.0.2
2 parents 0fa9647 + 22c4047 commit 3379bc6

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

.github/workflows/publish.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Publish PowerShell Module
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags-ignore:
8+
- 'v*'
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
validate-and-publish:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Install PowerShell
24+
run: |
25+
sudo apt update
26+
sudo apt install -y powershell
27+
28+
- name: Extract Module Version from Manifest
29+
id: get_version
30+
shell: pwsh
31+
run: |
32+
# Load the manifest
33+
$ManifestPath = "PSMultipartFormData/PSMultipartFormData.psd1"
34+
$ModuleData = Import-PowerShellDataFile -Path $ManifestPath
35+
$CurrentVersion = $ModuleData.ModuleVersion
36+
37+
# Fetch the latest tag (assuming tags follow the versioning scheme)
38+
git fetch --tags
39+
$LatestTag = (git tag --sort=-v:refname | Select-Object -First 1) -replace "^v", ""
40+
41+
# Compare versions
42+
Write-Host "Current Module Version: $CurrentVersion"
43+
Write-Host "Latest Git Tag: $LatestTag"
44+
45+
if (-not $LatestTag -or [version]$CurrentVersion -gt [version]$LatestTag) {
46+
Write-Host "✅ Version has been incremented, proceeding with publish..."
47+
echo "SHOULD_PUBLISH=true" >> $env:GITHUB_ENV
48+
echo "version=$CurrentVersion" >> $env:GITHUB_ENV
49+
} else {
50+
Write-Host "⚠️ Module version has not been incremented! Skipping publish..."
51+
echo "SHOULD_PUBLISH=false" >> $env:GITHUB_ENV
52+
}
53+
54+
- name: Publish Module to PSGallery
55+
if: env.SHOULD_PUBLISH == 'true'
56+
shell: pwsh
57+
env:
58+
PS_GALLERY_KEY: ${{ secrets.PS_GALLERY_KEY }}
59+
run: |
60+
if ($env:ACT -eq 'true') {
61+
Write-Host "✅ Would have published module to PSGallery."
62+
} else {
63+
Write-Host "⚙️ Publishing module to PSGallery..."
64+
$NuGetApiKey = "$($env:PS_GALLERY_KEY)"
65+
Publish-Module -Path PSMultipartFormData -NuGetApiKey $NuGetApiKey -Repository PSGallery
66+
Write-Host "✅ Module published to PSGallery."
67+
}
68+
69+
- name: Create Git Tag
70+
if: env.SHOULD_PUBLISH == 'true'
71+
env:
72+
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
73+
run: |
74+
if [ "$ACT" = "true" ]; then
75+
echo "✅ Would have created Git tag."
76+
else
77+
echo "🏷️ Creating Git tag..."
78+
DeployKey="$DEPLOY_KEY"
79+
80+
# Configure SSH for GitHub
81+
mkdir -p ~/.ssh
82+
echo "$DeployKey" > ~/.ssh/id_rsa
83+
chmod 600 ~/.ssh/id_rsa
84+
85+
# Disable host key checking
86+
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
87+
88+
# Setup Git User Config
89+
git config --global user.name "GitHub Actions"
90+
git config --global user.email "actions@github.com"
91+
92+
git remote set-url origin git@github.com:t3hn3rd/PSMultipartFormData.git
93+
94+
git tag "v$version"
95+
git push origin "v$version"
96+
echo "✅ Git tag created."
97+
fi
98+
99+
- name: Create GitHub Release
100+
if: env.SHOULD_PUBLISH == 'true'
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103+
run: |
104+
if [ "$ACT" = "true" ]; then
105+
echo "✅ Would have created GitHub release."
106+
else
107+
echo "📦 Creating GitHub release for v$version..."
108+
gh release create "v$version" \
109+
--repo "$GITHUB_REPOSITORY" \
110+
--title "PSMultipartFormData v$version" \
111+
--notes "🚀 Released PSMultipartFormData v$version" \
112+
--generate-notes
113+
echo "✅ GitHub release created."
114+
fi
115+
116+
- name: Skip Message (if not publishing)
117+
if: env.SHOULD_PUBLISH == 'false'
118+
run: echo "✅ No version change detected, skipping publish."
119+
120+
- name: Camo Purge
121+
uses: kevincobain2000/action-camo-purge@v1
8.35 KB
Binary file not shown.
File renamed without changes.

media/icon_256.png

19.6 KB
Loading

media/icon_512.png

43.3 KB
Loading

0 commit comments

Comments
 (0)