Skip to content

Commit 219db02

Browse files
authored
align with github-stats-extended (#22)
* remove GITHUB_REPOSITORY_OWNER, align with github-stats-extended setup, split test * test GITHUB_REPOSITORY_OWNER * remove debug log * switch back to 'rickstaa' in e2e.yml * align ci.yml, use pnpm, precise permissions, concurrent tests, cleanup
1 parent aa342da commit 219db02

15 files changed

Lines changed: 2297 additions & 4867 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Setup Node.js + PNPM and install Dependencies
2+
description: |
3+
This is a composite GitHub Action that:
4+
- Sets up pnpm package manager
5+
- Configures Node.js environment
6+
- Installs project dependencies with caching
7+
8+
inputs:
9+
node-version:
10+
description: "Explicit node version. Otherwise fallback reading `.nvmrc`"
11+
12+
runs:
13+
using: composite
14+
15+
steps:
16+
- name: Install pnpm
17+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5
18+
19+
- name: Setup Node.js (via input)
20+
if: ${{ inputs.node-version }}
21+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
22+
with:
23+
node-version: ${{ inputs.node-version }}
24+
cache: "pnpm"
25+
registry-url: "https://registry.npmjs.org"
26+
27+
- name: Setup Node.js (via .nvmrc)
28+
if: ${{ !inputs.node-version }}
29+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
30+
with:
31+
node-version-file: ".nvmrc"
32+
cache: "pnpm"
33+
registry-url: "https://registry.npmjs.org"
34+
35+
- name: Install Dependencies
36+
shell: bash
37+
run: pnpm install --frozen-lockfile

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
concurrency:
13+
group: "${{ github.workflow }}-${{ github.head_ref }}"
14+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
15+
16+
permissions: {}
17+
18+
jobs:
19+
test:
20+
name: Test ${{ matrix.node }} on ${{ matrix.os }}
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
node: [22, 24]
26+
os: [ubuntu-latest, macos-latest]
27+
runs-on: ${{ matrix.os }}
28+
29+
permissions:
30+
contents: read
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
35+
36+
- name: Install Dependencies
37+
uses: ./.github/actions/install-dependencies
38+
with:
39+
node-version: ${{ matrix.node }}
40+
41+
- name: Run E2E tests
42+
run: pnpm run test
43+
env:
44+
PAT_1: ${{ secrets.GITHUB_TOKEN }}
45+
GITHUB_REPOSITORY_OWNER: "rickstaa"
46+
47+
code-checks:
48+
name: Code checks
49+
50+
runs-on: ubuntu-latest
51+
52+
permissions:
53+
contents: read
54+
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
58+
59+
- name: Install Dependencies
60+
uses: ./.github/actions/install-dependencies
61+
62+
- name: Format
63+
run: pnpm run format:check
64+
65+
- name: Lint (knip)
66+
run: pnpm run lint:knip

.github/workflows/e2e.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
name: Release
1+
name: Update version tags
22
on:
33
push:
44
branches-ignore:
55
- "**"
66
tags:
77
- "v*.*.*"
8-
permissions:
9-
contents: write
8+
9+
permissions: {}
10+
1011
jobs:
1112
update-semver:
1213
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
1316
steps:
1417
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1518
- uses: haya14busa/action-update-semver@7d2c558640ea49e798d46539536190aff8c18715 # v1.5.1
16-
with:
17-
major_version_tag_only: true
18-
- name: Create release
19-
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1
20-
env:
21-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
node_modules
2+
3+
# OS
24
.DS_Store
3-
.env
4-
.vscode
5+
6+
# IDE
7+
.idea/
8+
.vscode/*
9+
!.vscode/extensions.json
10+
!.vscode/settings.json
511
*.code-workspace

.husky/pre-commit

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
4-
npm run lint-staged
5-
npm test
1+
pnpm lint-staged
2+
pnpm test

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pnpm-lock.yaml
22
package-lock.json
33
yarn.lock
4+
*.md

.prettierrc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"useTabs": false,
4+
"semi": true,
5+
"trailingComma": "all",
26
"singleQuote": false,
3-
"trailingComma": "all"
7+
"printWidth": 80,
8+
"tabWidth": 2,
9+
"overrides": [
10+
{
11+
"files": ["*.jsonc"],
12+
"options": {
13+
"trailingComma": "none"
14+
}
15+
}
16+
]
417
}

index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import core from "@actions/core";
22
import { mkdir, writeFile } from "node:fs/promises";
33
import path from "node:path";
4+
5+
import { getInput, info, setFailed, setOutput, warning } from "@actions/core";
46
import statsApi from "github-readme-stats/api/index.js";
57
import repoApi from "github-readme-stats/api/pin.js";
68
import topLangsApi from "github-readme-stats/api/top-langs.js";
@@ -32,14 +34,16 @@ const normalizeOptions = (options) => {
3234
* @returns {Record<string, string>} Parsed options.
3335
*/
3436
const parseOptions = (value) => {
35-
if (!value) return {};
37+
if (!value) {
38+
return {};
39+
}
3640

3741
const trimmed = value.trim();
3842
const options = {};
3943
if (trimmed.startsWith("{")) {
4044
try {
4145
Object.assign(options, JSON.parse(trimmed));
42-
} catch (error) {
46+
} catch {
4347
throw new Error("Invalid JSON in options.");
4448
}
4549
} else {
@@ -77,7 +81,7 @@ const cardHandlers = {
7781
const validateCardOptions = (card, query, repoOwner) => {
7882
if (!query.username && repoOwner) {
7983
query.username = repoOwner;
80-
core.warning("username not provided; defaulting to repository owner.");
84+
warning("username not provided; defaulting to repository owner.");
8185
}
8286
switch (card) {
8387
case "stats":
@@ -103,9 +107,9 @@ const validateCardOptions = (card, query, repoOwner) => {
103107
};
104108

105109
const run = async () => {
106-
const card = core.getInput("card", { required: true }).toLowerCase();
107-
const optionsInput = core.getInput("options") || "";
108-
const outputPathInput = core.getInput("path");
110+
const card = getInput("card", { required: true }).toLowerCase();
111+
const optionsInput = getInput("options") || "";
112+
const outputPathInput = getInput("path");
109113

110114
const handler = cardHandlers[card];
111115
if (!handler) {
@@ -136,10 +140,10 @@ const run = async () => {
136140
}
137141

138142
await writeFile(outputPath, svg, "utf8");
139-
core.info(`Wrote ${outputPath}`);
140-
core.setOutput("path", outputPathValue);
143+
info(`Wrote ${outputPath}`);
144+
setOutput("path", outputPathValue);
141145
};
142146

143147
run().catch((error) => {
144-
core.setFailed(error instanceof Error ? error.message : String(error));
148+
setFailed(error instanceof Error ? error.message : String(error));
145149
});

jest.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)