Skip to content

Commit

Permalink
Merge branch 'test-ci-workflow'
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjcf committed Dec 13, 2024
2 parents dec6a77 + b1f43b2 commit b99c7a0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
48 changes: 23 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
# Step 1: Check out the code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Cache dependencies
- name: Cache dependencies
uses: actions/cache@v3
with:
Expand All @@ -26,87 +24,87 @@ jobs:
restore-keys: |
${{ runner.os }}-node-
# Step 3: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 22
cache: 'npm'

# Step 4: Install dependencies
- name: Install dependencies
run: npm install

# Step 5: Validate commit messages
- name: Validate commit messages
run: |
npx --no-install commitlint --from=HEAD~10 --to=HEAD
npx --no-install commitlint --from=$(git rev-list --max-parents=0 HEAD) --to=HEAD
# Step 6: Run linting
- name: Lint code
run: npm run lint

# Step 7: Run jsdom tests
- name: Run jsdom tests
run: npm run test:jsdom
run: npm run test

# Step 8: Run node tests
- name: Run node tests
run: npm run test
run: npm run test:node

# Step 9: Run coverage
- name: Run coverage
run: npm run test:coverage

release:
needs: build
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
# Step 1: Check out the code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Install dependencies
- name: Set up Git configuration
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 22

- name: Install dependencies
run: npm install

# Step 3: Generate changelog and bump version
- name: Configure NPM registry
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: Generate changelog and bump version
run: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Step 4: Push changes and tags
- name: Push changes and tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git push origin main --follow-tags
# Step 5: Publish to NPM
- name: Publish to NPM
if: github.ref == 'refs/heads/main'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

refresh-token:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 22

# Step 3: Run the token refresh script
- name: Install dependencies
run: npm install

- name: Refresh NPM Token
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
echo "Running jsdom tests..."
npm run test:jsdom
echo "Running package tests..."
npm run test

echo "Running node tests..."
echo "Running scripts tests..."
npm run test:node
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("refreshNpmToken", () => {
const mockRepoName = "mock-user/mock-repo";
const mockNewToken = "mock-new-token";

let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
let consoleErrorSpy;

beforeEach(() => {
process.env.GITHUB_TOKEN = mockGithubToken;
Expand All @@ -24,7 +24,7 @@ describe("refreshNpmToken", () => {
ok: true,
status: 200,
statusText: "OK",
} as Response);
});

// Spy on console.error to suppress logs
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
Expand Down Expand Up @@ -62,7 +62,7 @@ describe("refreshNpmToken", () => {
ok: false,
status: 500,
statusText: "Internal Server Error",
} as Response);
});

// Assert that refreshNpmToken rejects with the correct error
await expect(refreshNpmToken()).rejects.toThrow(
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"emitDecoratorMetadata": true,
"esModuleInterop": true
},
"include": ["src", "scripts/**/*.ts"],
"include": ["src"],
"exclude": ["node_modules", "dist", "src/examples", "src/tests"]
}
2 changes: 1 addition & 1 deletion vitest.node.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export default defineConfig({
test: {
environment: "node", // Use Node.js environment
globals: true, // Enable global imports like fetch, etc.
include: ["scripts/__tests__/**/*.test.ts"], // Only run tests in the scripts directory
include: ["scripts/__tests__/**/*.test.js"], // Only run tests in the scripts directory
},
});

0 comments on commit b99c7a0

Please sign in to comment.