Skip to content

[3.0] Streamline native builds (and build native libs for 3.0) #14

[3.0] Streamline native builds (and build native libs for 3.0)

[3.0] Streamline native builds (and build native libs for 3.0) #14

Workflow file for this run

name: Native Builds
on:
pull_request:
types: [opened, edited, synchronize]
permissions:
pull-requests: write
env:
# A space-separated list of paths to native libraries to build.
NATIVE_LIBRARY_PATHS: "sources/SDL/Native"
# A space-separated list of submodule paths for each native library path. Use _ if a submodule is not used - this must
# match the number of spaces in NATIVE_LIBRARY_PATHS.
NATIVE_LIBRARY_SUBMODULE_PATHS: "eng/submodules/sdl"
# A space-separated list of shorthands to the native library paths that will build the native library for each native
# library path. This must match the number of spaces in NATIVE_LIBRARY_PATHS. If a shorthand builds multiple native
# binary paths, these will be deduplicated.
NATIVE_LIBRARY_SHORTHANDS: "SDL"
jobs:
prerequisites:
name: PR Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: parse
name: Determine which native libraries the user has asked to build, and where to look for changes.
run: ./workflow-stage1.sh
working-directory: eng/native/buildsystem
env:
PR_COMMENT: ${{ github.event.pull_request.body }}
- uses: dorny/paths-filter@v3
id: filter
name: Determine which natives need to be rebuilt.
with:
filters: ${{ steps.parse.outputs.workflow_filters }}
- name: Find a warning message from a previous run, if applicable.
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.number }}
comment-author: "github-actions[bot]"
body-includes: "Some of the native library builds modified in this PR were not referenced in the PR description."
- id: strat
name: Create the matrix strategy for the native builds.
run: ./workflow-stage2.sh
working-directory: eng/native/buildsystem
env:
NATIVE_LIBRARY_APPLICABLE_SHORTHANDS: ${{ join(fromJSON(steps.filter.outputs.changes), ' ') }}
NATIVE_LIBRARY_USER_REFERENCED_SHORTHANDS: ${{ steps.parse.outputs.targets_referenced }}
PR_EXISTING_NOTICE_ID: ${{ steps.fc.outputs.comment-id }}
- name: Write a comment if needed.
if: ${{ steps.strat.outputs.comment_to_write }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body: ${{ steps.strat.outputs.comment_to_write }}
edit-mode: replace
outputs:
matrix_strategy: ${{ steps.strat.outputs.matrix_strategy }}
targets_referenced: ${{ steps.parse.outputs.targets_referenced }}
build:
needs: [prerequisites]
strategy:
matrix:
flat: ${{ fromJSON(needs.prerequisites.outputs.matrix_strategy) }}
runs-on: ${{ (startsWith(matrix.flat.runtime, 'osx') || startsWith(matrix.flat.runtime, 'ios') || startsWith(matrix.flat.runtime, 'tvos')) && 'macos-latest' || startsWith(matrix.flat.runtime, 'win') && 'windows-latest' || 'ubuntu-latest' }}
name: ${{ matrix.flat.target }} / ${{ matrix.flat.runtime }}
steps:
- uses: actions/checkout@v3
- run: ${{ format('.{0}{1}', startsWith(matrix.flat.runtime, 'win') && '\' || '/', matrix.flat.exec) }}
working-directory: ${{ matrix.flat.dir }}
- uses: actions/upload-artifact@v4
with:
name: natives-${{ matrix.flat.target }}-${{ matrix.flat.runtime }}
path: |
${{ matrix.flat.dir }}/runtimes/${{ matrix.flat.runtime }}/**/*
${{ matrix.flat.dir}}/lib/*${{ matrix.flat.runtime }}*/**/*
commit:
name: Commit Binaries
needs: [prerequisites, build]
runs-on: ubuntu-latest
if: ${{ needs.prerequisites.outputs.targets_referenced }}
steps:
- name: Checkout PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr checkout ${{ github.event.pull_request.number }}
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
pattern: natives-*
merge-multiple: true
- name: Commit Artifacts
run: |
git config --local user.email "[email protected]"
git config --local user.name "The Silk.NET Automaton"
git add .
git commit -m "Update native binaries for ${{ github.sha }}"
git push