Repository navigation
193 lines (173 loc) · 6.58 KB
/
Copy pathbuild.yml
File metadata and controls
193 lines (173 loc) · 6.58 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
name: Build
on:
workflow_call:
inputs:
source_sha:
required: true
type: string
build_type:
required: true
type: string
version_identifier:
required: false
type: string
default: ''
outputs:
semver:
value: ${{ jobs.Prepare.outputs.semver }}
tag:
value: ${{ jobs.Prepare.outputs.tag }}
application_name:
value: ${{ jobs.Prepare.outputs.application_name }}
jobs:
Prepare:
runs-on: ubuntu-latest
outputs:
semver: ${{ steps.prepare.outputs.semver }}
tag: ${{ steps.prepare.outputs.tag }}
application_name: ${{ steps.prepare.outputs.application_name }}
version_suffix: ${{ steps.prepare.outputs.version_suffix }}
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
ref: ${{ inputs.source_sha }}
- name: Prepare build version
id: prepare
uses: diffscope/catalogs/actions/nightly@main
with:
operation: prepare
source-sha: ${{ inputs.source_sha }}
build-type: ${{ inputs.build_type }}
version-identifier: ${{ inputs.version_identifier }}
Build:
needs: Prepare
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: read
env:
CGO_ENABLED: '1'
VERSION_SUFFIX: ${{ needs.Prepare.outputs.version_suffix }}
APPLICATION_SEMVER: ${{ needs.Prepare.outputs.semver }}
APPLICATION_NAME: ${{ needs.Prepare.outputs.application_name }}
ARTIFACT_PLATFORM: ${{ matrix.platform }}
ARTIFACT_ARCH: ${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: Linux
arch: amd64
- os: windows-latest
platform: Windows
arch: amd64
- os: macos-latest
platform: macOS
arch: arm64
defaults:
run:
shell: pwsh
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ inputs.source_sha }}
- name: Go setup
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Dependency download
run: go mod download
- name: MinGW configuration
if: runner.os == 'Windows'
run: |
$compiler = Get-Command gcc -ErrorAction Stop
"CC=$($compiler.Source)" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
& $compiler.Source --version
- name: Formatting validation
if: matrix.os == 'ubuntu-latest' # Formatting validation requires one platform.
run: |
$unformatted = gofmt -l .
if ($unformatted) {
Write-Error "The following Go files require gofmt formatting:"
$unformatted
exit 1
}
- name: Vet
run: go vet ./...
- name: Test
run: go test ./...
- name: Race detection
run: go test -race ./...
- name: Build
run: |
New-Item -ItemType Directory -Force dist | Out-Null
$ext = if ($env:RUNNER_OS -eq 'Windows') { '.exe' } else { '' }
$linkerFlags = "-compressdwarf=false -X github.com/diffscope/diffscope-package-manager/internal/buildinfo.Suffix=$env:VERSION_SUFFIX"
if ($IsWindows) {
# MinGW emits PE sections that its matching objcopy can split without rewriting Go's internal-linker layout.
$linkerFlags += ' -linkmode=external'
}
go build -v -ldflags $linkerFlags -o "dist/dspm$ext" ./cmd/dspm
- name: Separate debug symbols
run: |
$ext = if ($env:RUNNER_OS -eq 'Windows') { '.exe' } else { '' }
$escapedVersion = $env:APPLICATION_SEMVER -replace '[.\-+]', '_'
$artifactBase = "$($env:APPLICATION_NAME)_$($escapedVersion)_$($env:ARTIFACT_PLATFORM)_$($env:ARTIFACT_ARCH)"
$archivePath = "symbol-archives/$($artifactBase)_debug_symbols.7z"
& ./scripts/ci/Split-Debug-Symbols.ps1 `
-ExecutablePath "dist/dspm$ext" `
-SymbolsDir debug-symbols `
-ArchivePath $archivePath
"SYMBOLS_PATH=$archivePath" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
"SYMBOLS_ARTIFACT_NAME=$($artifactBase)_debug_symbols" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
- name: Validate stripped executable
run: |
$ext = if ($env:RUNNER_OS -eq 'Windows') { '.exe' } else { '' }
$versionOutput = & "./dist/dspm$ext" --json --version
if ($LASTEXITCODE -ne 0) {
throw 'The stripped executable could not report its version'
}
$version = $versionOutput | ConvertFrom-Json
if ($version.name -ne 'dspm' -or $version.version -ne $env:APPLICATION_SEMVER) {
throw 'The stripped executable version differs from the reserved version'
}
- name: Upload debug symbols
uses: actions/upload-artifact@v7
with:
name: ${{ env.SYMBOLS_ARTIFACT_NAME }}
path: ${{ env.SYMBOLS_PATH }}
if-no-files-found: error
overwrite: true
compression-level: 0
- name: Artifact upload
if: inputs.build_type == 'dev'
uses: actions/upload-artifact@v7
with:
name: dspm-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }}
path: dist/*
if-no-files-found: error
- name: Prepare nightly asset
if: inputs.build_type == 'nightly'
run: |
$expectedRunnerArch = if ($env:ARTIFACT_ARCH -eq 'amd64') { 'X64' } else { 'ARM64' }
if ($env:RUNNER_ARCH -ne $expectedRunnerArch) {
throw "Unexpected runner architecture: $env:RUNNER_ARCH"
}
$ext = if ($env:RUNNER_OS -eq 'Windows') { '.exe' } else { '' }
$escapedVersion = $env:APPLICATION_SEMVER -replace '[.\-+]', '_'
$assetName = "$($env:APPLICATION_NAME)_$($escapedVersion)_$($env:ARTIFACT_PLATFORM)_$($env:ARTIFACT_ARCH)_standalone$ext"
New-Item -ItemType Directory -Force release-assets | Out-Null
Copy-Item -LiteralPath "dist/dspm$ext" -Destination "release-assets/$assetName"
"ASSET_NAME=$assetName" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
- name: Nightly artifact upload
if: inputs.build_type == 'nightly'
uses: actions/upload-artifact@v7
with:
name: ${{ env.ASSET_NAME }}
path: release-assets/*
if-no-files-found: error
overwrite: true