1+ name : Release wht.ps1
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths :
8+ - ' wht.ps1' # Only trigger if the script itself changes
9+
10+ permissions :
11+ contents : write
12+
13+ env :
14+ SCRIPT_NAME : " wht.ps1"
15+
16+ jobs :
17+ release :
18+ runs-on : ubuntu-latest
19+
20+ steps :
21+ - name : Checkout repository
22+ uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0
25+
26+ - name : Set up Git identity
27+ run : |
28+ git config --global user.name "${{ github.actor }}"
29+ git config --global user.email "${{ github.actor }}@users.noreply.github.com"
30+
31+ # Extract version from the specific script line: $scriptVersion = "x.x.x"
32+ - name : Extract version
33+ id : extract_version
34+ run : |
35+ NEW_VERSION=$(grep -Po '(?<=\$scriptVersion = ")([0-9]+\.[0-9]+\.[0-9]+)' ${{ env.SCRIPT_NAME }})
36+ echo "Detected version: $NEW_VERSION"
37+ echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
38+
39+ # Check if this version tag already exists to avoid errors/duplicates
40+ - name : Check if tag exists
41+ id : check_tag
42+ run : |
43+ if git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then
44+ echo "Tag v$NEW_VERSION already exists."
45+ echo "TAG_EXISTS=true" >> $GITHUB_ENV
46+ else
47+ echo "Tag v$NEW_VERSION does not exist. Proceeding with release."
48+ echo "TAG_EXISTS=false" >> $GITHUB_ENV
49+ fi
50+
51+ # Create the git tag and push it
52+ - name : Create and push tag
53+ if : env.TAG_EXISTS == 'false'
54+ run : |
55+ git tag -a "v$NEW_VERSION" -m "Release version $NEW_VERSION"
56+ git push origin "v$NEW_VERSION"
57+
58+ # Extract the .NOTES block for the release body
59+ - name : Extract release notes
60+ if : env.TAG_EXISTS == 'false'
61+ run : |
62+ RELEASE_NOTES=$(sed -n '/^.NOTES/,/^#>/p' ${{ env.SCRIPT_NAME }} | sed '1d;$d')
63+ echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
64+ echo "$RELEASE_NOTES" >> $GITHUB_ENV
65+ echo "EOF" >> $GITHUB_ENV
66+
67+ # Create the GitHub Release (No files attached, just the tag and notes)
68+ - name : Create Release
69+ if : env.TAG_EXISTS == 'false'
70+ uses : softprops/action-gh-release@v2
71+ env :
72+ GITHUB_TOKEN : ${{ secrets.PAT_GITHUB }}
73+ with :
74+ tag_name : v${{ env.NEW_VERSION }}
75+ name : Release v${{ env.NEW_VERSION }}
76+ body : ${{ env.RELEASE_NOTES }}
77+ draft : false
78+ prerelease : false
0 commit comments