-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (111 loc) · 4.62 KB
/
release.yml
File metadata and controls
132 lines (111 loc) · 4.62 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
name: Build Release Assets
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: write
jobs:
build-windows-assets:
runs-on: windows-latest
steps:
- name: Check out repository
uses: actions/checkout@v5
- name: Read app version
id: version
shell: pwsh
run: |
$match = Select-String -Path "npcjason_app/version.py" -Pattern 'APP_VERSION = "([^"]+)"'
if (-not $match) {
throw "Could not determine app version from npcjason_app/version.py"
}
$version = $match.Matches[0].Groups[1].Value
"app_version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install Python dependencies
shell: pwsh
run: |
python -m pip install --upgrade pip
python -m pip install ".[build]"
python -m pip check
- name: Run tests
shell: pwsh
run: python -m unittest discover -s tests -v
- name: Compile source files
shell: pwsh
run: python -m compileall npcjason_app tests npcjason.py
- name: Install Inno Setup
shell: pwsh
run: choco install innosetup --no-progress -y
- name: Generate icon
shell: pwsh
run: python generate_icon.py
- name: Build EXE
shell: pwsh
run: python -m PyInstaller npcjason.spec --clean --noconfirm
- name: Build installer
shell: pwsh
run: |
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" installer.iss
- name: Generate SHA256 checksums
shell: pwsh
run: |
$assets = @(
"dist\NPCJason.exe",
"NPCJason_Setup_${{ steps.version.outputs.app_version }}.exe"
)
$lines = foreach ($asset in $assets) {
$hash = Get-FileHash -Path $asset -Algorithm SHA256
"$($hash.Hash.ToLower()) $([System.IO.Path]::GetFileName($asset))"
}
Set-Content -Path release-sha256.txt -Value $lines
- name: Upload workflow artifacts
uses: actions/upload-artifact@v6
with:
name: NPCJason-${{ github.event.release.tag_name || github.ref_name }}
path: |
dist/NPCJason.exe
NPCJason_Setup_${{ steps.version.outputs.app_version }}.exe
release-sha256.txt
if-no-files-found: error
- name: Attach release assets
if: github.event_name == 'release'
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY_OWNER: ${{ github.repository_owner }}
REPOSITORY_NAME: ${{ github.event.repository.name }}
RELEASE_ID: ${{ github.event.release.id }}
run: |
$headers = @{
Accept = "application/vnd.github+json"
Authorization = "Bearer $env:GITHUB_TOKEN"
"X-GitHub-Api-Version" = "2022-11-28"
}
$assets = @(
@{ name = "NPCJason.exe"; path = "dist\NPCJason.exe" },
@{ name = "NPCJason_Setup_${{ steps.version.outputs.app_version }}.exe"; path = "NPCJason_Setup_${{ steps.version.outputs.app_version }}.exe" },
@{ name = "release-sha256.txt"; path = "release-sha256.txt" }
)
$assetsUrl = "https://api.github.com/repos/$env:REPOSITORY_OWNER/$env:REPOSITORY_NAME/releases/$env:RELEASE_ID/assets"
$existingAssets = Invoke-RestMethod -Method Get -Uri $assetsUrl -Headers $headers
foreach ($assetDefinition in $assets) {
foreach ($existing in @($existingAssets | Where-Object { $_.name -eq $assetDefinition.name })) {
$deleteUrl = "https://api.github.com/repos/$env:REPOSITORY_OWNER/$env:REPOSITORY_NAME/releases/assets/$($existing.id)"
Invoke-RestMethod -Method Delete -Uri $deleteUrl -Headers $headers | Out-Null
}
}
$uploadHeaders = @{
Accept = "application/vnd.github+json"
Authorization = "Bearer $env:GITHUB_TOKEN"
"X-GitHub-Api-Version" = "2022-11-28"
"Content-Type" = "application/octet-stream"
}
foreach ($assetDefinition in $assets) {
$encodedName = [uri]::EscapeDataString($assetDefinition.name)
$uploadUrl = "https://uploads.github.com/repos/$env:REPOSITORY_OWNER/$env:REPOSITORY_NAME/releases/$env:RELEASE_ID/assets?name=$encodedName"
Invoke-RestMethod -Method Post -Uri $uploadUrl -Headers $uploadHeaders -InFile $assetDefinition.path | Out-Null
}