-
Notifications
You must be signed in to change notification settings - Fork 25
202 lines (169 loc) · 7.36 KB
/
check-update.yml
File metadata and controls
202 lines (169 loc) · 7.36 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Check PDFium Update
on:
schedule:
# 1st and 15th of each month at 08:00 UTC
- cron: '0 8 1,15 * *'
workflow_dispatch:
inputs:
force_update:
description: 'Force update even if version matches'
type: boolean
default: false
target_version:
description: 'Specific bblanchon version to target (e.g. 134.0.6996.0). Leave empty for latest.'
type: string
default: ''
revision:
description: 'Revision number for the NuGet package version (4th segment, e.g. 0 -> x.y.z.0, 1 -> x.y.z.1). Defaults to 0.'
type: string
default: '0'
permissions:
contents: write
jobs:
check-and-update:
runs-on: ubuntu-latest
steps:
- name: Detect upstream release
id: upstream
run: |
TARGET_VERSION="${{ github.event.inputs.target_version }}"
if [ -n "$TARGET_VERSION" ]; then
# Fetch all releases and find the one matching the requested version
PAGE=1
FOUND=false
while [ "$FOUND" = "false" ] && [ "$PAGE" -le 10 ]; do
RELEASES=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/bblanchon/pdfium-binaries/releases?per_page=30&page=$PAGE")
MATCH=$(echo "$RELEASES" | jq -r --arg v "$TARGET_VERSION" \
'.[] | select(.name | test($v)) | @json' | head -1)
if [ -n "$MATCH" ]; then
RELEASE_JSON="$MATCH"
FOUND=true
else
COUNT=$(echo "$RELEASES" | jq length)
if [ "$COUNT" -lt 30 ]; then break; fi
PAGE=$((PAGE + 1))
fi
done
if [ "$FOUND" = "false" ]; then
echo "::error::Could not find release matching version $TARGET_VERSION"
exit 1
fi
else
# Fetch latest release
RELEASE_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/bblanchon/pdfium-binaries/releases/latest)
fi
RELEASE_NAME=$(echo "$RELEASE_JSON" | jq -r '.name')
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id')
TAG_NAME=$(echo "$RELEASE_JSON" | jq -r '.tag_name')
# Extract version from name like "PDFium v134.0.6996.0" or "PDFium 134.0.6996.0"
UPSTREAM_VERSION=$(echo "$RELEASE_NAME" | grep -oP '\d+\.\d+\.\d+\.\d+')
if [ -z "$UPSTREAM_VERSION" ]; then
echo "::error::Could not parse version from release name: $RELEASE_NAME"
exit 1
fi
echo "version=$UPSTREAM_VERSION" >> "$GITHUB_OUTPUT"
echo "release_id=$RELEASE_ID" >> "$GITHUB_OUTPUT"
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "Upstream: $UPSTREAM_VERSION (release ID: $RELEASE_ID, tag: $TAG_NAME)"
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
ref: master
- name: Read current version
id: current
run: |
CURRENT_VERSION=$(grep -oP '(?<=<Version>).*(?=</Version>)' src/Directory.Build.props)
echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "Current version: $CURRENT_VERSION"
- name: Compare versions
id: compare
run: |
UPSTREAM="${{ steps.upstream.outputs.version }}"
CURRENT="${{ steps.current.outputs.version }}"
FORCE="${{ github.event.inputs.force_update }}"
REVISION="${{ github.event.inputs.revision || '0' }}"
if [ "$UPSTREAM" = "$CURRENT" ] && [ "$FORCE" != "true" ] && [ "$REVISION" = "0" ]; then
echo "No update needed. Upstream ($UPSTREAM) matches current ($CURRENT)."
echo "needs_update=false" >> "$GITHUB_OUTPUT"
else
echo "Update available: $CURRENT -> $UPSTREAM (force=$FORCE)"
echo "needs_update=true" >> "$GITHUB_OUTPUT"
fi
- name: Verify NuGet package exists
if: steps.compare.outputs.needs_update == 'true'
run: |
VERSION="${{ steps.upstream.outputs.version }}"
PACKAGE="bblanchon.PDFium.Win32"
URL="https://api.nuget.org/v3-flatcontainer/${PACKAGE,,}/index.json"
# NuGet normalizes versions by stripping trailing .0 (e.g. 146.0.7678.0 -> 146.0.7678)
NORMALIZED_VERSION=$(echo "$VERSION" | sed 's/\.0$//')
echo "Checking NuGet for $PACKAGE version $VERSION (normalized: $NORMALIZED_VERSION)..."
VERSIONS=$(curl -s "$URL" | jq -r '.versions[]')
if echo "$VERSIONS" | grep -qx "$VERSION\|$NORMALIZED_VERSION"; then
echo "$PACKAGE found on NuGet."
else
echo "::error::$PACKAGE $VERSION not found on NuGet. The upstream GitHub release may have been published before NuGet packages. Try again later."
exit 1
fi
- name: Install .NET
if: steps.compare.outputs.needs_update == 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.*
- name: Install native dependencies
if: steps.compare.outputs.needs_update == 'true'
run: sudo apt-get update && sudo apt-get install -y libc6-dev
- name: Build bindings generator
if: steps.compare.outputs.needs_update == 'true'
run: dotnet build src/PDFiumCoreBindingsGenerator/PDFiumCoreBindingsGenerator.csproj -c Release
- name: Generate bindings
if: steps.compare.outputs.needs_update == 'true'
run: |
REVISION="${{ github.event.inputs.revision || '0' }}"
dotnet src/PDFiumCoreBindingsGenerator/bin/Release/net8.0/PDFiumCoreBindingsGenerator.dll \
${{ steps.upstream.outputs.release_id }} true "$REVISION"
- name: Build PDFiumCore
if: steps.compare.outputs.needs_update == 'true'
run: |
dotnet build src/PDFiumCore -c Release
- name: Run tests
if: steps.compare.outputs.needs_update == 'true'
run: dotnet test src/PDFiumCore.Tests -c Release
- name: Pack
if: steps.compare.outputs.needs_update == 'true'
run: dotnet pack src/PDFiumCore -c Release -o ./artifacts
- name: Read package version
if: steps.compare.outputs.needs_update == 'true'
id: package
run: |
PKG_VERSION=$(grep -oP '(?<=<Version>).*(?=</Version>)' src/Directory.Build.props)
echo "version=$PKG_VERSION" >> "$GITHUB_OUTPUT"
echo "Package version: $PKG_VERSION"
- name: Commit, tag and push
if: steps.compare.outputs.needs_update == 'true'
run: |
VERSION="${{ steps.package.outputs.version }}"
TAG_NAME="${{ steps.upstream.outputs.tag_name }}"
TAG="v${VERSION}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "PDFium version v${VERSION} ${TAG_NAME} [master]"
git tag "$TAG"
git push origin master "$TAG"
- name: Create release
if: steps.compare.outputs.needs_update == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.package.outputs.version }}
name: "PDFiumCore v${{ steps.package.outputs.version }} Released"
files: |
artifacts/*.nupkg
artifacts/*.snupkg
- name: Push NuGet packages
if: steps.compare.outputs.needs_update == 'true'
run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.ORG_NUGET_AUTH_TOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate