Skip to content

Commit 27ee149

Browse files
NeKzorThisAMJ
authored andcommitted
fix: slow upload step
1 parent d061342 commit 27ee149

3 files changed

Lines changed: 74 additions & 62 deletions

File tree

.github/workflows/CD.yml

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,12 @@ jobs:
3232
if: github.repository_owner == 'p2sr'
3333
env:
3434
DL_SAR_API_TOKEN: ${{ secrets.DL_SAR_API_TOKEN }}
35-
run: |
36-
SAR_VERSION=$(git describe --tags)
37-
curl -X "POST" \
38-
-H "Authorization: Bearer $DL_SAR_API_TOKEN" \
39-
-H "Content-Type: multipart/form-data" \
40-
-F "version=$(echo $SAR_VERSION | awk -F- '{print $1}')" \
41-
-F "sar_version=$SAR_VERSION" \
42-
-F "system=linux" \
43-
-F "commit=$GITHUB_SHA" \
44-
-F "branch=$GITHUB_REF_NAME" \
45-
-F "count=1" \
46-
-F "hashes[0]=$(sha256sum sar.so | cut -d ' ' -f 1)" \
47-
-F "files[0]=@sar.so" \
48-
"https://dl.sar.portal2.sr/api/v1/upload"
35+
RELEASE_BUILD: 1
36+
uses: actions/github-script@v7
37+
with:
38+
script: |
39+
const script = require('./.github/workflows/canary.js');
40+
return await script({ github, context, core });
4941
build-win:
5042
name: Windows Build
5143
runs-on: windows-2019
@@ -77,25 +69,14 @@ jobs:
7769
if-no-files-found: error
7870
- name: Upload to dl.sar.portal2.sr
7971
if: github.repository_owner == 'p2sr'
80-
shell: bash
8172
env:
8273
DL_SAR_API_TOKEN: ${{ secrets.DL_SAR_API_TOKEN }}
83-
run: |
84-
SAR_VERSION=$(git describe --tags)
85-
curl -X "POST" \
86-
-H "Authorization: Bearer $DL_SAR_API_TOKEN" \
87-
-H "Content-Type: multipart/form-data" \
88-
-F "version=$(echo $SAR_VERSION | awk -F- '{print $1}')" \
89-
-F "sar_version=$SAR_VERSION" \
90-
-F "system=windows" \
91-
-F "commit=$GITHUB_SHA" \
92-
-F "branch=$GITHUB_REF_NAME" \
93-
-F "count=2" \
94-
-F "hashes[0]=$(sha256sum bin/sar.dll | cut -d ' ' -f 1)" \
95-
-F "hashes[1]=$(sha256sum bin/sar.pdb | cut -d ' ' -f 1)" \
96-
-F "files[0]=@bin/sar.dll" \
97-
-F "files[1]=@bin/sar.pdb" \
98-
"https://dl.sar.portal2.sr/api/v1/upload"
74+
RELEASE_BUILD: 1
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
const script = require('./.github/workflows/canary.js');
79+
return await script({ github, context, core });
9980
release:
10081
name: Release
10182
if: github.repository == 'p2sr/SourceAutoRecord'

.github/workflows/CI.yml

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,12 @@ jobs:
4343
if: github.ref == 'refs/heads/master' && github.repository_owner == 'p2sr'
4444
env:
4545
DL_SAR_API_TOKEN: ${{ secrets.DL_SAR_API_TOKEN }}
46-
run: |
47-
SAR_VERSION=$(git describe --tags)
48-
curl -X "POST" \
49-
-H "Authorization: Bearer $DL_SAR_API_TOKEN" \
50-
-H "Content-Type: multipart/form-data" \
51-
-F "version=$(echo $SAR_VERSION | awk -F- '{print $1}')-canary" \
52-
-F "sar_version=$SAR_VERSION-canary" \
53-
-F "system=linux" \
54-
-F "commit=$GITHUB_SHA" \
55-
-F "branch=$GITHUB_REF_NAME" \
56-
-F "count=1" \
57-
-F "hashes[0]=$(sha256sum sar.so | cut -d ' ' -f 1)" \
58-
-F "files[0]=@sar.so" \
59-
"https://dl.sar.portal2.sr/api/v1/upload"
46+
RELEASE_BUILD: 0
47+
uses: actions/github-script@v7
48+
with:
49+
script: |
50+
const script = require('./.github/workflows/canary.js');
51+
console.log(await script({ github, context, core }));
6052
6153
build-win:
6254
name: Windows Build
@@ -84,22 +76,11 @@ jobs:
8476
if-no-files-found: error
8577
- name: Upload to dl.sar.portal2.sr
8678
if: github.ref == 'refs/heads/master' && github.repository_owner == 'p2sr'
87-
shell: bash
8879
env:
8980
DL_SAR_API_TOKEN: ${{ secrets.DL_SAR_API_TOKEN }}
90-
run: |
91-
SAR_VERSION=$(git describe --tags)
92-
curl -X "POST" \
93-
-H "Authorization: Bearer $DL_SAR_API_TOKEN" \
94-
-H "Content-Type: multipart/form-data" \
95-
-F "version=$(echo $SAR_VERSION | awk -F- '{print $1}')-canary" \
96-
-F "sar_version=$SAR_VERSION-canary" \
97-
-F "system=windows" \
98-
-F "commit=$GITHUB_SHA" \
99-
-F "branch=$GITHUB_REF_NAME" \
100-
-F "count=2" \
101-
-F "hashes[0]=$(sha256sum bin/sar.dll | cut -d ' ' -f 1)" \
102-
-F "hashes[1]=$(sha256sum bin/sar.pdb | cut -d ' ' -f 1)" \
103-
-F "files[0]=@bin/sar.dll" \
104-
-F "files[1]=@bin/sar.pdb" \
105-
"https://dl.sar.portal2.sr/api/v1/upload"
81+
RELEASE_BUILD: 0
82+
uses: actions/github-script@v7
83+
with:
84+
script: |
85+
const script = require('./.github/workflows/canary.js');
86+
console.log(await script({ github, context, core }));

.github/workflows/canary.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { readFile } = require("node:fs/promises");
2+
const { spawnSync } = require("node:child_process");
3+
const { createHash } = require("node:crypto");
4+
5+
const isWindows = process.platform === "win32";
6+
const files = isWindows ? ["sar.dll", "sar.pdb"] : ["sar.so"];
7+
8+
// @ts-check
9+
/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
10+
module.exports = async ({ context, core }) => {
11+
const git = spawnSync("git", ["describe", "--tags"]);
12+
if (git.status !== 0) {
13+
return git.stderr.toString("utf-8");
14+
}
15+
16+
const SAR_VERSION = git.stdout.toString("utf-8");
17+
const release = process.env.release == '1';
18+
19+
core.info(`Uploading ${release ? 'release' : 'canary'} version ${SAR_VERSION}`);
20+
21+
const body = new FormData();
22+
body.set("version", `${SAR_VERSION.split("-").at(0)}${!release ? '-canary' : ''}`);
23+
body.set("sar_version", `${SAR_VERSION}${!release ? '-canary' : ''}`);
24+
body.set("system", isWindows ? "windows" : "linux");
25+
body.set("commit", context.sha);
26+
body.set("branch", context.ref.split("/").at(-1));
27+
body.set("count", files.length.toString());
28+
29+
for (let i = 0; i < files.length; ++i) {
30+
const filename = files[i];
31+
const file = await readFile(`./bin/${filename}`);
32+
body.set(`hashes[${i}]`, createHash("sha256").update(file).digest("hex"));
33+
body.set(`files[${i}]`, new Blob([file]), filename);
34+
}
35+
36+
core.debug(JSON.stringify([...body.entries()]));
37+
38+
const res = await fetch("https://dl.sar.portal2.sr/api/v1/upload", {
39+
method: "POST",
40+
headers: {
41+
"Authorization": `Bearer ${process.env.DL_SAR_API_TOKEN}`,
42+
"Content-Type": "multipart/form-data",
43+
},
44+
body,
45+
});
46+
47+
core.info(res.statusText);
48+
49+
return await res.text();
50+
};

0 commit comments

Comments
 (0)