Skip to content

Commit 4650808

Browse files
Initial commit
0 parents  commit 4650808

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4131
-0
lines changed

.cspell.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
3+
"version": "0.2",
4+
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"],
5+
"useGitignore": true,
6+
"language": "en",
7+
"words": ["dataurl", "devpool", "outdir", "servedir"],
8+
"dictionaries": ["typescript", "node", "software-terms"],
9+
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
10+
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
11+
}

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MY_SECRET="MY_SECRET"

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
static/dist/** linguist-generated
2+
*.lockb linguist-generated
3+
*.lock linguist-generated

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

.github/empty-string-checker.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import * as core from "@actions/core";
2+
import { Octokit } from "@octokit/rest";
3+
import simpleGit from "simple-git";
4+
5+
const token = process.env.GITHUB_TOKEN;
6+
const [owner, repo] = process.env.GITHUB_REPOSITORY?.split("/") || [];
7+
const pullNumber = process.env.GITHUB_PR_NUMBER || process.env.PULL_REQUEST_NUMBER || "0";
8+
const baseRef = process.env.GITHUB_BASE_REF;
9+
const excludedFiles: string[] = process.env.EXCLUDED_FILES
10+
? process.env.EXCLUDED_FILES.split("\n")
11+
.map((file) => file.trim())
12+
.filter(Boolean)
13+
: [];
14+
15+
if (!token || !owner || !repo || pullNumber === "0" || !baseRef) {
16+
core.setFailed("Missing required environment variables.");
17+
process.exit(1);
18+
}
19+
20+
const octokit = new Octokit({ auth: token });
21+
const git = simpleGit();
22+
23+
async function main() {
24+
try {
25+
const { data: pullRequest } = await octokit.pulls.get({
26+
owner,
27+
repo,
28+
pull_number: parseInt(pullNumber, 10),
29+
});
30+
31+
const baseSha = pullRequest.base.sha;
32+
const headSha = pullRequest.head.sha;
33+
34+
await git.fetch(["origin", baseSha, headSha]);
35+
36+
const diff = await git.diff([`${baseSha}...${headSha}`]);
37+
38+
core.info("Checking for empty strings...");
39+
const violations = parseDiffForEmptyStrings(diff);
40+
41+
if (violations.length > 0) {
42+
violations.forEach(({ file, line, content }) => {
43+
core.warning(
44+
"Detected an empty string.\n\nIf this is during variable initialization, consider using a different approach.\nFor more information, visit: https://www.github.com/ubiquity/ts-template/issues/31",
45+
{
46+
file,
47+
startLine: line,
48+
}
49+
);
50+
});
51+
52+
// core.setFailed(`${violations.length} empty string${violations.length > 1 ? "s" : ""} detected in the code.`);
53+
54+
await octokit.rest.checks.create({
55+
owner,
56+
repo,
57+
name: "Empty String Check",
58+
head_sha: headSha,
59+
status: "completed",
60+
conclusion: violations.length > 0 ? "failure" : "success",
61+
output: {
62+
title: "Empty String Check Results",
63+
summary: `Found ${violations.length} violation${violations.length !== 1 ? "s" : ""}`,
64+
annotations: violations.map((v) => ({
65+
path: v.file,
66+
start_line: v.line,
67+
end_line: v.line,
68+
annotation_level: "warning",
69+
message: "Empty string found",
70+
raw_details: v.content,
71+
})),
72+
},
73+
});
74+
} else {
75+
core.info("No empty strings found.");
76+
}
77+
} catch (error) {
78+
core.setFailed(`An error occurred: ${error instanceof Error ? error.message : String(error)}`);
79+
}
80+
}
81+
82+
function parseDiffForEmptyStrings(diff: string) {
83+
const violations: Array<{ file: string; line: number; content: string }> = [];
84+
const diffLines = diff.split("\n");
85+
86+
let currentFile: string;
87+
let headLine = 0;
88+
let inHunk = false;
89+
90+
diffLines.forEach((line) => {
91+
const hunkHeaderMatch = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
92+
if (hunkHeaderMatch) {
93+
headLine = parseInt(hunkHeaderMatch[1], 10);
94+
inHunk = true;
95+
return;
96+
}
97+
98+
if (line.startsWith("--- a/") || line.startsWith("+++ b/")) {
99+
currentFile = line.slice(6);
100+
inHunk = false;
101+
return;
102+
}
103+
104+
// Skip files in excludedFiles
105+
if (excludedFiles.includes(currentFile)) {
106+
return;
107+
}
108+
109+
// Only process TypeScript files
110+
if (!currentFile?.endsWith(".ts")) {
111+
return;
112+
}
113+
114+
if (inHunk && line.startsWith("+")) {
115+
// Check for empty strings in TypeScript syntax
116+
if (/^\+.*""/.test(line)) {
117+
// Ignore empty strings in comments
118+
if (!line.trim().startsWith("//") && !line.trim().startsWith("*")) {
119+
// Ignore empty strings in template literals
120+
if (!/`[^`]*\$\{[^}]*\}[^`]*`/.test(line)) {
121+
violations.push({
122+
file: currentFile,
123+
line: headLine,
124+
content: line.substring(1).trim(),
125+
});
126+
}
127+
}
128+
}
129+
headLine++;
130+
} else if (!line.startsWith("-")) {
131+
headLine++;
132+
}
133+
});
134+
135+
return violations;
136+
}
137+
main().catch((error) => {
138+
core.setFailed(`Error running empty string check: ${error instanceof Error ? error.message : String(error)}`);
139+
});

.github/knip.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { KnipConfig } from "knip";
2+
3+
const config: KnipConfig = {
4+
entry: ["build/index.ts", ".github/empty-string-checker.ts"],
5+
project: ["src/**/*.ts"],
6+
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**", "eslint.config.mjs"],
7+
ignoreExportsUsedInFile: true,
8+
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
9+
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "@types/jest", "@mswjs/data", "husky"],
10+
eslint: true,
11+
};
12+
13+
export default config;

.github/pull_request_template.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Related Issue
2+
<!-- Link to the issue or task (e.g., "Resolves #123" or "Resolves https://github.com/ubiquity/ts-template/issues/1") -->
3+
4+
## Summary
5+
<!-- Briefly summarize the changes in this PR -->
6+
7+
## Proof of Fix
8+
<!-- Attach a test URL, screenshot or video demonstrating the fix -->
9+
10+
## Testing Steps
11+
<!-- Steps to test this pull request locally (include any setup or environment changes) -->
12+
13+
## Post-merge Steps
14+
<!-- Any steps required after merging (e.g., run migrations, clear cache) -->

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-22.04
14+
15+
steps:
16+
- name: Check out repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up bun
20+
uses: oven-sh/setup-bun@v2
21+
22+
- name: Build
23+
run: |
24+
bun install
25+
bun run build
26+
27+
- name: Upload build artifact
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: static
31+
path: static
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Conventional Commits
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
conventional-commits:
8+
name: Conventional Commits
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ubiquity/action-conventional-commits@master

.github/workflows/cspell.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Spell Check
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
spellcheck:
8+
name: Check for spelling errors
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up bun
16+
uses: oven-sh/setup-bun@v2
17+
18+
- name: Set up bun
19+
uses: oven-sh/setup-bun@v2
20+
21+
- name: Install cspell
22+
run: bun add cspell
23+
24+
- name: Run cspell
25+
run: bun run format:cspell

0 commit comments

Comments
 (0)