forked from Romanitho/Winget-AutoUpdate
-
Notifications
You must be signed in to change notification settings - Fork 22
201 lines (174 loc) · 9.28 KB
/
Copy pathGitFlow_Nightly-builds.yml
File metadata and controls
201 lines (174 loc) · 9.28 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# This workflow creates nightly builds from the develop branch:
# - Checks for merged PRs since the last tag
# - Creates a pre-release version if changes are detected
# - Builds and packages the software
# - Creates GitHub release with artifacts
name: GitFlow | Nightly Builds
on:
# Automated nightly builds at midnight
schedule:
- cron: "0 0 * * *"
# Manual trigger for testing purposes
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: Create Nightly Build
runs-on: windows-latest
env:
# Define the branch as a variable
BRANCH: develop
steps:
# Step 1: Checkout the develop branch for nightly builds
- name: Checkout code
uses: actions/checkout@v5
with:
lfs: "true"
fetch-depth: 0
# Always checkout develop for nightly builds
ref: ${{ env.BRANCH }}
# Step 2: Verify if a new build is required by checking for merged PRs since last tag
- name: Check for merged PRs since last tag
id: check_prs
shell: powershell
run: |
# Get the latest release tag (any type)
$LATEST_TAG = git tag -l --sort=-version:refname | Select-Object -First 1
Write-Host "Latest release: $LATEST_TAG"
# Get all merged PRs since last tag (only merge commits from PRs)
$MERGED_PRS = git log --merges --grep="Merge pull request" --pretty=format:"%h %s" "$LATEST_TAG..develop"
# Count merges
$MERGE_COUNT = ($MERGED_PRS | Measure-Object).Count
if ($MERGE_COUNT -eq 0) {
Write-Host "No PRs merged to develop since last tag. Skipping build."
$BUILD_NEEDED = $false
}
else {
Write-Host "Merged PRs since last tag (develop):"
Write-Host $MERGED_PRS
if ($MERGE_COUNT -eq 1 -and $MERGED_PRS -match "Merge pull request #\d+ from .*/release/") {
Write-Host "Only change since last tag is a release PR merge. Skipping build."
$BUILD_NEEDED = $false
}
else {
$BUILD_NEEDED = $true
# Set release type for output (adapts to your previous logic if you need it)
if ($LATEST_TAG -like "*-*") {
$RELEASE_TYPE = "prerelease"
} else {
$RELEASE_TYPE = "preminor"
}
echo "RELEASE_TYPE=$RELEASE_TYPE" >> $env:GITHUB_OUTPUT
}
}
echo "BUILD_NEEDED=$BUILD_NEEDED" >> $env:GITHUB_OUTPUT
# Step 3: Generate new semantic version number
- name: Auto Increment Semver Action
uses: MCKanpolat/auto-semver-action@5003b8d37f4b03d95f15303ea10242cbf7c13141 # 2
if: steps.check_prs.outputs.BUILD_NEEDED == 'true'
id: versioning
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
incrementPerCommit: false
releaseType: ${{ steps.check_prs.outputs.RELEASE_TYPE }}
# Step 4: Format version numbers for different purposes (SemVer, MSI version)
- name: Format Semver (and MSI version)
if: steps.check_prs.outputs.BUILD_NEEDED == 'true'
id: format_version
shell: powershell
run: |
# Get version from previous step
$NextSemver = "${{ steps.versioning.outputs.version }}"
# Create MSI-compatible version (x.y.z.build)
$commit_count = (git rev-list --count HEAD)
$commit_count_mod = $commit_count % 65535 # MSI has a version limit
$MsiBase = $NextSemver.Split("-")[0] # Remove prerelease segment
$MsiVersion = "$MsiBase.$commit_count_mod"
# Format the release name based on trigger type
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
$ReleaseName = "WAU $NextSemver [Pre-release Build]"
$ReleaseBodyIntro = "This is a **pre-release build** created from the latest changes in the develop branch."
} else {
$ReleaseName = "WAU $NextSemver [Nightly Build]"
$ReleaseBodyIntro = "This is an **automated nightly build** created from the latest changes in the develop branch."
}
# Output all version information
echo "MSI version: $MsiVersion"
echo "Semver created: $NextSemver"
echo "Release name: $ReleaseName"
echo "Release body intro: $ReleaseBodyIntro"
echo "MsiVersion=$MsiVersion" >> $env:GITHUB_OUTPUT
echo "NextSemVer=$NextSemver" >> $env:GITHUB_OUTPUT
echo "ReleaseName=$ReleaseName" >> $env:GITHUB_OUTPUT
echo "ReleaseBodyIntro=$ReleaseBodyIntro" >> $env:GITHUB_OUTPUT
# Step 5: Build the project and generate artifacts
- name: Build project
if: steps.check_prs.outputs.BUILD_NEEDED == 'true'
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 version information
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.format_version.outputs.MsiVersion }} -d NextSemVer=${{ steps.format_version.outputs.NextSemVer }} -d Comment="${{ steps.format_version.outputs.ReleaseName }}" -d PreRelease=1
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 6: Create GitHub release with all artifacts
- name: Create release
uses: ncipollo/release-action@bcfe5470707e8832e12347755757cec0eb3c22af # v1.18.0
if: steps.check_prs.outputs.BUILD_NEEDED == 'true'
with:
tag: v${{ steps.format_version.outputs.NextSemVer }}
commit: ${{ env.BRANCH }}
prerelease: true
generateReleaseNotes: true
name: ${{ steps.format_version.outputs.ReleaseName }}
artifacts: "WAU.msi,${{ steps.build_project.outputs.admx_zip_name }}"
body: |
${{ steps.format_version.outputs.ReleaseBodyIntro }}
⚠️ **Warning**: This build may contain unstable features and is intended for testing purposes only.
## Files
|Files|Hash (SHA256)|Downloads|
|---|---|---|
|[WAU.msi](https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v${{ steps.format_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.format_version.outputs.NextSemVer }}/${{ steps.build_project.outputs.admx_zip_name }})|`${{ steps.build_project.outputs.admx_sha }}`|<picture></picture>|