-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (103 loc) · 4.45 KB
/
Copy pathcheck-vlc-update.yml
File metadata and controls
113 lines (103 loc) · 4.45 KB
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
name: Check VLC Headers
# Runs daily. Regenerates the P/Invoke bindings from the latest VLC headers and,
# if the generated interop file actually changed, derives a version from the VLC
# header macros (libvlc_version.h) as MAJOR.MINOR.REVISION-nightly.<UTC-date>,
# commits the regenerated bindings + bumped version, tags it, and invokes the
# reusable NuGet publish workflow.
#
# Detection is "regenerate-and-diff": it triggers on changes that affect the
# generated binding surface, ignoring header edits that don't (comments, etc.).
on:
schedule:
- cron: '0 3 * * *' # daily at 03:00 UTC
workflow_dispatch:
permissions:
contents: write
id-token: write # allows the reusable publish workflow to use trusted publishing (OIDC)
jobs:
check:
runs-on: windows-latest
outputs:
updated: ${{ steps.diff.outputs.updated }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
# Fetches the latest VLC include/vlc headers into tools/.vlc and regenerates
# src/LibVLCSharp.Core/Generated/LibVLC.Interop.g.cs via ClangSharp.
- name: Regenerate bindings from latest VLC headers
run: ./tools/generate.ps1
shell: pwsh
- name: Detect binding changes
id: diff
shell: pwsh
run: |
# .gitattributes (* text=auto) normalizes line endings, so this only
# reports real content changes, not CRLF/LF noise.
$changed = git status --porcelain -- src/LibVLCSharp.Core/Generated
if ($changed) {
Write-Host "Bindings changed:`n$changed"
"updated=true" >> $env:GITHUB_OUTPUT
} else {
Write-Host 'No binding changes; nothing to publish.'
"updated=false" >> $env:GITHUB_OUTPUT
}
- name: Derive version from VLC headers
id: version
if: steps.diff.outputs.updated == 'true'
shell: pwsh
run: |
$header = 'tools/.vlc/include/vlc/libvlc_version.h'
if (-not (Test-Path $header)) { throw "Not found: $header" }
$text = Get-Content $header -Raw
function Get-Macro([string]$name) {
# VLC headers write the macros as "# define LIBVLC_VERSION_MAJOR (4)"
# (note the space after '#'), so allow optional whitespace there.
if ($text -match "#\s*define\s+$name\s*\(?\s*(\d+)") { return [int]$Matches[1] }
throw "Macro $name not found in libvlc_version.h"
}
$major = Get-Macro 'LIBVLC_VERSION_MAJOR'
$minor = Get-Macro 'LIBVLC_VERSION_MINOR'
$rev = Get-Macro 'LIBVLC_VERSION_REVISION'
$stamp = (Get-Date).ToUniversalTime().ToString('yyyyMMddHHmm')
$version = "$major.$minor.$rev-nightly.$stamp"
Write-Host "Derived version: $version"
"version=$version" >> $env:GITHUB_OUTPUT
# Write the version into Directory.Build.props so the package picks it up.
$props = 'Directory.Build.props'
$content = Get-Content $props -Raw
$content = $content -replace '<Version>[^<]*</Version>', "<Version>$version</Version>"
Set-Content -Path $props -Value $content -NoNewline
- name: Commit, tag and push
if: steps.diff.outputs.updated == 'true'
shell: pwsh
run: |
$version = '${{ steps.version.outputs.version }}'
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add src/LibVLCSharp.Core/Generated Directory.Build.props
git commit -m "chore: regenerate bindings for updated VLC headers ($version)"
git tag "v$version"
git push origin "HEAD:${{ github.ref_name }}"
git push origin "v$version"
publish:
needs: check
if: needs.check.outputs.updated == 'true'
# Build & publish the just-tagged commit (the GITHUB_TOKEN that pushed the tag
# cannot trigger the tag-push workflow, so we invoke publish directly here and
# point it at the new tag).
# Trusted publishing needs id-token: write in the called workflow; grant it here.
permissions:
contents: read
id-token: write
uses: ./.github/workflows/nuget-publish.yml
with:
ref: v${{ needs.check.outputs.version }}