Skip to content

Commit 016f95a

Browse files
authored
Use unity-changeset package to scrape versions (#55)
* Use unity-changeset package to scrape versions
1 parent fe20df7 commit 016f95a

File tree

6 files changed

+989
-1206
lines changed

6 files changed

+989
-1206
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: install dependencies
5454
run: yarn && yarn --cwd ./functions
5555
- name: Deploy test to Firebase
56-
uses: w9jds/firebase-action@v13.10.2
56+
uses: w9jds/firebase-action@v13.25.0
5757
with:
5858
args: deploy --only functions:testFunction
5959
env:
@@ -63,7 +63,7 @@ jobs:
6363
run: curl -f -s -S -X POST https://testfunction-wbe4ukn6tq-ey.a.run.app
6464

6565
- name: Cleanup Firebase Test
66-
uses: w9jds/firebase-action@v13.10.2
66+
uses: w9jds/firebase-action@v13.25.0
6767
if: always()
6868
with:
6969
args: functions:delete testFunction --force
@@ -84,13 +84,13 @@ jobs:
8484
- name: install dependencies
8585
run: yarn && yarn --cwd ./functions
8686
- name: Deploy to Firebase
87-
uses: w9jds/firebase-action@v13.10.2
87+
uses: w9jds/firebase-action@v13.25.0
8888
with:
8989
args: deploy
9090
env:
9191
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}'
9292
- name: Cleanup Firebase Test
93-
uses: w9jds/firebase-action@v13.10.2
93+
uses: w9jds/firebase-action@v13.25.0
9494
if: always()
9595
with:
9696
args: functions:delete testFunction --force

functions/package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,31 @@
1616
},
1717
"main": "lib/index.js",
1818
"dependencies": {
19-
"@octokit/auth-app": "^6.1.1",
19+
"@octokit/auth-app": "^6.1.3",
2020
"@octokit/rest": "^20.1.1",
2121
"eris": "^0.17.2",
22-
"firebase-admin": "^12.1.1",
23-
"firebase-functions": "^5.0.1",
24-
"httpie": "^1.1.2",
25-
"jsdom": "^24.1.0",
22+
"firebase-admin": "^12.7.0",
23+
"firebase-functions": "^6.1.0",
24+
"graphql": "^16.9.0",
2625
"lodash": "^4.17.21",
2726
"node-fetch": "^2.7.0",
28-
"semver": "^7.6.2"
27+
"semver": "^7.6.3",
28+
"unity-changeset": "^2.3.0"
2929
},
3030
"devDependencies": {
3131
"@octokit/types": "^13.5.0",
32-
"@types/jsdom": "^21.1.7",
3332
"@types/lodash": "^4.17.4",
34-
"@types/node": "^20.14.0",
33+
"@types/node": "^22.9.0",
3534
"@types/node-fetch": "^2.6.11",
3635
"@types/semver": "^7.5.8",
37-
"@types/ws": "^8.5.10",
36+
"@types/ws": "^8.5.13",
3837
"@typescript-eslint/eslint-plugin": "^7.12.0",
3938
"@typescript-eslint/parser": "^7.12.0",
4039
"eslint": "^8.57.0",
4140
"eslint-plugin-import": "^2.29.1",
4241
"firebase-functions-test": "^3.3.0",
4342
"jest": "^29.7.0",
44-
"typescript": "^5.4.5"
43+
"typescript": "^5.6.3"
4544
},
4645
"private": true,
4746
"volta": {

functions/src/logic/ingestUnityVersions/scrapeVersions.ts

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
1-
import { getDocumentFromUrl } from '../utils/get-document-from-url';
21
import { EditorVersionInfo } from '../../model/editorVersionInfo';
2+
import { searchChangesets, SearchMode } from 'unity-changeset';
33

4-
const UNITY_ARCHIVE_URL = 'https://unity.com/releases/editor/archive';
5-
const unity_version_regex = /unityhub:\/\/(\d+)\.(\d+)\.(\d+[a-zA-Z]\d+)\/(\w+)/g;
4+
const unity_version_regex = /^(\d+)\.(\d+)\.(\d+)([a-zA-Z]+)(-?\d+)$/;
65

76
export const scrapeVersions = async (): Promise<EditorVersionInfo[]> => {
8-
const document = await getDocumentFromUrl(UNITY_ARCHIVE_URL);
7+
const unityVersions = await searchChangesets(SearchMode.Default);
98

10-
const scripts = document.querySelectorAll('script');
9+
if (unityVersions?.length > 0) {
10+
return unityVersions
11+
.map((unityVersion) => {
12+
const match = RegExp(unity_version_regex).exec(unityVersion.version);
13+
if (match) {
14+
const [_, major, minor, patch, lifecycle, build] = match;
1115

12-
const allVersions = new Map<string, EditorVersionInfo>();
13-
14-
for (const script of scripts) {
15-
if (script.textContent) {
16-
const matches = [...script.textContent.matchAll(unity_version_regex)];
17-
if (matches.length > 0) {
18-
const versions = matches
19-
.filter((match) => {
20-
// Filter out prerelease and unsupported versions
21-
const [_, major, minor, patch, changeSet] = match;
22-
return patch.includes('f') && Number(major) >= 2017;
23-
})
24-
.map((match) => {
25-
const [_, major, minor, patch, changeSet] = match;
26-
const version = `${major}.${minor}.${patch}`;
27-
if (!allVersions.has(version)) {
28-
return {
29-
version,
30-
changeSet,
31-
major: Number(major),
32-
minor: Number(minor),
33-
patch,
34-
};
35-
}
36-
37-
// Return null if version is not unique
16+
if (lifecycle !== 'f' || Number(major) < 2017) {
3817
return null;
39-
})
40-
.filter((version) => version !== null) as EditorVersionInfo[];
41-
42-
versions.forEach((it) => {
43-
allVersions.set(it.version, it);
44-
});
45-
}
46-
}
47-
}
48-
49-
if (allVersions.size > 0) {
50-
return Array.from(allVersions.values());
18+
}
19+
20+
return {
21+
version: unityVersion.version,
22+
changeSet: unityVersion.changeset,
23+
major: Number(major),
24+
minor: Number(minor),
25+
patch,
26+
} as EditorVersionInfo;
27+
}
28+
return null;
29+
})
30+
.filter((versionInfo): versionInfo is EditorVersionInfo => versionInfo !== null);
5131
}
5232

5333
throw new Error('No Unity versions found!');

functions/src/logic/utils/get-document-from-url.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)