Skip to content

Commit 5d2d01e

Browse files
authored
(Fix): Fix setting vars to false and add testing framework (#69)
* add bool parsing * initial ts setup * local test working * workflow * fix tokens and upload * add env name * fix status code
1 parent 98dcf46 commit 5d2d01e

12 files changed

+3885
-21
lines changed

.github/workflows/pr.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Pull Request
2+
run-name: Pull Request for ${{ github.ref_name }} by ${{ github.actor }}
3+
4+
concurrency:
5+
group: ${{ github.head_ref || github.run_id }}
6+
cancel-in-progress: true
7+
8+
permissions: read-all
9+
10+
on:
11+
pull_request: {}
12+
13+
jobs:
14+
trunk_code_quality_runner:
15+
name: Trunk Code Quality runner [linux]
16+
runs-on: ubuntu-latest
17+
permissions:
18+
checks: write
19+
contents: read
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: "22"
28+
29+
- name: Install pnpm
30+
uses: trunk-io/trunk-action/install@v1
31+
with:
32+
tools: pnpm
33+
34+
- name: Install dependencies
35+
run: pnpm install
36+
37+
- name: Trunk Check
38+
uses: trunk-io/trunk-action@v1
39+
40+
test_and_upload:
41+
name: Test and Upload
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v4
49+
with:
50+
node-version: "22"
51+
52+
- name: Install pnpm
53+
uses: trunk-io/trunk-action/install@v1
54+
with:
55+
tools: pnpm
56+
57+
- name: Run tests
58+
shell: bash
59+
run: |
60+
pnpm install
61+
pnpm test
62+
63+
# Do NOT continue-on-error for these uploads
64+
- name: Trunk Analytics Uploader (Prod)
65+
uses: ./
66+
with:
67+
junit-paths: junit.xml
68+
org-slug: trunk
69+
token: ${{ secrets.TRUNK_PROD_ORG_API_TOKEN }}
70+
allow-missing-junit-files: "false"
71+
# Forces the uploader to not continue-on-error and use the CLI exit code
72+
quarantine: "true"
73+
74+
- name: Trunk Analytics Uploader (Staging)
75+
uses: ./
76+
with:
77+
junit-paths: junit.xml
78+
org-slug: trunk-staging-org
79+
token: ${{ secrets.TRUNK_STAGING_ORG_API_TOKEN }}
80+
allow-missing-junit-files: "false"
81+
# Forces the uploader to not continue-on-error and use the CLI exit code
82+
quarantine: "true"
83+
env:
84+
TRUNK_PUBLIC_API_ADDRESS: https://api.trunk-staging.io

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
junit.xml

.trunk/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
plugins
77
user_trunk.yaml
88
user.yaml
9+
tmp

.trunk/trunk.yaml

+28-12
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,51 @@
22
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
33
version: 0.1
44
cli:
5-
version: 1.18.1
5+
version: 1.22.8
66
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
77
plugins:
88
sources:
99
- id: trunk
10-
ref: v1.4.1
10+
ref: v1.6.6
1111
uri: https://github.com/trunk-io/plugins
1212
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
1313
runtimes:
1414
enabled:
1515
- go@1.21.0
16-
- node@18.12.1
16+
- node@18.20.5
1717
- python@3.10.8
1818
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
1919
lint:
2020
enabled:
21-
- checkov@3.1.50
21+
- actionlint@1.7.4
22+
- checkov@3.2.334
23+
- eslint@9.16.0
2224
- git-diff-check
23-
- markdownlint@0.38.0
24-
- prettier@3.1.1
25-
- shellcheck@0.9.0
25+
- markdownlint@0.43.0
26+
- osv-scanner@1.9.1
27+
- prettier@3.4.2
28+
- shellcheck@0.10.0
2629
- shfmt@3.6.0
27-
- trivy@0.48.1
28-
- trufflehog@3.63.7
29-
- yamllint@1.33.0
30+
- sort-package-json@2.12.0
31+
- trivy@0.58.0
32+
- trufflehog@3.86.0
33+
- trunk-toolbox@0.5.4
34+
- yamllint@1.35.1
3035
actions:
31-
disabled:
32-
- trunk-announce
36+
definitions:
37+
- id: test-pre-push
38+
display_name: Arg Tests
39+
runtime: node
40+
packages_file: package.json
41+
run: npm test
42+
triggers:
43+
- git_hooks: [pre-push]
3344
enabled:
45+
- test-pre-push
46+
- trunk-announce
3447
- trunk-check-pre-push
3548
- trunk-fmt-pre-commit
3649
- trunk-upgrade-available
50+
tools:
51+
enabled:
52+
- pnpm@9.15.0

action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ runs:
5151
- name: Upload test results
5252
run: ${GITHUB_ACTION_PATH}/script.sh ${{ inputs.run }}
5353
shell: bash
54-
continue-on-error: ${{ inputs.run == '' && inputs.quarantine == '' }}
54+
continue-on-error: ${{ inputs.run == '' && (inputs.quarantine == '' || inputs.quarantine == 'false') }}
5555
env:
5656
JUNIT_PATHS: ${{ inputs.junit-paths }}
5757
ORG_URL_SLUG: ${{ inputs.org-slug }}

eslint.config.mjs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import path from "node:path";
2+
import url from "node:url";
3+
4+
import eslint from "@eslint/js";
5+
import tseslint from "typescript-eslint";
6+
import pluginJest from "eslint-plugin-jest";
7+
8+
export default tseslint.config(
9+
eslint.configs.recommended,
10+
...tseslint.configs.strictTypeChecked,
11+
...tseslint.configs.stylisticTypeChecked,
12+
{
13+
languageOptions: {
14+
parserOptions: {
15+
projectService: true,
16+
tsconfigRootDir: path.dirname(url.fileURLToPath(import.meta.url)),
17+
},
18+
},
19+
},
20+
{
21+
rules: {
22+
"no-console": "error",
23+
},
24+
},
25+
{
26+
// update this to match your test files
27+
files: ["**/*.test.ts"],
28+
plugins: { jest: pluginJest },
29+
languageOptions: {
30+
globals: pluginJest.environments.globals.globals,
31+
},
32+
rules: {
33+
"jest/no-disabled-tests": "warn",
34+
"jest/no-focused-tests": "error",
35+
"jest/no-identical-title": "error",
36+
"jest/prefer-to-have-length": "warn",
37+
"jest/valid-expect": "error",
38+
},
39+
},
40+
);

jest.config.mjs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// eslint-disable-next-line no-undef
2+
process.env.JEST_JUNIT_ADD_FILE_ATTRIBUTE = "true";
3+
4+
const config = {
5+
preset: "ts-jest",
6+
testEnvironment: "node",
7+
extensionsToTreatAsEsm: [".ts"],
8+
moduleNameMapper: {
9+
"^(\\.{1,2}/.*)\\.js$": "$1",
10+
},
11+
reporters: ["default", "jest-junit"],
12+
transform: {
13+
"^.+\\.ts?$": [
14+
"ts-jest",
15+
{
16+
useESM: true,
17+
},
18+
],
19+
},
20+
};
21+
22+
export default config;

package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "trunk-analytics-uploader",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest"
8+
},
9+
"devDependencies": {
10+
"@eslint/js": "^9.16.0",
11+
"@types/eslint__js": "^8.42.3",
12+
"@types/jest": "^29.5.14",
13+
"@types/node": "^22.7.9",
14+
"eslint": "^9.16.0",
15+
"eslint-plugin-jest": "^28.9.0",
16+
"jest": "^29.7.0",
17+
"jest-junit": "^16.0.0",
18+
"ts-jest": "^29.2.5",
19+
"ts-node": "^10.9.2",
20+
"typescript": "^5.7.2",
21+
"typescript-eslint": "^8.18.0"
22+
}
23+
}

0 commit comments

Comments
 (0)