Skip to content

Commit 27c0455

Browse files
author
LongYinan
committed
ci: upload artifacts to github release
1 parent 8997e1f commit 27c0455

File tree

7 files changed

+168
-5
lines changed

7 files changed

+168
-5
lines changed

.github/workflows/ci.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,9 @@ jobs:
203203
npx lerna publish from-package --no-verify-access --yes
204204
env:
205205
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
206+
207+
- name: Upload artifacts to Github release
208+
run: |
209+
node scripts/upload-to-release.js
210+
env:
211+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

LICENSE

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"typecheck": "tsc -b tsconfig.project.json -verbose"
2121
},
2222
"devDependencies": {
23+
"@octokit/rest": "^17.8.0",
2324
"@typescript-eslint/eslint-plugin": "^2.29.0",
2425
"@typescript-eslint/parser": "^2.29.0",
2526
"ava": "^3.8.0",
@@ -39,6 +40,7 @@
3940
"npm-run-all": "^4.1.5",
4041
"nyc": "^15.0.1",
4142
"prettier": "^2.0.5",
43+
"putasset": "^5.0.3",
4244
"ts-node": "^8.9.1",
4345
"tsconfig-paths": "^3.9.0",
4446
"typescript": "^3.8.3"

scripts/mv-artifacts.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ const { existsSync } = require('fs')
33
const { platform } = require('os')
44
const { join } = require('path')
55

6+
const supporttedPlatforms = require('./platforms')
7+
68
const MOVE_ALL = process.env.MOVE_TARGET === 'all'
79

8-
const platforms = MOVE_ALL ? ['linux', 'darwin', 'win32'] : [platform()]
10+
const platforms = MOVE_ALL ? supporttedPlatforms : [platform()]
911

1012
const packages = ['crc32', 'jieba']
1113

scripts/platforms.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = ['linux', 'darwin', 'win32']

scripts/upload-to-release.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const { execSync } = require('child_process')
2+
const { join } = require('path')
3+
const { existsSync } = require('fs')
4+
const chalk = require('chalk')
5+
const putasset = require('putasset')
6+
const { Octokit } = require('@octokit/rest')
7+
8+
const supporttedPlatforms = require('./platforms')
9+
10+
const headCommit = execSync('git log -1 --pretty=%B', {
11+
encoding: 'utf8',
12+
})
13+
14+
;(async () => {
15+
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')
16+
const octokit = new Octokit({
17+
auth: process.env.GITHUB_TOKEN,
18+
})
19+
const packages = headCommit
20+
.split('\n')
21+
.map((line) => line.trim())
22+
.filter((line, index) => line.length && index)
23+
.map((line) => line.substr(2))
24+
.map(parseTag)
25+
.filter((pkgInfo) => pkgInfo.isNativePackage)
26+
for (const package of packages) {
27+
await octokit.repos.createRelease({
28+
owner,
29+
repo,
30+
tag_name: package.tag,
31+
})
32+
await Promise.all(
33+
supporttedPlatforms.map(async (platform) => {
34+
const binary = join(package.pkgDir, `${package.name}.${platform}.node`)
35+
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
36+
owner,
37+
repo,
38+
tag: package.tag,
39+
filename: binary,
40+
})
41+
console.info(`${chalk.green(binary)} upload success`)
42+
console.info(`Download url: ${chalk.blueBright(downloadUrl)}`)
43+
}),
44+
)
45+
}
46+
})()
47+
48+
/**
49+
* @param {string} tag
50+
*/
51+
function parseTag(tag) {
52+
const [, packageWithVersion] = tag.split('/')
53+
const [name, version] = packageWithVersion.split('@')
54+
const pkgDir = join(__dirname, '..', 'packages', name)
55+
const tomlFilePath = join(pkgDir, 'Cargo.toml')
56+
const isNativePackage = existsSync(tomlFilePath)
57+
58+
return {
59+
name,
60+
version,
61+
pkgDir,
62+
tag,
63+
isNativePackage,
64+
}
65+
}

yarn.lock

+91-3
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,18 @@
10061006
dependencies:
10071007
"@octokit/types" "^2.0.0"
10081008

1009+
"@octokit/core@^2.4.3":
1010+
version "2.5.0"
1011+
resolved "https://registry.yarnpkg.com/@octokit/core/-/core-2.5.0.tgz#4706258893a7ac6ab35d58d2fb9f2d2ba19a41a5"
1012+
integrity sha512-uvzmkemQrBgD8xuGbjhxzJN1darJk9L2cS+M99cHrDG2jlSVpxNJVhoV86cXdYBqdHCc9Z995uLCczaaHIYA6Q==
1013+
dependencies:
1014+
"@octokit/auth-token" "^2.4.0"
1015+
"@octokit/graphql" "^4.3.1"
1016+
"@octokit/request" "^5.4.0"
1017+
"@octokit/types" "^2.0.0"
1018+
before-after-hook "^2.1.0"
1019+
universal-user-agent "^5.0.0"
1020+
10091021
"@octokit/endpoint@^6.0.1":
10101022
version "6.0.1"
10111023
resolved "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.1.tgz#16d5c0e7a83e3a644d1ddbe8cded6c3d038d31d7"
@@ -1015,6 +1027,15 @@
10151027
is-plain-object "^3.0.0"
10161028
universal-user-agent "^5.0.0"
10171029

1030+
"@octokit/graphql@^4.3.1":
1031+
version "4.4.0"
1032+
resolved "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-4.4.0.tgz#4540b48bbf796b837b311ba6ea5104760db530ca"
1033+
integrity sha512-Du3hAaSROQ8EatmYoSAJjzAz3t79t9Opj/WY1zUgxVUGfIKn0AEjg+hlOLscF6fv6i/4y/CeUvsWgIfwMkTccw==
1034+
dependencies:
1035+
"@octokit/request" "^5.3.0"
1036+
"@octokit/types" "^2.0.0"
1037+
universal-user-agent "^5.0.0"
1038+
10181039
"@octokit/plugin-enterprise-rest@^3.6.1":
10191040
version "3.6.2"
10201041
resolved "https://registry.npmjs.org/@octokit/plugin-enterprise-rest/-/plugin-enterprise-rest-3.6.2.tgz#74de25bef21e0182b4fa03a8678cd00a4e67e561"
@@ -1027,6 +1048,13 @@
10271048
dependencies:
10281049
"@octokit/types" "^2.0.1"
10291050

1051+
"@octokit/plugin-paginate-rest@^2.2.0":
1052+
version "2.2.0"
1053+
resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.2.0.tgz#9ae0c14c1b90ec0d96d2ef1b44706b4505a91cee"
1054+
integrity sha512-KoNxC3PLNar8UJwR+1VMQOw2IoOrrFdo5YOiDKnBhpVbKpw+zkBKNMNKwM44UWL25Vkn0Sl3nYIEGKY+gW5ebw==
1055+
dependencies:
1056+
"@octokit/types" "^2.12.1"
1057+
10301058
"@octokit/plugin-request-log@^1.0.0":
10311059
version "1.0.0"
10321060
resolved "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-1.0.0.tgz#eef87a431300f6148c39a7f75f8cfeb218b2547e"
@@ -1040,6 +1068,14 @@
10401068
"@octokit/types" "^2.0.1"
10411069
deprecation "^2.3.1"
10421070

1071+
"@octokit/[email protected]":
1072+
version "3.10.0"
1073+
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-3.10.0.tgz#47f780d69192e45f09f71ded76f0b121b40e2d48"
1074+
integrity sha512-Z2DBsdnkWKuVBVFiLoEUKP/82ylH4Ij5F1Mss106hnQYXTxDfCWAyHW+hJ6ophuHVJ9Flaaue3fYn4CggzkHTg==
1075+
dependencies:
1076+
"@octokit/types" "^2.14.0"
1077+
deprecation "^2.3.1"
1078+
10431079
"@octokit/request-error@^1.0.2":
10441080
version "1.2.1"
10451081
resolved "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.2.1.tgz#ede0714c773f32347576c25649dc013ae6b31801"
@@ -1058,7 +1094,7 @@
10581094
deprecation "^2.0.0"
10591095
once "^1.4.0"
10601096

1061-
"@octokit/request@^5.2.0":
1097+
"@octokit/request@^5.2.0", "@octokit/request@^5.3.0", "@octokit/request@^5.4.0":
10621098
version "5.4.2"
10631099
resolved "https://registry.npmjs.org/@octokit/request/-/request-5.4.2.tgz#74f8e5bbd39dc738a1b127629791f8ad1b3193ee"
10641100
integrity sha512-zKdnGuQ2TQ2vFk9VU8awFT4+EYf92Z/v3OlzRaSh4RIP0H6cvW1BFPXq4XYvNez+TPQjqN+0uSkCYnMFFhcFrw==
@@ -1094,13 +1130,30 @@
10941130
once "^1.4.0"
10951131
universal-user-agent "^4.0.0"
10961132

1133+
"@octokit/rest@^17.1.3", "@octokit/rest@^17.8.0":
1134+
version "17.8.0"
1135+
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-17.8.0.tgz#85da66a98d9f5dfadab079dbb15f6031bd7e5460"
1136+
integrity sha512-m2pdo9+DoEoqQ7wRXV1ihffhE1gbvoC20nvchphluEusbZI6Y9HyXABGiXL+mByy2uUMR2cgBDqBJQQ6bY8Uvg==
1137+
dependencies:
1138+
"@octokit/core" "^2.4.3"
1139+
"@octokit/plugin-paginate-rest" "^2.2.0"
1140+
"@octokit/plugin-request-log" "^1.0.0"
1141+
"@octokit/plugin-rest-endpoint-methods" "3.10.0"
1142+
10971143
"@octokit/types@^2.0.0", "@octokit/types@^2.0.1", "@octokit/types@^2.11.1":
10981144
version "2.12.1"
10991145
resolved "https://registry.npmjs.org/@octokit/types/-/types-2.12.1.tgz#4a26b4a85ec121043d3b0745b5798f9d8fd968ca"
11001146
integrity sha512-LRLR1tjbcCfAmUElvTmMvLEzstpx6Xt/aQVTg2xvd+kHA2Ekp1eWl5t+gU7bcwjXHYEAzh4hH4WH+kS3vh+wRw==
11011147
dependencies:
11021148
"@types/node" ">= 8"
11031149

1150+
"@octokit/types@^2.12.1", "@octokit/types@^2.14.0":
1151+
version "2.15.0"
1152+
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-2.15.0.tgz#b2070520207727bc6ab3a9caa1e4f60b0434bfa8"
1153+
integrity sha512-0mnpenB8rLhBVu8VUklp38gWi+EatjvcEcLWcdProMKauSaQWWepOAybZ714sOGsEyhXPlIcHICggn8HUsCXVw==
1154+
dependencies:
1155+
"@types/node" ">= 8"
1156+
11041157
"@samverschueren/stream-to-observable@^0.3.0":
11051158
version "0.3.0"
11061159
resolved "https://registry.npmjs.org/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
@@ -1673,7 +1726,7 @@ bcrypt-pbkdf@^1.0.0:
16731726
dependencies:
16741727
tweetnacl "^0.14.3"
16751728

1676-
before-after-hook@^2.0.0:
1729+
before-after-hook@^2.0.0, before-after-hook@^2.1.0:
16771730
version "2.1.0"
16781731
resolved "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.1.0.tgz#b6c03487f44e24200dd30ca5e6a1979c5d2fb635"
16791732
integrity sha512-IWIbu7pMqyw3EAJHzzHbWa85b6oud/yfKYg5rqB5hNE8CeMi3nX+2C2sj0HswfblST86hpVEOAb9x34NZd6P7A==
@@ -1941,6 +1994,11 @@ chardet@^0.7.0:
19411994
resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
19421995
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==
19431996

1997+
checkup@^1.3.0:
1998+
version "1.3.0"
1999+
resolved "https://registry.yarnpkg.com/checkup/-/checkup-1.3.0.tgz#d3800276fea5d0f247ffc951be78c8b02f8e0d76"
2000+
integrity sha1-04ACdv6l0PJH/8lRvnjIsC+ODXY=
2001+
19442002
chokidar@^3.4.0:
19452003
version "3.4.0"
19462004
resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.4.0.tgz#b30611423ce376357c765b9b8f904b9fba3c0be8"
@@ -4967,7 +5025,7 @@ [email protected]:
49675025
resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92"
49685026
integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==
49695027

4970-
mime-types@^2.1.12, mime-types@~2.1.19:
5028+
mime-types@^2.1.12, mime-types@^2.1.21, mime-types@~2.1.19:
49715029
version "2.1.27"
49725030
resolved "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f"
49735031
integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==
@@ -6067,6 +6125,19 @@ pupa@^2.0.1:
60676125
dependencies:
60686126
escape-goat "^2.0.0"
60696127

6128+
putasset@^5.0.3:
6129+
version "5.0.3"
6130+
resolved "https://registry.yarnpkg.com/putasset/-/putasset-5.0.3.tgz#2fa82a8fc5e2333869df8ffb0e1f8618b1c87b9b"
6131+
integrity sha512-LGRp0SLOC4PDP/BawMaG3/hw6iKgQPRXcBF7WIzx2XTYwHVk2sS3gpvZqz6bf9GhKMal2phs+DF7J6eIAXEL4w==
6132+
dependencies:
6133+
"@octokit/rest" "^17.1.3"
6134+
checkup "^1.3.0"
6135+
mime-types "^2.1.21"
6136+
readjson "^2.0.1"
6137+
try-catch "^3.0.0"
6138+
try-to-catch "^3.0.0"
6139+
yargs-parser "^18.1.1"
6140+
60706141
q@^1.5.1:
60716142
version "1.5.1"
60726143
resolved "https://registry.npmjs.org/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
@@ -6227,6 +6298,13 @@ readdirp@~3.4.0:
62276298
dependencies:
62286299
picomatch "^2.2.1"
62296300

6301+
readjson@^2.0.1:
6302+
version "2.0.1"
6303+
resolved "https://registry.yarnpkg.com/readjson/-/readjson-2.0.1.tgz#1822964dfd0bc0b49c8f983c192a9dd5309eb9e1"
6304+
integrity sha512-6WuJWYFKx9IVT0zogHlyRC6p+RttAC457garckmGQ8qKICT/xLVrpmvlwp8nTwPHzopbdXIJ593Df8AErIbgeQ==
6305+
dependencies:
6306+
try-catch "^3.0.0"
6307+
62306308
redent@^1.0.0:
62316309
version "1.0.0"
62326310
resolved "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde"
@@ -7268,6 +7346,16 @@ trim-off-newlines@^1.0.0, trim-off-newlines@^1.0.1:
72687346
resolved "https://registry.npmjs.org/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3"
72697347
integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM=
72707348

7349+
try-catch@^3.0.0:
7350+
version "3.0.0"
7351+
resolved "https://registry.yarnpkg.com/try-catch/-/try-catch-3.0.0.tgz#7996d8b89895e2e8ae62cbdbeb4fe17470f8131b"
7352+
integrity sha512-3uAqUnoemzca1ENvZ72EVimR+E8lqBbzwZ9v4CEbLjkaV3Q+FtdmPUt7jRtoSoTiYjyIMxEkf6YgUpe/voJ1ng==
7353+
7354+
try-to-catch@^3.0.0:
7355+
version "3.0.0"
7356+
resolved "https://registry.yarnpkg.com/try-to-catch/-/try-to-catch-3.0.0.tgz#a1903b44d13d5124c54d14a461d22ec1f52ea14b"
7357+
integrity sha512-eIm6ZXwR35jVF8By/HdbbkcaCDTBI5PpCPkejRKrYp0jyf/DbCCcRhHD7/O9jtFI3ewsqo9WctFEiJTS6i+CQA==
7358+
72717359
ts-node@^8.9.1:
72727360
version "8.10.1"
72737361
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.10.1.tgz#77da0366ff8afbe733596361d2df9a60fc9c9bd3"

0 commit comments

Comments
 (0)