Install the Android NDK before all steps that need it #2
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
# Uploads a toolchain release's binary size metrics to DataDog. | |
# | |
# To target a specific Swift Toolchain Release, run: | |
# | |
# $TOOLCHAIN_VERSION="..." | |
# gh workflow run "Release - Swift Toolchain Binary Sizes" ` | |
# -f toolchain_version=${TOOLCHAIN_VERSION} ` | |
# -R github.com/thebrowsercompany/swift-build ` | |
# | |
name: Release - Swift Toolchain Binary Sizes | |
on: | |
pull_request: | |
paths: | |
- .github/workflows/release-swift-toolchain-binary-sizes.yml | |
release: | |
types: [created, edited] | |
workflow_call: | |
inputs: | |
toolchain_version: | |
description: 'Use this swift toolchain release version' | |
required: false | |
type: string | |
default: '' | |
dry_run: | |
description: 'Whether to generate data but skip uploads.' | |
required: false | |
type: boolean | |
default: true | |
workflow_dispatch: | |
inputs: | |
toolchain_version: | |
description: 'Use this swift toolchain release version' | |
required: false | |
type: string | |
default: '' | |
dry_run: | |
description: 'Whether to generate data but skip uploads.' | |
required: false | |
type: boolean | |
default: true | |
env: | |
SOURCE_ROOT: ${{ github.workspace }}/source | |
BUILD_ROOT: ${{ github.workspace }}/build | |
jobs: | |
context: | |
runs-on: windows-latest | |
outputs: | |
matrix: ${{ steps.matrix.outputs.matrix }} | |
toolchain_version: ${{ steps.toolchain-version.outputs.toolchain_version }} | |
upload: ${{ steps.upload.outputs.upload }} | |
steps: | |
- id: matrix | |
run: | | |
$Matrix = @" | |
[ | |
{ | |
"arch": "amd64", | |
"os": "windows-latest", | |
"is_cirun": "false" | |
}, | |
{ | |
"arch": "arm64", | |
"os": "cirun-win11-23h2-pro-arm64-16-2024-05-17", | |
"is_cirun": "true" | |
} | |
] | |
"@ | |
# Cirun kill switch. | |
# Edit https://github.com/thebrowsercompany/swift-build/settings/variables/actions to override. | |
if ("${{ vars.USE_CIRUN }}" -eq "false") { | |
$Matrix="$Matrix" | jq '[ .[] | select(.is_cirun == "false") ]' | |
} | |
# Minify output so Github can parse it. | |
$Matrix=$Matrix | jq -c | |
echo "Generated matrix: $Matrix" | |
"matrix=$Matrix" | Out-File -Encoding utf8 -Append $env:GITHUB_OUTPUT | |
- name: Determine Swift toolchain version | |
id: toolchain-version | |
env: | |
# This version is arbitrarily chosen. | |
TEST_SWIFT_TOOLCHAIN_VERSION: "20240509.3" | |
run: | | |
if ( "${{ inputs.toolchain_version }}" ) { | |
$ToolchainVersion="${{ inputs.toolchain_version }}" | |
} elseif ( "${{ github.event_name == 'pull_request' }}" -eq "true" ) { | |
$ToolchainVersion="${{ env.TEST_SWIFT_TOOLCHAIN_VERSION }}" | |
} else { | |
$ToolchainVersion="${{ github.ref_name }}" | |
} | |
"toolchain_version=$ToolchainVersion" | Out-File -Encoding utf8 -Append $env:GITHUB_OUTPUT | |
binary_size_data: | |
name: Generate Swift toolchain binary size data | |
needs: [context] | |
permissions: | |
contents: read | |
# required to make OIDC work | |
id-token: write | |
env: | |
BLOATY_OPTIONS_FILE: ${{ github.workspace }}/bloaty.textproto | |
strategy: | |
matrix: | |
include: ${{ fromJson(needs.context.outputs.matrix) }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout swift-build | |
uses: actions/checkout@v4 | |
with: | |
show-progress: false | |
- name: Get service account credentials | |
# configure-aws-credentials v4.0.1 release | |
uses: thebrowsercompany/gha-aws-ssm-get-parameter@v1 | |
with: | |
aws-role-to-assume: ${{ secrets.SWIFT_TOOLCHAIN_UPLOADER_ROLE_ARN }} | |
aws-role-session-name: SwiftToolchainMetricsUploader | |
aws-ssm-parameter: "/shared/secrets/GITHUB_ACTIONS_BQ_DATA_UPLOAD" | |
save-to-filepath: ${{ github.workspace }}/.google_application_credentials | |
- name: Setup Google application default credentials | |
run: echo "GOOGLE_APPLICATION_CREDENTIALS=${{ github.workspace }}/.google_application_credentials" | Out-File -FilePath $env:GITHUB_ENV -Append | |
- name: Install Swift toolchain | |
uses: compnerd/gha-setup-swift@9955d596781e4dda7bc4ca61bd534be03660b698 # main | |
with: | |
github-repo: thebrowsercompany/swift-build | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
release-asset-name: installer-${{ matrix.arch }}.exe | |
release-tag-name: ${{ needs.context.outputs.toolchain_version }} | |
- name: Store Swift Toolchain root in environment variable | |
run: | | |
# Locate the toolchain installation <root> by walking up from | |
# '<root>/Toolchains/<toolchain-version>/usr/bin/swift.exe'. | |
$SwiftPath=$(Get-Command swift).Source | |
$SwiftInstallRoot=$(Resolve-Path -LiteralPath $SwiftPath\..\..\..\..\..) | |
echo "SWIFT_INSTALL_ROOT=${SwiftInstallRoot}" | Out-File -FilePath $env:GITHUB_ENV -Append | |
# For scripts/python/binary_sizes | |
- name: Install Python dependencies | |
run: | | |
pip install google-cloud-bigquery | |
pip install google-auth-oathlib | |
pip install pandas | |
- name: Setup VS Dev Env | |
uses: compnerd/gha-setup-vsdevenv@f1ba60d553a3216ce1b89abe0201213536bc7557 # main | |
with: | |
host_arch: ${{ matrix.arch }} | |
components: 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64;Microsoft.VisualStudio.Component.VC.Tools.ARM64' | |
arch: ${{ matrix.arch }} | |
- name: Run google/bloaty | |
uses: thebrowsercompany/gha-google-bloaty@4a6a22aac0c6aba05eacb41a34e6a3c02737f10c # main | |
with: | |
bloaty-version: 34f4a66559ad4938c1e629e9b5f54630b2b4d7b0 | |
bloaty-args: -w -n 0 -d inputfiles,segments -s file --csv | |
bloaty-input-files: | | |
${{ env.SWIFT_INSTALL_ROOT }}/**/*.dll | |
${{ env.SWIFT_INSTALL_ROOT }}/**/*.exe | |
bloaty-output-file: ${{ github.workspace }}/binary_sizes.csv | |
cache-bloaty: 'true' | |
# Normally the cache key includes `bloaty-version`. This ensures that | |
# all workflow runs for the same target arch use a single cache | |
# consuming minimal space. | |
cache-bloaty-key: google-bloaty-${{ matrix.arch }} | |
# Use MSVC (cl) for arm64 because: | |
# 1. g++ is the default and fails on our arm64 vms because the Windows SDK isn't old enough to | |
# support g++11 (required by google/bloaty -> google/re2). | |
# 2. clang-cl fails on google/bloaty -> protocolfbuffers/protobuf due to | |
# https://github.com/protocolbuffers/protobuf/issues/6503. | |
compiler: ${{ matrix.arch == 'arm64' && 'cl' || '' }} | |
- name: Generate BigQuery table data | |
run: | | |
Set-StrictMode -Version 1.0 | |
$CreationTime=(gh release view ${{ needs.context.outputs.toolchain_version }} --json createdAt --jq '.[]') | |
$Script="./scripts/python/binary_sizes/bigquery_generate_table_data.py" | |
python ${Script} ${{ github.workspace }}/binary_sizes.csv ${{ github.workspace }}/table_data.csv ` | |
--toolchain-version=${{ needs.context.outputs.toolchain_version }} ` | |
--toolchain-arch=${{ matrix.arch }} ` | |
--strip-inputfiles-prefix=${{ env.SWIFT_INSTALL_ROOT }} ` | |
--creation-time="$CreationTime" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Show BigQuery table data to upload | |
run: Get-Content -Path ${{ github.workspace }}/table_data.csv | |
- name: Upload to BigQuery | |
if: github.event_name != 'pull_request' && inputs.dry_run == false | |
continue-on-error: true | |
run: | | |
$Script="./scripts/python/binary_sizes/bigquery_load_csv.py" | |
python ${Script} ${{ github.workspace }}/table_data.csv | |
# TODO(thebrowsercompany/gha-aws-ssm-get-parameter/issues/1): Do this as a post-step in gha-aws-ssm-get-parameter. | |
- name: Cleanup credentials | |
run: Remove-Item ${{ github.workspace }}/.google_application_credentials |