Repository navigation
181 lines (163 loc) · 7.62 KB
/
Copy pathrelease.yml
File metadata and controls
181 lines (163 loc) · 7.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
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
# Creates the release assets when a release is published:
# 1. build: builds the AccUnit library and the MCP server from the release tag (build.yml)
# -> artifacts AccUnit-bin and AccUnit-McpServer
# 2. upload-library: attaches AccUnit.<version>.bin.zip and AccUnit.McpServer.<version>.zip to the release
# 3. build-access-add-in: builds the Access add-in (AccUnitLoader.accda) from access-add-in/source,
# loads the library files into the table usys_AppFiles and attaches
# AccUnitLoader.<add-in version>.Access.zip to the release
#
# Runner requirements for build-access-add-in: Windows, Microsoft Access (64 bit), PowerShell 7,
# GitHub CLI (gh). The runner workspace must not be below %TEMP%: Access does not run VBA there,
# even with the trusted location that msaccess-vcs-build sets for the build.
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
release-tag:
description: "Release tag to build"
required: true
upload:
description: "Upload the zip files to the release"
type: boolean
default: false
permissions:
contents: write
env:
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.release-tag }}
UPLOAD_TO_RELEASE: ${{ github.event_name == 'release' || inputs.upload }}
GH_TOKEN: ${{ github.token }}
jobs:
build:
uses: ./.github/workflows/build.yml
with:
ref: ${{ github.event.release.tag_name || inputs.release-tag }}
upload-library:
needs: build
if: github.event_name == 'release' || inputs.upload
runs-on: ubuntu-latest
steps:
- name: "Download library zip"
uses: actions/download-artifact@v8
with:
name: "AccUnit-bin"
path: build
- name: "Download MCP server zip"
uses: actions/download-artifact@v8
with:
name: "AccUnit-McpServer"
path: build
- name: "Upload library and MCP server zip to release"
run: gh release upload "$RELEASE_TAG" build/AccUnit.*.bin.zip build/AccUnit.McpServer.*.zip --repo "$GITHUB_REPOSITORY" --clobber
build-access-add-in:
needs: build
runs-on: [self-hosted, Windows, Office]
env:
LIB_DIR: ${{ github.workspace }}\build\lib
OUT_DIR: ${{ github.workspace }}\build\out
APP_CONFIG_FILE: ${{ github.workspace }}\build\app-config.json
steps:
- name: "Checkout"
uses: actions/checkout@v7
with:
ref: ${{ env.RELEASE_TAG }}
- name: "Download library zip"
uses: actions/download-artifact@v8
with:
name: "AccUnit-bin"
path: build/download
- name: "Extract AccUnit library files"
shell: pwsh
run: |
$downloadDir = Join-Path $env:GITHUB_WORKSPACE 'build\download'
New-Item -ItemType Directory -Force -Path $env:LIB_DIR | Out-Null
$zipFiles = @(Get-ChildItem -Path $downloadDir -Filter 'AccUnit.*.bin.zip')
if ($zipFiles.Count -ne 1) { throw "Expected exactly one AccUnit.*.bin.zip in artifact AccUnit-bin, found $($zipFiles.Count)" }
Expand-Archive -Path $zipFiles[0].FullName -DestinationPath $env:LIB_DIR -Force
Get-ChildItem -Path $env:LIB_DIR | Format-Table Name, Length
- name: "Disable DEVMODE for release build"
shell: pwsh
run: |
# absolute path: .NET file methods do not follow the PowerShell location
$vbeProjectFile = Join-Path $env:GITHUB_WORKSPACE 'access-add-in\source\vbe-project.json'
$content = [System.IO.File]::ReadAllText($vbeProjectFile)
if ($content -notmatch 'DEVMODE\s*=\s*1') { throw "DEVMODE = 1 not found in $vbeProjectFile" }
$content = $content -replace 'DEVMODE\s*=\s*1', 'DEVMODE = 0'
[System.IO.File]::WriteAllText($vbeProjectFile, $content, [System.Text.UTF8Encoding]::new($true))
- name: "Create app config (load files into usys_AppFiles)"
shell: pwsh
run: |
$iconFile = Join-Path $env:GITHUB_WORKSPACE 'access-add-in\resources\ACLib.ico'
$config = @{
Procedures = @(
@{ Name = 'ImportAccUnitFilesFromFolder'; Parameters = @($env:LIB_DIR) },
@{ Name = 'ImportAppIconFile'; Parameters = @($iconFile) }
)
}
$config | ConvertTo-Json -Depth 5 | Set-Content -Path $env:APP_CONFIG_FILE -Encoding utf8
Get-Content -Path $env:APP_CONFIG_FILE
- name: "Build AccUnitLoader.accda"
uses: AccessCodeLib/msaccess-vcs-build@v2.0.0
with:
source-dir: "access-add-in/source"
target-dir: "build/out"
app-config: ${{ env.APP_CONFIG_FILE }}
timeout-minutes: 10
- name: "Verify usys_AppFiles"
shell: pwsh
run: |
$expectedIds = @(
'AccUnit.tlb', 'AccUnit.dll', 'AccessCodeLib.Common.Tools.dll',
'AccessCodeLib.Common.VBIDETools.dll', 'AccUnit.VbeAddIn.dll',
'AccessCodeLib.Common.VbeUserControlHost.dll', 'AppIcon'
)
$addInFile = Join-Path $env:OUT_DIR 'AccUnitLoader.accda'
if (-not (Test-Path $addInFile)) { throw "Built add-in not found: $addInFile" }
# DAO through Access: DAO.DBEngine.120 is often not registered outside Click-to-Run Office
$access = New-Object -ComObject Access.Application
try {
$db = $access.DBEngine.OpenDatabase($addInFile, $false, $true)
$rs = $db.OpenRecordset('SELECT id, version FROM USys_AppFiles')
$foundIds = @()
while (-not $rs.EOF) {
$foundIds += $rs.Fields.Item('id').Value
Write-Host "$($rs.Fields.Item('id').Value) $($rs.Fields.Item('version').Value)"
$rs.MoveNext()
}
$rs.Close()
$db.Close()
}
finally {
$access.Quit()
[void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($access)
}
$missingIds = @($expectedIds | Where-Object { $foundIds -notcontains $_ })
if ($missingIds.Count -gt 0) { throw "Missing in usys_AppFiles: $($missingIds -join ', ')" }
- name: "Create add-in zip"
id: zip
shell: pwsh
run: |
$configFile = Join-Path $env:GITHUB_WORKSPACE 'access-add-in\source\modules\_config_Application.bas'
$match = Select-String -LiteralPath $configFile -Pattern 'APPLICATION_VERSION As String = "(\d+)\.(\d+)\.(\d{2})(\d{2})\.\d+"'
if (-not $match) { throw "APPLICATION_VERSION not found or not in format major.minor.PPCC.date in $configFile" }
$parts = $match.Matches[0].Groups
# Add-in version major.minor.PPCC.date -> zip name major.minor.patch.CC (as in earlier releases)
$version = '{0}.{1}.{2}.{3}' -f $parts[1].Value, $parts[2].Value, [int]$parts[3].Value, $parts[4].Value
$zipFile = Join-Path $env:GITHUB_WORKSPACE "build\AccUnitLoader.$version.Access.zip"
Compress-Archive -Path (Join-Path $env:OUT_DIR 'AccUnitLoader.accda'), 'access-add-in/AccUnitLoader_Install.vbs' -DestinationPath $zipFile -Force
"zip-file=$zipFile" >> $env:GITHUB_OUTPUT
- name: "Upload build artifact"
uses: actions/upload-artifact@v7
with:
name: "AccUnitLoader"
path: |
${{ steps.zip.outputs.zip-file }}
build/out/*.log
if-no-files-found: error
- name: "Upload add-in zip to release"
if: env.UPLOAD_TO_RELEASE == 'true'
shell: pwsh
run: |
gh release upload $env:RELEASE_TAG "${{ steps.zip.outputs.zip-file }}" --repo $env:GITHUB_REPOSITORY --clobber
if ($LASTEXITCODE -ne 0) { throw "Upload to release '$env:RELEASE_TAG' failed" }