Skip to content

Commit 8a7cdde

Browse files
committed
feat: init ci
1 parent 2b1f837 commit 8a7cdde

File tree

9 files changed

+1466
-1077
lines changed

9 files changed

+1466
-1077
lines changed

.eslintrc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ rules:
175175

176176
overrides:
177177
- files:
178-
- ./**/*.js
178+
- ./scripts/**/*.js
179179
plugins:
180180
- '@typescript-eslint'
181181
parserOptions:
182-
project: ./tsconfig.json
182+
project: ./scripts/tsconfig.json
183183
rules:
184184
'@typescript-eslint/prefer-nullish-coalescing': 0
185185
'@typescript-eslint/prefer-optional-chain': 0

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [Brooooooklyn]

.github/workflows/CI.yml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
node: ['10', '12', '14']
11+
os: [ubuntu-latest, macos-latest, windows-latest]
12+
13+
name: stable - ${{ matrix.os }} - node@${{ matrix.node }}
14+
runs-on: ${{ matrix.os }}
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Setup node
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node }}
23+
24+
- name: Set platform name
25+
run: |
26+
export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
27+
echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
28+
shell: bash
29+
30+
- name: Install llvm
31+
if: matrix.os == 'windows-latest'
32+
run: choco install -y llvm
33+
34+
- name: Set llvm path
35+
if: matrix.os == 'windows-latest'
36+
uses: allenevans/[email protected]
37+
with:
38+
LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'
39+
40+
- name: Install
41+
uses: actions-rs/toolchain@v1
42+
with:
43+
toolchain: stable
44+
profile: minimal
45+
override: true
46+
47+
- name: Generate Cargo.lock
48+
uses: actions-rs/cargo@v1
49+
with:
50+
command: generate-lockfile
51+
52+
- name: Cache cargo registry
53+
uses: actions/cache@v1
54+
with:
55+
path: ~/.cargo/registry
56+
key: stable-${{ matrix.os }}-node@${{ matrix.node }}-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
57+
58+
- name: Cache cargo index
59+
uses: actions/cache@v1
60+
with:
61+
path: ~/.cargo/git
62+
key: stable-${{ matrix.os }}gnu-node@${{ matrix.node }}-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
63+
64+
- name: Cache NPM dependencies
65+
uses: actions/cache@v1
66+
with:
67+
path: node_modules
68+
key: npm-cache-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
69+
restore-keys: |
70+
npm-cache-
71+
72+
- name: 'Install dependencies'
73+
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
74+
75+
- name: 'Build'
76+
run: yarn build
77+
78+
- name: Upload artifact
79+
uses: actions/upload-artifact@v2
80+
with:
81+
name: bindings-${{ env.PLATFORM_NAME }}
82+
path: packages/core/swc.${{ env.PLATFORM_NAME }}.node
83+
84+
- name: Clear the cargo caches
85+
run: |
86+
cargo install cargo-cache --no-default-features --features ci-autoclean
87+
cargo-cache
88+
89+
test_binding:
90+
name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
91+
needs:
92+
- build
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
os: [ubuntu-latest, macos-latest, windows-latest]
97+
node: ['10', '12', '14']
98+
runs-on: ${{ matrix.os }}
99+
100+
steps:
101+
- uses: actions/checkout@v2
102+
103+
- name: Setup node
104+
uses: actions/setup-node@v1
105+
with:
106+
node-version: ${{ matrix.node }}
107+
108+
- name: Set platform name
109+
run: |
110+
export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
111+
echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
112+
shell: bash
113+
114+
# Do not cache node_modules, or yarn workspace links broken
115+
- name: 'Install dependencies'
116+
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
117+
118+
- name: Download artifacts
119+
uses: actions/download-artifact@v2
120+
with:
121+
name: bindings-${{ env.PLATFORM_NAME }}
122+
path: packages/core/swc.${{ env.PLATFORM_NAME }}.node
123+
124+
- name: List packages
125+
run: ls -R packages
126+
shell: bash
127+
128+
- name: Test bindings
129+
run: yarn test
130+
131+
publish:
132+
name: Publish
133+
if: "startsWith(github.event.head_commit.message, 'chore(release): publish')"
134+
runs-on: ubuntu-latest
135+
needs: test_binding
136+
137+
steps:
138+
- uses: actions/checkout@v2
139+
140+
- name: Setup node
141+
uses: actions/setup-node@v1
142+
with:
143+
node-version: 12
144+
145+
- name: Cache NPM dependencies
146+
uses: actions/cache@v1
147+
with:
148+
path: node_modules
149+
key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
150+
restore-keys: |
151+
npm-cache-
152+
- name: 'Install dependencies'
153+
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
154+
155+
- name: Download all artifacts
156+
uses: actions/download-artifact@v2
157+
with:
158+
path: packages/core
159+
160+
- name: List artifacts
161+
run: ls -R artifacts
162+
shell: bash
163+
164+
- name: Upload artifacts to Github release
165+
run: |
166+
node scripts/upload-to-release.js
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169+
170+
- name: List packages
171+
run: ls -R packages
172+
shell: bash
173+
- name: Lerna publish
174+
run: |
175+
find ./packages/ -type d -maxdepth 1 -exec cp LICENSE {} \\;
176+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
177+
npx lerna publish from-package --no-verify-access --yes
178+
env:
179+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-present LongYinan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
},
3939
"devDependencies": {
4040
"@istanbuljs/nyc-config-typescript": "^1.0.1",
41+
"@octokit/rest": "^18.0.3",
4142
"@typescript-eslint/eslint-plugin": "^3.7.0",
4243
"@typescript-eslint/parser": "^3.7.0",
4344
"ava": "^3.10.1",
45+
"chalk": "^4.1.0",
4446
"eslint": "^7.5.0",
4547
"eslint-config-prettier": "^6.11.0",
4648
"eslint-plugin-import": "^2.22.0",
@@ -52,6 +54,7 @@
5254
"npm-run-all": "^4.1.5",
5355
"nyc": "^15.1.0",
5456
"prettier": "^2.0.5",
57+
"putasset": "^5.0.3",
5558
"source-map-support": "^0.5.19",
5659
"ts-node": "^8.10.2",
5760
"typescript": "^3.9.7"

packages/register/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
},
3535
"dependencies": {
3636
"@swc-node/core": "^0.0.0",
37-
"pirates": "^4.0.1",
38-
"source-map": "^0.7.3",
39-
"source-map-support": "^0.5.19"
37+
"pirates": "^4.0.1"
4038
}
4139
}

scripts/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"outDir": "../dist"
6+
},
7+
"include": ["."]
8+
}

scripts/upload-to-release.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { execSync } = require('child_process')
2+
const { join } = require('path')
3+
4+
const { Octokit } = require('@octokit/rest')
5+
const chalk = require('chalk')
6+
const putasset = require('putasset')
7+
8+
const supporttedPlatforms = []
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 core = 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+
.find((pkgInfo) => pkgInfo.isNativePackage)
26+
if (core) {
27+
await octokit.repos.createRelease({
28+
owner,
29+
repo,
30+
tag_name: core.tag,
31+
})
32+
await Promise.all(
33+
supporttedPlatforms.map(async (platform) => {
34+
const binary = join('package', 'core', `swc.${platform}.node`)
35+
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
36+
owner,
37+
repo,
38+
tag: core.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+
})().catch((e) => {
47+
console.error(e)
48+
})
49+
50+
/**
51+
* @param {string} tag
52+
*/
53+
function parseTag(tag) {
54+
const [, packageWithVersion] = tag.split('/')
55+
const [name, version] = packageWithVersion.split('@')
56+
const isNativePackage = name === 'core'
57+
58+
return {
59+
name,
60+
version,
61+
tag,
62+
isNativePackage,
63+
}
64+
}

0 commit comments

Comments
 (0)