forked from mkaring/ConfuserEx
-
Notifications
You must be signed in to change notification settings - Fork 4
161 lines (141 loc) · 5.42 KB
/
Copy pathrelease.yml
File metadata and controls
161 lines (141 loc) · 5.42 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
name: release
# GitHub Actions minutes are limited, so releases are NOT cut automatically on
# every push to main. Instead:
# - Run this workflow manually (Actions tab -> release -> Run workflow) to build
# and publish a release from main on demand.
# - On the 1st of each month it checks main for commits since the last release
# tag and only spends the (expensive) Windows build when there are new changes.
#
# The check job runs on a cheap Ubuntu runner, so a monthly run with nothing new
# costs only a few seconds and publishes nothing.
on:
workflow_dispatch:
inputs:
force:
description: "Release even if there are no new commits since the last release tag"
type: boolean
default: false
schedule:
- cron: "0 6 1 * *" # 06:00 UTC on the 1st of every month
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
jobs:
check:
name: Check main for new commits
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.decide.outputs.should_release }}
steps:
- uses: actions/checkout@v5
with:
ref: main
fetch-depth: 0
fetch-tags: true
- name: Decide whether to release
id: decide
shell: bash
run: |
last_tag=$(git tag --list 'v*' --sort=-v:refname | head -n1)
if [ -z "$last_tag" ]; then
echo "No release tag found — treating as first release."
echo "should_release=true" >> "$GITHUB_OUTPUT"
exit 0
fi
behind=$(git rev-list "$last_tag"..HEAD --count)
echo "Last release: $last_tag — $behind new commit(s) on main since then."
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.force }}" = "true" ]; then
echo "Manual dispatch with force=true — releasing."
echo "should_release=true" >> "$GITHUB_OUTPUT"
elif [ "$behind" -gt 0 ]; then
echo "New commits present — releasing."
echo "should_release=true" >> "$GITHUB_OUTPUT"
else
echo "No new commits since $last_tag — skipping. (Use force=true to release anyway.)"
echo "should_release=false" >> "$GITHUB_OUTPUT"
fi
release:
name: Build and publish release
needs: check
if: needs.check.outputs.should_release == 'true'
runs-on: windows-2025
timeout-minutes: 15
permissions:
contents: write
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps:
- uses: actions/checkout@v5
with:
ref: main
fetch-depth: 0
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.vcxproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install nbgv
run: dotnet tool install -g nbgv
- name: Compute version
id: version
shell: pwsh
run: |
$ver = nbgv get-version -v NuGetPackageVersion
echo "VERSION=$ver" >> $env:GITHUB_OUTPUT
Write-Host "Version: $ver"
- name: Restore
run: msbuild Confuser2.sln -t:Restore -verbosity:minimal
- name: Build
run: msbuild Confuser2.sln -p:Configuration=Release -verbosity:minimal
- name: Package CLI
shell: pwsh
run: |
$src = 'Confuser.CLI/bin/Release/net10.0'
Get-ChildItem $src -Exclude '*.pdb','*.xml' | Compress-Archive -DestinationPath 'ConfuserEx-CLI.zip'
Write-Host "Created ConfuserEx-CLI.zip"
- name: Package GUI
shell: pwsh
run: |
$src = 'ConfuserEx/bin/Release/net10.0-windows'
Get-ChildItem $src -Exclude '*.pdb','*.xml' | Compress-Archive -DestinationPath 'ConfuserEx-GUI.zip'
Write-Host "Created ConfuserEx-GUI.zip"
- name: Package combined
shell: pwsh
run: |
$tmp = 'combined'
New-Item -ItemType Directory -Path $tmp -Force | Out-Null
Copy-Item 'Confuser.CLI/bin/Release/net10.0/*' $tmp -Exclude '*.pdb','*.xml' -Recurse
Copy-Item 'ConfuserEx/bin/Release/net10.0-windows/*' $tmp -Exclude '*.pdb','*.xml' -Recurse -Force
Get-ChildItem $tmp | Compress-Archive -DestinationPath 'ConfuserEx.zip'
Remove-Item $tmp -Recurse -Force
Write-Host "Created ConfuserEx.zip"
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create release tag
shell: bash
run: |
tag="v${{ steps.version.outputs.VERSION }}"
if git rev-parse "$tag" >/dev/null 2>&1; then
echo "Tag $tag already exists — skipping tag creation."
else
git tag -a "$tag" -m "Release ${{ steps.version.outputs.VERSION }}"
git push origin "$tag"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.VERSION }}
name: v${{ steps.version.outputs.VERSION }}
files: |
ConfuserEx-CLI.zip
ConfuserEx-GUI.zip
ConfuserEx.zip
Confuser.MSBuild.Tasks/bin/Release/*.nupkg