Skip to content
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
35 changes: 35 additions & 0 deletions .github/actions/cleanup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Clean up test action environment'
description: 'Deletes test branch and optionally test tag from remote'
inputs:
branch:
description: 'Branch name to delete'
required: true
tag:
description: 'Tag name to delete'
required: false
default: ''
runs:
using: composite
steps:
- name: Delete remote branch
shell: bash
run: |
test_branch=$(git ls-remote --heads origin refs/heads/${{ inputs.branch }})
if [[ -n $test_branch ]]; then
echo "test branch ${{ inputs.branch }} existed"
git push -d origin refs/heads/${{ inputs.branch }}
else
echo "test branch ${{ inputs.branch }} does not exist"
fi

- name: Delete remote tag
if: ${{ inputs.tag != '' }}
shell: bash
run: |
test_tag=$(git ls-remote --tags origin refs/tags/${{ inputs.tag }})
if [[ -n $test_tag ]]; then
echo "test tag ${{ inputs.tag }} existed"
git push -d origin refs/tags/${{ inputs.tag }}
else
echo "test tag ${{ inputs.tag }} does not exist"
fi
13 changes: 4 additions & 9 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: Setup Node.js
uses: actions/setup-node@v6
- uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm

- name: Install Dependencies
run: npm ci

- name: Build dist/ Directory
run: npm run bundle
- run: npm ci
- run: npm run bundle

# This will fail the workflow if the `dist/` directory is different than
# expected.
Expand Down
156 changes: 39 additions & 117 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,21 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'main' }}

jobs:
test-jest:
name: Jest Tests
test-vitest:
name: Vitest Tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Node.js
uses: actions/setup-node@v6
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm

- name: Install Dependencies
run: npm ci

- name: Check Format
run: npm run format:check

- name: Lint
run: npm run lint

- name: Test
run: npm run ci-test
- run: npm ci
- run: npm run format:check
- run: npm run lint
- run: npm test

test-action-basic:
name: GitHub Actions Test (Basic)
Expand All @@ -51,8 +41,7 @@ jobs:
BRANCH: test-action-basic

steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: Test Action
id: test-action
Expand All @@ -68,16 +57,10 @@ jobs:
run: echo "${{ steps.test-action.outputs.commit-sha }}"

- name: Clean up test action environment
shell: bash
if: always()
run: |
test_branch=$(git ls-remote --heads origin refs/heads/$BRANCH)
if [[ -n $test_branch ]]; then
echo "test branch $BRANCH existed"
git push -d origin refs/heads/$BRANCH
else
echo "test branch $BRANCH does not exist"
fi
uses: ./.github/actions/cleanup
with:
branch: ${{ env.BRANCH }}

test-action-branch:
name: GitHub Actions Test (Custom Branch)
Expand All @@ -89,8 +72,7 @@ jobs:
BRANCH: test-action-branch

steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: generate dummy content
shell: bash
Expand All @@ -113,16 +95,10 @@ jobs:
run: echo "${{ steps.test-action.outputs.commit-sha }}"

- name: Clean up test action environment
shell: bash
if: always()
run: |
test_branch=$(git ls-remote --heads origin refs/heads/$BRANCH)
if [[ -n $test_branch ]]; then
echo "test branch $BRANCH existed"
git push -d origin refs/heads/$BRANCH
else
echo "test branch $BRANCH does not exist"
fi
uses: ./.github/actions/cleanup
with:
branch: ${{ env.BRANCH }}

test-action-workspace:
name: GitHub Actions Test (Workspace)
Expand All @@ -134,8 +110,7 @@ jobs:
BRANCH: test-action-workspace

steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: generate dummy content
shell: bash
Expand All @@ -159,16 +134,10 @@ jobs:
run: echo "${{ steps.test-action.outputs.commit-sha }}"

- name: Clean up test action environment
shell: bash
if: always()
run: |
test_branch=$(git ls-remote --heads origin refs/heads/$BRANCH)
if [[ -n $test_branch ]]; then
echo "test branch $BRANCH existed"
git push -d origin refs/heads/$BRANCH
else
echo "test branch $BRANCH does not exist"
fi
uses: ./.github/actions/cleanup
with:
branch: ${{ env.BRANCH }}

test-action-glob:
name: GitHub Actions Test (Glob)
Expand All @@ -180,8 +149,7 @@ jobs:
BRANCH: test-action-glob

steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: generate dummy content
shell: bash
Expand All @@ -204,16 +172,10 @@ jobs:
run: echo "${{ steps.test-action.outputs.commit-sha }}"

- name: Clean up test action environment
shell: bash
if: always()
run: |
test_branch=$(git ls-remote --heads origin refs/heads/$BRANCH)
if [[ -n $test_branch ]]; then
echo "test branch $BRANCH existed"
git push -d origin refs/heads/$BRANCH
else
echo "test branch $BRANCH does not exist"
fi
uses: ./.github/actions/cleanup
with:
branch: ${{ env.BRANCH }}

test-action-tag:
name: GitHub Actions Test (Tag)
Expand All @@ -226,8 +188,7 @@ jobs:
BRANCH: test-action-tag

steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: Test Action
id: test-action
Expand All @@ -244,23 +205,11 @@ jobs:
echo "[tag] ${{ steps.test-action.outputs.tag }}"

- name: Clean up test action environment
shell: bash
if: always()
run: |
test_branch=$(git ls-remote --heads origin refs/heads/$BRANCH)
if [[ -n $test_branch ]]; then
echo "test branch $BRANCH existed"
git push -d origin refs/heads/$BRANCH
else
echo "test branch $BRANCH does not exist"
fi
test_tag=$(git ls-remote --tags origin refs/tags/$TAG)
if [[ -n $test_tag ]]; then
echo "test tag $TAG existed"
git push -d origin refs/tags/$TAG
else
echo "test tag $TAG does not exist"
fi
uses: ./.github/actions/cleanup
with:
branch: ${{ env.BRANCH }}
tag: ${{ env.TAG }}

test-action-file-tag:
name: GitHub Actions Test (File & Tag)
Expand All @@ -273,9 +222,7 @@ jobs:
TAG: 4.5.6

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: generate dummy content
shell: bash
Expand All @@ -301,23 +248,11 @@ jobs:
echo "[tag] ${{ steps.test-action.outputs.tag }}"

- name: Clean up test action environment
shell: bash
if: always()
run: |
test_branch=$(git ls-remote --heads origin refs/heads/$BRANCH)
if [[ -n $test_branch ]]; then
echo "test branch $BRANCH existed"
git push -d origin refs/heads/$BRANCH
else
echo "test branch $BRANCH does not exist"
fi
test_tag=$(git ls-remote --tags origin refs/tags/$TAG)
if [[ -n $test_tag ]]; then
echo "test tag $TAG existed"
git push -d origin refs/tags/$TAG
else
echo "test tag $TAG does not exist"
fi
uses: ./.github/actions/cleanup
with:
branch: ${{ env.BRANCH }}
tag: ${{ env.TAG }}

test-action-no-file-changes-tag:
name: GitHub Actions Test (No File Changes & Tag)
Expand All @@ -330,8 +265,7 @@ jobs:
TAG: 7.8.9

steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/checkout@v6

- name: Test Action
id: test-action
Expand All @@ -350,20 +284,8 @@ jobs:
echo "[tag] ${{ steps.test-action.outputs.tag }}"

- name: Clean up test action environment
shell: bash
if: always()
run: |
test_branch=$(git ls-remote --heads origin refs/heads/$BRANCH)
if [[ -n $test_branch ]]; then
echo "test branch $BRANCH existed"
git push -d origin refs/heads/$BRANCH
else
echo "test branch $BRANCH does not exist"
fi
test_tag=$(git ls-remote --tags origin refs/tags/$TAG)
if [[ -n $test_tag ]]; then
echo "test tag $TAG existed"
git push -d origin refs/tags/$TAG
else
echo "test tag $TAG does not exist"
fi
uses: ./.github/actions/cleanup
with:
branch: ${{ env.BRANCH }}
tag: ${{ env.TAG }}
5 changes: 1 addition & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ jobs:

steps:
- uses: actions/checkout@v6

- uses: actions/setup-node@v6
with:
node-version-file: .node-version
cache: npm

- run: npm ci

- name: Run tests
run: npx jest --coverage
- run: npm test -- --coverage

- name: Upload results to Codecov
uses: codecov/codecov-action@v6
Expand Down
16 changes: 8 additions & 8 deletions __tests__/blob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import fs from 'node:fs'
import { join } from 'node:path'
import { Buffer } from 'node:buffer'
import { Readable, PassThrough } from 'node:stream'
import { describe, jest, beforeEach, it, expect } from '@jest/globals'
import { describe, vi, beforeEach, it, expect } from 'vitest'
import { Blob, getBlob } from '../src/blob'
import * as cwd from '../src/utils/cwd'

describe('Blob', () => {
beforeEach(() => {
jest.spyOn(core, 'debug').mockReturnValue()
jest.spyOn(cwd, 'getCwd').mockReturnValue(__dirname)
vi.spyOn(core, 'debug').mockReturnValue()
vi.spyOn(cwd, 'getCwd').mockReturnValue(__dirname)
})

it('path', () => {
Expand Down Expand Up @@ -50,9 +50,9 @@ describe('Blob', () => {

it('file exists', async () => {
const blob = new Blob('/my_stream.txt')
jest
.spyOn(blob, 'streamable', 'get')
.mockReturnValue(Readable.from('Hello World'))
vi.spyOn(blob, 'streamable', 'get').mockReturnValue(
Readable.from('Hello World')
)

const chunks: Buffer[] = []
for await (const chunk of blob.streamable) {
Expand All @@ -75,7 +75,7 @@ describe('Blob', () => {
it('file with string', async () => {
const blob = getBlob('fixtures/error.txt')
const mockStream = new PassThrough()
jest.spyOn(blob, 'streamable', 'get').mockReturnValue(mockStream)
vi.spyOn(blob, 'streamable', 'get').mockReturnValue(mockStream)

const loadPromise = blob.load()
mockStream.emit('data', 'string data')
Expand All @@ -89,7 +89,7 @@ describe('Blob', () => {
it('stream with error', async () => {
const blob = getBlob('fixtures/error.txt')
const mockStream = new PassThrough()
jest.spyOn(blob, 'streamable', 'get').mockReturnValue(mockStream)
vi.spyOn(blob, 'streamable', 'get').mockReturnValue(mockStream)

blob.load()
expect(() => mockStream.emit('error', new Error('stream error'))).toThrow(
Expand Down
Loading
Loading