-
-
Notifications
You must be signed in to change notification settings - Fork 0
215 lines (171 loc) · 6.32 KB
/
build-artifact.yml
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: "2022 smdn <smdn@smdn.jp>"
name: Build artifact libhighlight
on:
workflow_dispatch:
inputs:
os:
description: "The OS label which run the build on. (ex: ubuntu-22.04, ubuntu-20.04, macos-12)"
required: false
type: string
create-pr-merge-artifact-branch:
description: "If true, creates the Pull Request for merging branch which the built artifact has been commited."
type: boolean
default: true
verbose:
description: "If true, enables verbose output."
required: false
type: boolean
default: false
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
jobs:
setup:
name: Set up
runs-on: ubuntu-latest
outputs:
runs-ons: ${{ steps.runs-on-os-list.outputs.runs-ons }}
base-branch: ${{ steps.base-branch.outputs.base-branch }}
env:
RUNS_ON_OS_LIST_DEFAULT: "['ubuntu-22.04', 'ubuntu-20.04', 'macos-12']"
steps:
- name: Determine OS list which run the build on
id: runs-on-os-list
shell: pwsh
run: |
$verbose = '${{ inputs.verbose }}' -ieq 'true'
$os_list = $Env:RUNS_ON_OS_LIST_DEFAULT | ConvertFrom-Json
if ( ! [string]::IsNullOrEmpty( '${{ inputs.os }}' ) ) {
$os_list = "${{ inputs.os }}".Split(",", [System.StringSplitOptions]::TrimEntries -bor [System.StringSplitOptions]::RemoveEmptyEntries)
}
if ( $verbose ) {
foreach ($os in $os_list) {
"::notice::build runs on: ${os}"
}
}
"runs-ons=$($os_list | ConvertTo-Json -Compress)" >> $Env:GITHUB_OUTPUT
- name: Determine the base branch
id: base-branch
shell: pwsh
run: |
$verbose = '${{ inputs.verbose }}' -ieq 'true'
$base_branch = $Env:GITHUB_REF.Replace('refs/heads/', '')
"base-branch=${base_branch}" >> $Env:GITHUB_OUTPUT
if ( $verbose ) {
"::notice::base branch: ${base_branch}"
}
build-artifact:
name: Build artifact on ${{ matrix.os }}
needs: [setup]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ${{ fromJson(needs.setup.outputs.runs-ons) }}
steps:
- name: Determine target RID
id: target-rid
shell: pwsh
run: |
$verbose = '${{ inputs.verbose }}' -ieq 'true'
if ('${{ matrix.os }}' -eq 'ubuntu-22.04') {
$target_rid = 'ubuntu.22.04'
}
elseif ('${{ matrix.os }}' -eq 'ubuntu-20.04') {
$target_rid = 'ubuntu.20.04'
}
elseif ('${{ matrix.os }}' -eq 'macos-12') {
$target_rid = 'osx'
}
"rid=${target_rid}" >> $Env:GITHUB_OUTPUT
if ( $verbose ) {
"::notice::target RID: ${target_rid}"
}
- name: Checkout repository
uses: actions/checkout@v4.1.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git identity
shell: pwsh
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Install build dependencies
shell: pwsh
run: |
make install-buildtime-deps-${{ steps.target-rid.outputs.rid }} -f eng/dependencies/install-deps.mk
- name: Build artifact
id: artifact
shell: pwsh
run: |
$log_file = [System.IO.Path]::GetFullPath('artifact.log')
cd src/highlight/
make artifact -f artifact.mk *>&1 | Tee-Object -FilePath $log_file
if ( -not $? ) {
Write-Error "failed to 'make artifact'"
exit(1)
}
# The makefile above switches current branch to the new branch where the artifacts to be commited.
$artifact_branch = $(git rev-parse --abbrev-ref HEAD)
git push origin $artifact_branch
"artifact-branch=${artifact_branch}" >> $Env:GITHUB_OUTPUT
"artifact-log-file=${log_file}" >> $Env:GITHUB_OUTPUT
- name: Create pull request
if: ${{ inputs.create-pr-merge-artifact-branch }}
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$verbose = '${{ inputs.verbose }}' -ieq 'true'
$pr_title = "Add '${{ steps.target-rid.outputs.rid }}'-targeted artifact built on ${{ matrix.os }}"
$pr_body = New-Object System.Text.StringBuilder -ArgumentList 2048
[void]$pr_body.AppendFormat(
'Automatically generated by workflow [{0} #{1}]({2}).',
'${{ github.workflow }}',
'${{ github.run_number }}',
'${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
).AppendLine()
[void]$pr_body.AppendLine()
#
# artifact build log
#
$artifact_build_log_file = '${{ steps.artifact.outputs.artifact-log-file }}'
[void]$pr_body.AppendLine('# Build logs')
[void]$pr_body.AppendLine('```')
[void]$pr_body.AppendLine($(Get-Content -Path $artifact_build_log_file) -join "`n")
[void]$pr_body.AppendLine('```')
#
# files changed
#
$changes_file = [System.IO.Path]::GetFullPath('changes.diff')
git show > $changes_file
[void]$pr_body.AppendLine('# Changes')
[void]$pr_body.AppendLine('```diff')
[void]$pr_body.AppendLine($(Get-Content -Path $changes_file) -join "`n")
[void]$pr_body.AppendLine('```')
#
# create PR
#
$pr_body_file = [System.IO.Path]::GetFullPath('pr-body.md')
Out-File -FilePath $pr_body_file -Encoding utf8 -InputObject $pr_body.ToString()
$pr_create_options = @(
'--base', '${{ needs.setup.outputs.base-branch }}',
'--head', '${{ steps.artifact.outputs.artifact-branch }}',
'--assignee', '${{ github.repository_owner }}',
'--no-maintainer-edit',
'--title', $pr_title,
'--body-file', $pr_body_file
)
$pr_url = $(gh pr create $pr_create_options)
"::notice::Created pull request for ${pr_title}: ${pr_url}"
# remove temporary working files
Remove-Item -Path $pr_body_file
Remove-Item -Path $artifact_build_log_file
Remove-Item -Path $changes_file
# show uncommit changes
if ( $verbose ) {
git status
}