Skip to content

Commit 77e3da9

Browse files
authored
Merge pull request #106 from endel/universal
Make NativeWebSocket Universal
2 parents e51e38a + 2ca8b40 commit 77e3da9

94 files changed

Lines changed: 8092 additions & 3225 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: NuGet Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
name: Build & Test
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v4
20+
with:
21+
dotnet-version: '8.0.x'
22+
23+
- name: Restore
24+
run: dotnet restore src/NativeWebSocket/NativeWebSocket.csproj
25+
26+
- name: Build
27+
run: dotnet build src/NativeWebSocket/NativeWebSocket.csproj -c Release --no-restore
28+
29+
publish:
30+
name: Publish to NuGet
31+
runs-on: ubuntu-latest
32+
needs: [build]
33+
# TODO: revert to: if: github.event_name == 'push' && github.ref == 'refs/heads/master'
34+
steps:
35+
- uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 2
38+
39+
- name: Setup .NET
40+
uses: actions/setup-dotnet@v4
41+
with:
42+
dotnet-version: '8.0.x'
43+
44+
- name: Check for version change
45+
id: version
46+
run: |
47+
CURRENT=$(grep '<Version>' src/NativeWebSocket/NativeWebSocket.csproj | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/')
48+
PREVIOUS=$(git show HEAD~1:src/NativeWebSocket/NativeWebSocket.csproj 2>/dev/null | grep '<Version>' | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/' || echo "")
49+
echo "current=$CURRENT" >> $GITHUB_OUTPUT
50+
echo "previous=$PREVIOUS" >> $GITHUB_OUTPUT
51+
if [ "$CURRENT" != "$PREVIOUS" ]; then
52+
echo "changed=true" >> $GITHUB_OUTPUT
53+
echo "Version changed: $PREVIOUS -> $CURRENT"
54+
else
55+
echo "changed=false" >> $GITHUB_OUTPUT
56+
echo "Version unchanged: $CURRENT"
57+
fi
58+
59+
- name: Pack NativeWebSocket
60+
# TODO: revert to: if: steps.version.outputs.changed == 'true'
61+
run: dotnet pack src/NativeWebSocket/NativeWebSocket.csproj -c Release -o packages/
62+
63+
- name: Pack NativeWebSocket.MonoGame
64+
# TODO: revert to: if: steps.version.outputs.changed == 'true'
65+
run: dotnet pack integrations/MonoGame/NativeWebSocket.MonoGame.csproj -c Release -o packages/
66+
67+
- name: Publish to NuGet
68+
# TODO: revert to: if: steps.version.outputs.changed == 'true'
69+
env:
70+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
71+
run: dotnet nuget push packages/*.nupkg --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
name: Unity UPM Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
checkSemver:
13+
name: Check for Semver Change
14+
runs-on: ubuntu-latest
15+
outputs:
16+
semver-updated: ${{ steps.check.outputs.changed }}
17+
steps:
18+
- name: Checkout Code
19+
uses: actions/checkout@v4
20+
- uses: EndBug/version-check@v1
21+
id: check
22+
with:
23+
file-name: integrations/Unity/package.json
24+
diff-search: true
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
- name: Log when changed
27+
if: steps.check.outputs.changed == 'true'
28+
run: 'echo "Version change found in commit ${{ steps.check.outputs.commit }}! New version: ${{ steps.check.outputs.version }} (${{ steps.check.outputs.type }})"'
29+
30+
updateUPM:
31+
name: Update UPM branch
32+
runs-on: ubuntu-latest
33+
needs: [checkSemver]
34+
if: needs.checkSemver.outputs.semver-updated == 'true'
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Assemble UPM package
39+
run: |
40+
mkdir -p upm-package/WebSocket
41+
42+
# Core library files (single source of truth)
43+
cp src/NativeWebSocket/IWebSocket.cs upm-package/WebSocket/
44+
cp src/NativeWebSocket/WebSocketTypes.cs upm-package/WebSocket/
45+
46+
# Wrap core WebSocket.cs with Unity conditional compilation guard
47+
{ echo '#if !UNITY_WEBGL || UNITY_EDITOR'; echo ''; cat src/NativeWebSocket/WebSocket.cs; echo ''; echo '#endif'; } > upm-package/WebSocket/WebSocket.cs
48+
49+
# Unity-specific files (WebGL platform support)
50+
cp integrations/Unity/WebSocketWebGL.cs upm-package/WebSocket/
51+
cp integrations/Unity/WebSocketFactoryWebGL.cs upm-package/WebSocket/
52+
cp integrations/Unity/WebSocket.jslib upm-package/WebSocket/
53+
cp integrations/Unity/WebSocket.jspre upm-package/WebSocket/
54+
cp integrations/Unity/colyseus.nativewebsocket.asmdef upm-package/WebSocket/
55+
56+
# Package metadata and samples
57+
cp integrations/Unity/package.json upm-package/
58+
cp -r integrations/Unity/Samples~ upm-package/
59+
60+
- name: Push package directory to subtree
61+
uses: s0/git-publish-subdir-action@develop
62+
env:
63+
REPO: self
64+
BRANCH: upm-2.0
65+
FOLDER: upm-package/
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
createPackage:
69+
name: Create Unity Package and Release
70+
runs-on: ubuntu-latest
71+
needs: [checkSemver]
72+
if: needs.checkSemver.outputs.semver-updated == 'true'
73+
steps:
74+
- name: Checkout Code
75+
uses: actions/checkout@v4
76+
77+
- name: Assemble package directory
78+
run: |
79+
mkdir -p upm-package/Assets/WebSocket
80+
81+
# Core library files
82+
cp src/NativeWebSocket/IWebSocket.cs upm-package/Assets/WebSocket/
83+
cp src/NativeWebSocket/WebSocketTypes.cs upm-package/Assets/WebSocket/
84+
85+
# Wrap core WebSocket.cs with Unity conditional compilation guard
86+
{ echo '#if !UNITY_WEBGL || UNITY_EDITOR'; echo ''; cat src/NativeWebSocket/WebSocket.cs; echo ''; echo '#endif'; } > upm-package/Assets/WebSocket/WebSocket.cs
87+
88+
# Unity-specific files
89+
cp integrations/Unity/WebSocketWebGL.cs upm-package/Assets/WebSocket/
90+
cp integrations/Unity/WebSocketFactoryWebGL.cs upm-package/Assets/WebSocket/
91+
cp integrations/Unity/WebSocket.jslib upm-package/Assets/WebSocket/
92+
cp integrations/Unity/WebSocket.jspre upm-package/Assets/WebSocket/
93+
cp integrations/Unity/colyseus.nativewebsocket.asmdef upm-package/Assets/WebSocket/
94+
95+
# Package metadata
96+
cp integrations/Unity/package.json upm-package/Assets/
97+
98+
- name: Generate .meta files
99+
run: |
100+
generate_meta() {
101+
local file="$1"
102+
local guid
103+
guid=$(echo -n "$file" | md5sum | cut -c1-32)
104+
local ext="${file##*.}"
105+
local meta="${file}.meta"
106+
107+
case "$ext" in
108+
cs)
109+
cat > "$meta" <<ENDMETA
110+
fileFormatVersion: 2
111+
guid: ${guid}
112+
MonoImporter:
113+
serializedVersion: 2
114+
defaultReferences: []
115+
executionOrder: 0
116+
icon: {instanceID: 0}
117+
ENDMETA
118+
;;
119+
jslib|jspre)
120+
cat > "$meta" <<ENDMETA
121+
fileFormatVersion: 2
122+
guid: ${guid}
123+
PluginImporter:
124+
serializedVersion: 2
125+
iconMap: {}
126+
executionOrder: {}
127+
defineConstraints: []
128+
isPreloaded: 0
129+
isOverridable: 0
130+
isExplicitlyReferenced: 0
131+
validateReferences: 1
132+
platformData:
133+
- first:
134+
Any:
135+
second:
136+
enabled: 1
137+
settings: {}
138+
userData:
139+
assetBundleName:
140+
assetBundleVariant:
141+
ENDMETA
142+
;;
143+
*)
144+
cat > "$meta" <<ENDMETA
145+
fileFormatVersion: 2
146+
guid: ${guid}
147+
DefaultImporter:
148+
externalObjects: {}
149+
userData:
150+
assetBundleName:
151+
assetBundleVariant:
152+
ENDMETA
153+
;;
154+
esac
155+
}
156+
157+
# Generate .meta for the WebSocket folder
158+
folder_guid=$(echo -n "Assets/WebSocket" | md5sum | cut -c1-32)
159+
cat > upm-package/Assets/WebSocket.meta <<ENDMETA
160+
fileFormatVersion: 2
161+
guid: ${folder_guid}
162+
folderAsset: yes
163+
DefaultImporter:
164+
externalObjects: {}
165+
userData:
166+
assetBundleName:
167+
assetBundleVariant:
168+
ENDMETA
169+
170+
# Generate .meta for package.json
171+
generate_meta "upm-package/Assets/package.json"
172+
173+
# Generate .meta for each file in WebSocket/
174+
for f in upm-package/Assets/WebSocket/*; do
175+
generate_meta "$f"
176+
done
177+
178+
- name: Gather meta files
179+
run: |
180+
cd upm-package
181+
find Assets -name '*.meta' > ../metaList
182+
cat ../metaList
183+
184+
- name: Extract Version
185+
id: version
186+
uses: notiz-dev/github-action-json-property@release
187+
with:
188+
path: 'integrations/Unity/package.json'
189+
prop_path: 'version'
190+
- run: echo ${{steps.version.outputs.prop}}
191+
192+
- name: Generate Unity Package
193+
id: build-package
194+
uses: pCYSl5EDgo/create-unitypackage@master
195+
with:
196+
package-path: 'NativeWebSocket.unitypackage'
197+
include-files: metaList
198+
project-folder: upm-package
199+
200+
- name: Upload Package
201+
uses: actions/upload-artifact@v4
202+
with:
203+
path: ./NativeWebSocket.unitypackage
204+
name: NativeWebSocket
205+
206+
- name: Changelog
207+
uses: scottbrenner/generate-changelog-action@master
208+
id: Changelog
209+
210+
- name: Create Release
211+
id: create_release
212+
uses: actions/create-release@v1
213+
env:
214+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
215+
with:
216+
tag_name: ${{ steps.version.outputs.prop }}
217+
release_name: ${{ steps.version.outputs.prop }}
218+
body: |
219+
${{ steps.Changelog.outputs.changelog }}
220+
draft: false
221+
prerelease: true
222+
223+
- name: Upload Release Asset
224+
id: upload-release-asset
225+
uses: actions/upload-release-asset@v1
226+
env:
227+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
228+
with:
229+
upload_url: ${{ steps.create_release.outputs.upload_url }}
230+
asset_path: ./NativeWebSocket.unitypackage
231+
asset_name: NativeWebSocket.unitypackage
232+
asset_content_type: application/x-gzip

0 commit comments

Comments
 (0)