-
-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (101 loc) · 4.07 KB
/
weekly-release.yml
File metadata and controls
117 lines (101 loc) · 4.07 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
name: Weekly Release
on:
schedule:
# Every Sunday at 03:00 UTC
- cron: "0 3 * * 0"
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if release is needed
id: gate
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
let latestTag = "";
try {
const latest = await github.rest.repos.getLatestRelease({ owner, repo });
latestTag = latest.data.tag_name;
core.info(`Latest release tag: ${latestTag}`);
core.setOutput("latest_tag", latestTag);
} catch (error) {
if (error.status === 404) {
core.info("No previous release found. A release will be created.");
core.setOutput("latest_tag", "");
core.setOutput("should_release", "true");
return;
}
throw error;
}
const compare = await github.rest.repos.compareCommitsWithBasehead({
owner,
repo,
basehead: `${latestTag}...${context.sha}`,
});
const aheadBy = compare.data.ahead_by || 0;
core.info(`Commits since ${latestTag}: ${aheadBy}`);
core.setOutput("should_release", aheadBy > 0 ? "true" : "false");
- name: Skip (no new commits)
if: steps.gate.outputs.should_release != 'true'
shell: pwsh
run: |
Write-Host "No commits since latest release tag '$env:LATEST_TAG'. Skipping build."
env:
LATEST_TAG: ${{ steps.gate.outputs.latest_tag }}
- name: Compute release metadata
if: steps.gate.outputs.should_release == 'true'
id: meta
shell: pwsh
run: |
$date = Get-Date -Format 'yyyyMMdd'
$sha = $env:GITHUB_SHA.Substring(0, 7)
$tag = "weekly-$date-$sha"
$name = "Weekly build $date ($sha)"
"tag=$tag" >> $env:GITHUB_OUTPUT
"name=$name" >> $env:GITHUB_OUTPUT
- name: Build binaries
if: steps.gate.outputs.should_release == 'true'
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$csc = "$env:windir\Microsoft.NET\Framework64\v4.0.30319\csc.exe"
if (-not (Test-Path $csc)) {
throw "csc.exe not found at: $csc"
}
& $csc /target:exe /out:GpdControl.exe GpdControl.cs
& $csc /target:winexe /out:GpdGui.exe /main:GpdGui.Program GpdGui.cs GpdControl.cs
- name: Package release assets
if: steps.gate.outputs.should_release == 'true'
id: package
shell: pwsh
run: |
$artifact = "gpd-win-controls-access-${{ steps.meta.outputs.tag }}.zip"
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (Test-Path $artifact) {
Remove-Item -Path $artifact -Force
}
$archive = [System.IO.Compression.ZipFile]::Open($artifact, [System.IO.Compression.ZipArchiveMode]::Create)
try {
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, "GpdControl.exe", "GpdControl.exe") | Out-Null
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, "GpdGui.exe", "GpdGui.exe") | Out-Null
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, "default_mappings.txt", "default_mappings.txt") | Out-Null
$archive.CreateEntry("profiles/") | Out-Null
} finally {
$archive.Dispose()
}
"artifact=$artifact" >> $env:GITHUB_OUTPUT
- name: Create GitHub release
if: steps.gate.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.meta.outputs.tag }}
name: ${{ steps.meta.outputs.name }}
generate_release_notes: true
files: ${{ steps.package.outputs.artifact }}
make_latest: true