Skip to content

Commit 4c8f129

Browse files
Merge pull request #11 from MtMath/fix/ci-permissions
fix(ci): misconfig permissions for GITHUB_TOKEN
2 parents 02c565b + 4636668 commit 4c8f129

File tree

4 files changed

+99
-82
lines changed

4 files changed

+99
-82
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ name: Build e release
66
jobs:
77
build:
88
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
issues: write
12+
pull-requests: write
913
steps:
1014
- uses: actions/checkout@v3
1115
- uses: actions/setup-node@v3
1216
with:
13-
node-version: '16.x'
14-
registry-url: 'https://registry.npmjs.org'
17+
node-version: "16.x"
18+
registry-url: "https://registry.npmjs.org"
1519
- run: npm i
1620
- run: npm run build
1721
- run: npm ci

src/modules/unity.ts

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { execa } from 'execa';
2-
import path from 'path';
3-
import process from 'process';
1+
import { execa } from "execa";
2+
import path from "path";
3+
import process from "process";
44

55
export type UnityInstallations = Record<string, string>;
66

@@ -10,62 +10,85 @@ const getUnityHubPath = () => {
1010
const programFiles = process.env.ProgramFiles || "C:/Program Files";
1111
return path.resolve(programFiles, "Unity Hub/Unity Hub.exe");
1212
}
13-
default: return "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
13+
default:
14+
return "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub";
1415
}
15-
}
16+
};
1617

1718
const parseUnityPath = (basePath: string) => {
1819
switch (process.platform) {
19-
case "win32": return basePath;
20-
default: return path.join(basePath, "/Contents/MacOS/Unity");
20+
case "win32":
21+
return basePath;
22+
default:
23+
return path.join(basePath, "/Contents/MacOS/Unity");
2124
}
22-
}
25+
};
2326

2427
const unityHubPath = getUnityHubPath();
2528

2629
export const getUnityInstallations = async (): Promise<UnityInstallations> => {
27-
const { stdout } = await execa(unityHubPath, "-- --headless editors -i".split(" "), { reject: false });
30+
const { stdout } = await execa(
31+
unityHubPath,
32+
"-- --headless editors -i".split(" "),
33+
{ reject: false }
34+
);
2835

2936
const isSuccess = stdout.includes(", installed at");
30-
if (!isSuccess) throw `Failed to execute command ${unityHubPath}. Consider create UnityHub env var`;
37+
if (!isSuccess)
38+
throw `Failed to execute command ${unityHubPath}. Consider create UnityHub env var`;
3139

3240
const lines = stdout.split(/\r\n|\n/);
3341
const installations: UnityInstallations = {};
3442

35-
lines.forEach(line => {
43+
lines.forEach((line) => {
3644
const [version, unityPath] = line
3745
.split(", installed at")
38-
.map(entry => entry.trim());
46+
.map((entry) => entry.trim());
3947

4048
if (!!version || !!path) installations[version] = parseUnityPath(unityPath);
4149
});
4250

43-
if (Object.keys(installations).length == 0) throw `No unity installations found at ${unityHubPath}.`;
51+
if (Object.keys(installations).length == 0)
52+
throw `No unity installations found at ${unityHubPath}.`;
4453

4554
return installations;
46-
}
55+
};
4756

4857
export const parseUnityVersion = (raw: string) => {
4958
const result = /^[0-9]+\.[0-9]+/gm.exec(raw);
50-
if (!result || result.length === 0) throw `Failed to parse unity version ${raw}`;
59+
if (!result || result.length === 0)
60+
throw `Failed to parse unity version ${raw}`;
5161

5262
return result[0];
53-
}
54-
55-
export const createUnityProject = async (unityPath: string, projectPath: string) => {
56-
await execa(unityPath, ["-quit", "-batchmode", "-createProject", projectPath]);
57-
}
58-
59-
export const openUnityProject = async (unityPath: string, projectPath: string) => {
60-
const subprocess = execa(unityPath, ["-projectPath", projectPath], {
61-
detached: true,
62-
cleanup: false,
63-
stdio: "ignore",
64-
});
63+
};
64+
65+
export const createUnityProject = async (
66+
unityPath: string,
67+
projectPath: string
68+
) => {
69+
await execa(unityPath, [
70+
"-quit",
71+
"-batchmode",
72+
"-createProject",
73+
projectPath,
74+
]);
75+
};
76+
77+
export const openUnityProject = async (
78+
unityPath: string,
79+
projectPath: string
80+
) => {
81+
const subprocess = execa(
82+
unityPath,
83+
["-projectPath", projectPath, "-useHub", "-hubIPC"],
84+
{
85+
detached: true,
86+
cleanup: false,
87+
stdio: "ignore",
88+
}
89+
);
6590

66-
// Waits for a short period of time before deeming the command successful
6791
await new Promise((resolve) => setTimeout(resolve, 2000));
6892

69-
// Disassociate the Unity process from the script process
7093
subprocess.unref();
71-
}
94+
};

templates/ci/.github/workflows/ci.yml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ name: CI
22
on:
33
push:
44
branches:
5-
- master
6-
5+
- master
6+
77
jobs:
88
semantic-release:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
12-
with:
13-
fetch-depth: 0
14-
- uses: actions/setup-node@v2
15-
with:
16-
node-version: 14
17-
- name: Semantic release
18-
id: semantic
19-
uses: cycjimmy/semantic-release-action@v3
20-
with:
21-
semantic_version: 17
22-
env:
23-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 16
17+
- name: Semantic release
18+
id: semantic
19+
uses: cycjimmy/semantic-release-action@v4
20+
with:
21+
semantic_version: 17
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2424
outputs:
2525
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
2626
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
@@ -29,26 +29,26 @@ jobs:
2929
needs: semantic-release
3030
runs-on: ubuntu-latest
3131
steps:
32-
- uses: actions/checkout@v3
33-
with:
34-
fetch-depth: 0
35-
- name: Create upm branch
36-
run: |
37-
git branch -d upm &> /dev/null || echo upm branch not found
38-
git subtree split -P "$PKG_ROOT" -b upm
39-
git checkout upm
40-
if [[ -d "Samples" ]]; then
41-
git mv Samples Samples~
42-
rm -f Samples.meta
43-
git config --global user.name 'github-bot'
44-
git config --global user.email '[email protected]'
45-
git commit -am "fix: Samples => Samples~"
46-
fi
47-
git push -f -u origin upm
48-
env:
49-
PKG_ROOT: Assets/Package
50-
- name: Create upm git tag
51-
if: needs.semantic-release.outputs.new_release_published == 'true'
52-
run: |
53-
git tag ${{ needs.semantic-release.outputs.new_release_version }} upm
54-
git push origin --tags
32+
- uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
- name: Create upm branch
36+
run: |
37+
git branch -d upm &> /dev/null || echo upm branch not found
38+
git subtree split -P "$PKG_ROOT" -b upm
39+
git checkout upm
40+
if [[ -d "Samples" ]]; then
41+
git mv Samples Samples~
42+
rm -f Samples.meta
43+
git config --global user.name 'github-bot'
44+
git config --global user.email '[email protected]'
45+
git commit -am "fix: Samples => Samples~"
46+
fi
47+
git push -f -u origin upm
48+
env:
49+
PKG_ROOT: Assets/Package
50+
- name: Create upm git tag
51+
if: needs.semantic-release.outputs.new_release_published == 'true'
52+
run: |
53+
git tag ${{ needs.semantic-release.outputs.new_release_version }} upm
54+
git push origin --tags

templates/ci/.releaserc.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
{
22
"tagFormat": "v${version}",
3+
"preset": "angular",
34
"plugins": [
4-
[
5-
"@semantic-release/commit-analyzer",
6-
{
7-
"preset": "angular"
8-
}
9-
],
5+
"@semantic-release/commit-analyzer",
106
"@semantic-release/release-notes-generator",
117
[
128
"@semantic-release/changelog",
13-
{
14-
"preset": "angular"
15-
}
16-
],
17-
[
18-
"@semantic-release/npm",
199
{
2010
"npmPublish": false,
2111
"pkgRoot": "Assets/Package"

0 commit comments

Comments
 (0)