Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): add github actions #1

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.ts text eol=lf
*.js text eol=lf
*.json text eol=lf
*.json5 text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.md text eol=lf
*.editorconfig text eol=lf
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Rlease
on:
push:
tags:
- "v*.*.*"

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Build
run: |
pnpm i
pnpm build

- name: Pack
run: |
pnpm pack

- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
out/*
*.tgz
generate_release_notes: true
draft: false
prerelease: false
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
run: |
pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
node-version: [16, 18, 20]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Intall
run: pnpm install

- name: Lint
run: pnpm run lint

- name: Typescript Check
run: pnpm run ts-check

- name: Build
run: pnpm build

- name: Test
run: pnpm run test

- name: Coveralls Parallel
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.os }}-${{ matrix.node-version }}
parallel: true

finish:
needs: test
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
1 change: 1 addition & 0 deletions cspell.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ words:
- tsup
- sparsefile
- treeshake
- lcov
dictionaries:
- companies
- softwareTerms
Expand Down
24 changes: 21 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ interface TestContext {
file: string;
}

/**
* Override Number.MAX_SAFE_INTEGER.
* Because in certain systems (such as the Ubuntu system in GitHub Actions),
* it is not allowed to set extremely large files, even if they are sparse files.
*/
const gn = global.Number;
function Number(...args: any[]) {
return gn(...args);
}
Object.setPrototypeOf(Number, class NumberClass extends global.Number {
public static override get MAX_SAFE_INTEGER(): number {
return 1024 * 1024 * 50;
}
});
global.Number = Number as unknown as NumberConstructor;
const MAX_SAFE_INTEGER = global.Number.MAX_SAFE_INTEGER;


beforeEach<TestContext>(async (ctx) => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "sparse-file-"));
ctx.cwd = tmpDir;
Expand Down Expand Up @@ -44,7 +62,7 @@ describe.concurrent("create sparse with safe mode", () => {
});

it<TestContext>("should throw error when size > Number.MAX_SAFE_INTEGER", async (ctx) => {
await expect(createSparse(ctx.file, Number.MAX_SAFE_INTEGER + 1)).rejects.toThrow(ERR_GT_MAX_SAFE_INTEGER);
await expect(createSparse(ctx.file, MAX_SAFE_INTEGER + 1)).rejects.toThrow(ERR_GT_MAX_SAFE_INTEGER);
});

it<TestContext>("do nothing when filesize == pass size param", async (ctx) => {
Expand Down Expand Up @@ -93,12 +111,12 @@ describe("create sparse without safe mode", () => {
size: 1,
});

await createSparse(ctx.file, Number.MAX_SAFE_INTEGER + 1, {
await createSparse(ctx.file, MAX_SAFE_INTEGER + 1, {
safe: false,
});

await expect(fs.stat(ctx.file)).resolves.toMatchObject({
size: Number.MAX_SAFE_INTEGER,
size: MAX_SAFE_INTEGER,
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
coverage: {
enabled: true,
provider: "v8",
reporter: ["text", "html", "json"],
reporter: ["text", "html", "json", "lcov"],
},
reporters: ["default"],
include: ["src/*.test.ts"],
Expand Down