|
| 1 | +name: Check VLC Headers |
| 2 | + |
| 3 | +# Runs daily. Regenerates the P/Invoke bindings from the latest VLC headers and, |
| 4 | +# if the generated interop file actually changed, derives a version from the VLC |
| 5 | +# header macros (libvlc_version.h) as MAJOR.MINOR.REVISION-nightly.<UTC-date>, |
| 6 | +# commits the regenerated bindings + bumped version, tags it, and invokes the |
| 7 | +# reusable NuGet publish workflow. |
| 8 | +# |
| 9 | +# Detection is "regenerate-and-diff": it triggers on changes that affect the |
| 10 | +# generated binding surface, ignoring header edits that don't (comments, etc.). |
| 11 | +on: |
| 12 | + schedule: |
| 13 | + - cron: '0 3 * * *' # daily at 03:00 UTC |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + id-token: write # allows the reusable publish workflow to use trusted publishing (OIDC) |
| 19 | + |
| 20 | +jobs: |
| 21 | + check: |
| 22 | + runs-on: windows-latest |
| 23 | + outputs: |
| 24 | + updated: ${{ steps.diff.outputs.updated }} |
| 25 | + version: ${{ steps.version.outputs.version }} |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Setup .NET |
| 33 | + uses: actions/setup-dotnet@v4 |
| 34 | + with: |
| 35 | + dotnet-version: | |
| 36 | + 8.0.x |
| 37 | + 9.0.x |
| 38 | +
|
| 39 | + # Fetches the latest VLC include/vlc headers into tools/.vlc and regenerates |
| 40 | + # src/LibVLCSharp.Core/Generated/LibVLC.Interop.g.cs via ClangSharp. |
| 41 | + - name: Regenerate bindings from latest VLC headers |
| 42 | + run: ./tools/generate.ps1 |
| 43 | + shell: pwsh |
| 44 | + |
| 45 | + - name: Detect binding changes |
| 46 | + id: diff |
| 47 | + shell: pwsh |
| 48 | + run: | |
| 49 | + # .gitattributes (* text=auto) normalizes line endings, so this only |
| 50 | + # reports real content changes, not CRLF/LF noise. |
| 51 | + $changed = git status --porcelain -- src/LibVLCSharp.Core/Generated |
| 52 | + if ($changed) { |
| 53 | + Write-Host "Bindings changed:`n$changed" |
| 54 | + "updated=true" >> $env:GITHUB_OUTPUT |
| 55 | + } else { |
| 56 | + Write-Host 'No binding changes; nothing to publish.' |
| 57 | + "updated=false" >> $env:GITHUB_OUTPUT |
| 58 | + } |
| 59 | +
|
| 60 | + - name: Derive version from VLC headers |
| 61 | + id: version |
| 62 | + if: steps.diff.outputs.updated == 'true' |
| 63 | + shell: pwsh |
| 64 | + run: | |
| 65 | + $header = 'tools/.vlc/include/vlc/libvlc_version.h' |
| 66 | + if (-not (Test-Path $header)) { throw "Not found: $header" } |
| 67 | + $text = Get-Content $header -Raw |
| 68 | + function Get-Macro([string]$name) { |
| 69 | + # VLC headers write the macros as "# define LIBVLC_VERSION_MAJOR (4)" |
| 70 | + # (note the space after '#'), so allow optional whitespace there. |
| 71 | + if ($text -match "#\s*define\s+$name\s*\(?\s*(\d+)") { return [int]$Matches[1] } |
| 72 | + throw "Macro $name not found in libvlc_version.h" |
| 73 | + } |
| 74 | + $major = Get-Macro 'LIBVLC_VERSION_MAJOR' |
| 75 | + $minor = Get-Macro 'LIBVLC_VERSION_MINOR' |
| 76 | + $rev = Get-Macro 'LIBVLC_VERSION_REVISION' |
| 77 | + $date = (Get-Date).ToUniversalTime().ToString('yyyyMMdd') |
| 78 | + $version = "$major.$minor.$rev-nightly.$date" |
| 79 | + Write-Host "Derived version: $version" |
| 80 | + "version=$version" >> $env:GITHUB_OUTPUT |
| 81 | +
|
| 82 | + # Write the version into Directory.Build.props so the package picks it up. |
| 83 | + $props = 'Directory.Build.props' |
| 84 | + $content = Get-Content $props -Raw |
| 85 | + $content = $content -replace '<Version>[^<]*</Version>', "<Version>$version</Version>" |
| 86 | + Set-Content -Path $props -Value $content -NoNewline |
| 87 | +
|
| 88 | + - name: Commit, tag and push |
| 89 | + if: steps.diff.outputs.updated == 'true' |
| 90 | + shell: pwsh |
| 91 | + run: | |
| 92 | + $version = '${{ steps.version.outputs.version }}' |
| 93 | + git config user.name 'github-actions[bot]' |
| 94 | + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 95 | + git add src/LibVLCSharp.Core/Generated Directory.Build.props |
| 96 | + git commit -m "chore: regenerate bindings for updated VLC headers ($version)" |
| 97 | + git tag "v$version" |
| 98 | + git push origin "HEAD:${{ github.ref_name }}" |
| 99 | + git push origin "v$version" |
| 100 | +
|
| 101 | + publish: |
| 102 | + needs: check |
| 103 | + if: needs.check.outputs.updated == 'true' |
| 104 | + # Build & publish the just-tagged commit (the GITHUB_TOKEN that pushed the tag |
| 105 | + # cannot trigger the tag-push workflow, so we invoke publish directly here and |
| 106 | + # point it at the new tag). |
| 107 | + # Trusted publishing needs id-token: write in the called workflow; grant it here. |
| 108 | + permissions: |
| 109 | + contents: read |
| 110 | + id-token: write |
| 111 | + uses: ./.github/workflows/nuget-publish.yml |
| 112 | + with: |
| 113 | + ref: v${{ needs.check.outputs.version }} |
0 commit comments