forked from Romanitho/Winget-AutoUpdate
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathGitFlow_Make-Release-and-Sync-to-Dev.yml
More file actions
167 lines (150 loc) · 7.96 KB
/
Copy pathGitFlow_Make-Release-and-Sync-to-Dev.yml
File metadata and controls
167 lines (150 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# This workflow completes the GitFlow release process:
# - Triggers automatically when a PR from release/* or hotfix/* to main is merged
# - Extracts version number from branch name
# - Builds stable release artifacts (not nightly builds)
# - Creates GitHub release with download stats
# - Synchronizes develop branch with main to maintain GitFlow integrity
name: GitFlow | Make Release and resync to develop
on:
# Trigger when PRs to main are closed (merged or not)
pull_request:
types: [closed]
branches:
- main
permissions:
contents: write
pull-requests: read
jobs:
build:
name: Create Release
# Run only when PR is merged (not just closed) and source branch is release/* or hotfix/*
if: github.event.pull_request.merged == true && (startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix/'))
runs-on: windows-latest
outputs:
next_semver: ${{ steps.release_version.outputs.NextSemVer }}
steps:
# Step 1: Checkout the code from the main branch after merge
- name: Checkout code
uses: actions/checkout@v5
with:
token: ${{ secrets.GH_PAT_SYNC }}
lfs: "true"
fetch-depth: 0
# Step 2: Extract version from branch name and calculate build number
- name: Get final Release Version
id: release_version
shell: bash
run: |
# Extract version from branch name if it's a release branch
if [[ "${{ github.event.pull_request.head.ref }}" =~ ^release/ ]]; then
VERSION=$(echo "${{ github.event.pull_request.head.ref }}" | sed -E 's/^release\///')
echo "Version extracted from release branch: $VERSION"
else
# Fetch the latest stable version for hotfix
LATEST_TAG=$(git tag -l --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
echo "Latest stable version: $LATEST_TAG"
# Calculate the new hotfix version by incrementing patch number
IFS='.' read -r -a version_parts <<< "${LATEST_TAG/v/}"
PATCH=$((version_parts[2] + 1))
VERSION="${version_parts[0]}.${version_parts[1]}.$PATCH"
echo "Version generated for hotfix: $VERSION"
fi
# Get the commit count and apply modulo 65535 (MSI version component limit)
commit_count=$(git rev-list --count HEAD)
commit_count_mod=$((commit_count % 65535))
NEW_VERSION="$VERSION.$commit_count_mod"
echo "Final version: $NEW_VERSION"
echo "MsiVersion=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "NextSemVer=$VERSION" >> $GITHUB_OUTPUT
# Step 3: Build all project artifacts for the stable release
- name: Build project
id: build_project
shell: powershell
run: |
# Download and install Microsoft Deployment Toolkit
echo "### Get MDT from Microsoft ###"
wget https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi -UseBasicParsing -OutFile .\MicrosoftDeploymentToolkit_x64.msi
Start-Process .\MicrosoftDeploymentToolkit_x64.msi -ArgumentList "/quiet /norestart" -Wait
# Extract ServiceUI for elevated notifications
echo "### Copy ServiceUI.exe x64 to 'Sources\Winget-AutoUpdate' folder ###"
Copy-Item -Path "C:\Program Files\Microsoft Deployment Toolkit\Templates\Distribution\Tools\x64\ServiceUI.exe" -Destination ".\Sources\Winget-AutoUpdate\ServiceUI.exe" -Force
Get-Item .\Sources\Winget-AutoUpdate\*
# Install WiX tools for MSI creation
echo "### Install WiX ###"
dotnet new console
dotnet tool install --global wix --version 5.0.1
wix extension add WixToolset.UI.wixext/5.0.1 -g
wix extension add WixToolset.Util.wixext/5.0.1 -g
# Build MSI package with STABLE flag
echo "### Create WAU msi ###"
cd .\Sources\Wix\
wix build -src build.wxs -ext WixToolset.Util.wixext -ext WixToolset.UI.wixext -out ..\..\WAU.msi -arch x64 -d Version=${{ steps.release_version.outputs.MsiVersion }} -d NextSemVer=${{ steps.release_version.outputs.NextSemVer }} -d Comment="STABLE" -d PreRelease=0
cd ..\..
Get-Item .\WAU.msi
# Calculate MSI file hash for verification
echo "### Get MSI file SHA ###"
$MsiSHA = (Get-FileHash .\WAU.msi).hash
echo " - WAU.msi SHA256: $MsiSHA"
echo "msi_sha=$MsiSHA" >> $env:GITHUB_OUTPUT
# Package ADMX policy templates
echo "### Zip ADMX ###"
$admxPath = ".\Sources\Policies\ADMX\WAU.admx"
try {
(Get-Content $admxPath -Raw -ErrorAction Stop) -match 'revision="([\d\.]+)"' | Out-Null
$ADMXversion = $matches[1]
$admxZip = "WAU_ADMX_$($ADMXversion).zip"
}
catch {
Write-Host "Error getting WAU ADMX version!"
$admxZip = "WAU_ADMX.zip"
}
Compress-Archive -Path .\Sources\Policies\ADMX -DestinationPath .\$admxZip -Force
Get-Item .\*.zip
echo "admx_zip_name=$admxZip" >> $env:GITHUB_OUTPUT
# Calculate ADMX package hash for verification
echo "### Get ADMX zip SHA ###"
$ADMXSHA = (Get-FileHash .\$admxZip).hash
echo " - $admxZip SHA256: $ADMXSHA"
echo "admx_sha=$ADMXSHA" >> $env:GITHUB_OUTPUT
# Step 4: Create stable GitHub release with all artifacts
- name: Create release
uses: ncipollo/release-action@bcfe5470707e8832e12347755757cec0eb3c22af # v1.18.0
with:
tag: v${{ steps.release_version.outputs.NextSemVer }}
prerelease: false # This is a stable release
generateReleaseNotes: true
name: WAU ${{ steps.release_version.outputs.NextSemVer }}
artifacts: "WAU.msi,${{ steps.build_project.outputs.admx_zip_name }}"
body: |
## Files
|Files|Hash (SHA256)|Downloads|
|---|---|---|
|[WAU.msi](https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v${{ steps.release_version.outputs.NextSemVer }}/WAU.msi) (x64)|`${{ steps.build_project.outputs.msi_sha }}`|<picture></picture>|
|[${{ steps.build_project.outputs.admx_zip_name }}](https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v${{ steps.release_version.outputs.NextSemVer }}/${{ steps.build_project.outputs.admx_zip_name }})|`${{ steps.build_project.outputs.admx_sha }}`|<picture></picture>|
sync:
name: Sync develop with main
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT_SYNC }}
# Step 5: Configure Git for merge back to develop
- name: Configure Git
shell: bash
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
# Step 6: Sync develop with main to ensure all release changes are in the develop branch
- name: Sync develop with main
shell: bash
run: |
# Checkout develop branch
git checkout develop
git pull origin develop
# Merge main into develop with no fast-forward to preserve history
git merge --no-ff origin/main -m "Merge main into develop after the creation of release v${{ needs.build.outputs.next_semver }}"
# Push changes to develop branch
git push origin develop