diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b78433..90d3f58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -26,67 +24,66 @@ 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 @@ -94,19 +91,20 @@ jobs: 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 }} diff --git a/.husky/pre-push b/.husky/pre-push index fe7dad3..3dcc4f1 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -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 \ No newline at end of file diff --git a/scripts/__tests__/refresh-npm-token.test.ts b/scripts/__tests__/refresh-npm-token.test.js similarity index 95% rename from scripts/__tests__/refresh-npm-token.test.ts rename to scripts/__tests__/refresh-npm-token.test.js index ace0b53..5ed344a 100644 --- a/scripts/__tests__/refresh-npm-token.test.ts +++ b/scripts/__tests__/refresh-npm-token.test.js @@ -13,7 +13,7 @@ describe("refreshNpmToken", () => { const mockRepoName = "mock-user/mock-repo"; const mockNewToken = "mock-new-token"; - let consoleErrorSpy: ReturnType; + let consoleErrorSpy; beforeEach(() => { process.env.GITHUB_TOKEN = mockGithubToken; @@ -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(() => {}); @@ -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( diff --git a/scripts/refresh-npm-token.ts b/scripts/refresh-npm-token.js similarity index 100% rename from scripts/refresh-npm-token.ts rename to scripts/refresh-npm-token.js diff --git a/tsconfig.json b/tsconfig.json index 6fec498..a4f01b2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,6 +28,6 @@ "emitDecoratorMetadata": true, "esModuleInterop": true }, - "include": ["src", "scripts/**/*.ts"], + "include": ["src"], "exclude": ["node_modules", "dist", "src/examples", "src/tests"] } diff --git a/vitest.node.config.ts b/vitest.node.config.ts index 4f84298..f490fd5 100644 --- a/vitest.node.config.ts +++ b/vitest.node.config.ts @@ -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 }, });