Skip to content

Commit bcb4f18

Browse files
Fix CI (#2)
1 parent ebbf523 commit bcb4f18

3 files changed

Lines changed: 175 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main, master ]
65
pull_request:
7-
branches: [ main, master ]
6+
workflow_dispatch:
87

98
jobs:
109
build-test-pack:
1110
runs-on: ubuntu-latest
1211

1312
steps:
1413
- name: Checkout
15-
uses: actions/checkout@v4
14+
uses: actions/checkout@v6
1615

1716
- name: Setup .NET
18-
uses: actions/setup-dotnet@v4
17+
uses: actions/setup-dotnet@v5
1918
with:
2019
dotnet-version: 10.0.x
2120

.github/workflows/release.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: Package version, for example 1.0.1
8+
required: true
9+
type: string
10+
prerelease:
11+
description: Mark GitHub Release as prerelease
12+
required: false
13+
default: false
14+
type: boolean
15+
release_notes:
16+
description: GitHub Release notes
17+
required: false
18+
default: ""
19+
type: string
20+
21+
concurrency:
22+
group: release-${{ inputs.version }}
23+
cancel-in-progress: false
24+
25+
jobs:
26+
build-pack:
27+
name: Build, test and pack
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v6
33+
34+
- name: Setup .NET
35+
uses: actions/setup-dotnet@v5
36+
with:
37+
dotnet-version: 10.0.x
38+
39+
- name: Restore
40+
run: dotnet restore OpenPort.Net.sln
41+
42+
- name: Build
43+
env:
44+
VERSION: ${{ inputs.version }}
45+
run: |
46+
package_version="${VERSION#v}"
47+
dotnet build OpenPort.Net.sln \
48+
--configuration Release \
49+
--no-restore \
50+
/p:Version="$package_version" \
51+
/p:PackageVersion="$package_version"
52+
53+
- name: Test
54+
run: dotnet test OpenPort.Net.sln --configuration Release --no-build --verbosity normal
55+
56+
- name: Pack
57+
env:
58+
VERSION: ${{ inputs.version }}
59+
run: |
60+
package_version="${VERSION#v}"
61+
dotnet pack OpenPort.Net/OpenPort.Net.csproj \
62+
--configuration Release \
63+
--no-build \
64+
--output artifacts \
65+
/p:Version="$package_version" \
66+
/p:PackageVersion="$package_version"
67+
68+
- name: Upload package artifact
69+
uses: actions/upload-artifact@v7
70+
with:
71+
name: nuget-package
72+
path: artifacts/*.nupkg
73+
if-no-files-found: error
74+
75+
publish-nuget:
76+
name: Publish to NuGet
77+
needs: build-pack
78+
runs-on: ubuntu-latest
79+
80+
steps:
81+
- name: Setup .NET
82+
uses: actions/setup-dotnet@v5
83+
with:
84+
dotnet-version: 10.0.x
85+
86+
- name: Download package artifact
87+
uses: actions/download-artifact@v7
88+
with:
89+
name: nuget-package
90+
path: artifacts
91+
92+
- name: Push package
93+
env:
94+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
95+
run: |
96+
if [ -z "$NUGET_API_KEY" ]; then
97+
echo "::error::Repository secret NUGET_API_KEY is not set."
98+
exit 1
99+
fi
100+
101+
dotnet nuget push artifacts/*.nupkg \
102+
--api-key "$NUGET_API_KEY" \
103+
--source https://api.nuget.org/v3/index.json \
104+
--skip-duplicate
105+
106+
github-release:
107+
name: Create GitHub Release
108+
needs: build-pack
109+
runs-on: ubuntu-latest
110+
permissions:
111+
contents: write
112+
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v6
116+
with:
117+
fetch-depth: 0
118+
119+
- name: Download package artifact
120+
uses: actions/download-artifact@v7
121+
with:
122+
name: nuget-package
123+
path: artifacts
124+
125+
- name: Create release
126+
env:
127+
GH_TOKEN: ${{ github.token }}
128+
VERSION: ${{ inputs.version }}
129+
PRERELEASE: ${{ inputs.prerelease }}
130+
RELEASE_NOTES: ${{ inputs.release_notes }}
131+
run: |
132+
package_version="${VERSION#v}"
133+
tag="v$package_version"
134+
135+
if ! git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1; then
136+
git config user.name "github-actions[bot]"
137+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
138+
git tag "$tag" "$GITHUB_SHA"
139+
git push origin "$tag"
140+
fi
141+
142+
notes="$RELEASE_NOTES"
143+
if [ -z "$notes" ]; then
144+
notes="OpenPort.Net $package_version"
145+
fi
146+
printf '%s\n' "$notes" > release-notes.md
147+
148+
prerelease_flag=""
149+
if [ "$PRERELEASE" = "true" ]; then
150+
prerelease_flag="--prerelease"
151+
fi
152+
153+
if gh release view "$tag" >/dev/null 2>&1; then
154+
gh release upload "$tag" artifacts/*.nupkg --clobber
155+
else
156+
gh release create "$tag" artifacts/*.nupkg \
157+
--title "OpenPort.Net $package_version" \
158+
--notes-file release-notes.md \
159+
$prerelease_flag
160+
fi

OpenPort.Net/Providers/UpnpIgdProvider.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,24 @@ public async Task<IReadOnlyList<PortMapping>> GetMappingsAsync(CancellationToken
303303

304304
private static Uri ResolveControlUri(Uri rootDeviceUri, string controlUrl)
305305
{
306-
if (Uri.TryCreate(controlUrl, UriKind.Absolute, out var absolute))
306+
if (Uri.TryCreate(controlUrl, UriKind.Absolute, out var absolute) && IsHttpUri(absolute))
307307
{
308308
return absolute;
309309
}
310310

311-
var baseUri = new Uri(rootDeviceUri.GetLeftPart(UriPartial.Authority));
312-
return new Uri(baseUri, controlUrl);
311+
var resolved = new Uri(rootDeviceUri, controlUrl);
312+
if (!IsHttpUri(resolved))
313+
{
314+
throw new UriFormatException($"Unsupported UPnP control URL scheme '{resolved.Scheme}'.");
315+
}
316+
317+
return resolved;
313318
}
314319

320+
private static bool IsHttpUri(Uri uri) =>
321+
string.Equals(uri.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) ||
322+
string.Equals(uri.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase);
323+
315324
private static IEnumerable<KeyValuePair<string, string>> BuildAddArguments(PortMapping mapping)
316325
{
317326
var internalAddress = mapping.InternalAddress?.ToString() ?? NetworkUtils.GetLocalAddressForGateway(NetworkUtils.GetDefaultGatewayAddress() ?? IPAddress.None)?.ToString() ?? "";

0 commit comments

Comments
 (0)