Build artifact libhighlight #48
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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-14']" | |
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') { | |
# osx-x64 | |
$target_rid = 'osx' | |
} | |
elseif ('${{ matrix.os }}' -eq 'macos-14') { | |
# osx-arm64 | |
$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 | |
} |