Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/assets/.gitkeep

This file was deleted.

134 changes: 134 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Code Quality

on:
push:
paths:
- "codemods/**/*.js"
- "codemods/**/*.ts"
- "codemods/**/*.tsx"
- "codemods/**/*.jsx"
- "codemods/**/codemod.yaml"
- "codemods/**/workflow.yaml"
- "codemods/**/package.json"
- "codemods/**/package-lock.json"
- "codemods/**/tests/**"
- "package.json"
- "package-lock.json"
- "tsconfig.json"
- "biome.jsonc"
- ".github/workflows/code-quality.yml"
pull_request:
paths:
- "codemods/**/*.js"
- "codemods/**/*.ts"
- "codemods/**/*.tsx"
- "codemods/**/*.jsx"
- "codemods/**/codemod.yaml"
- "codemods/**/workflow.yaml"
- "codemods/**/package.json"
- "codemods/**/package-lock.json"
- "codemods/**/tests/**"
- "package.json"
- "package-lock.json"
- "tsconfig.json"
- "biome.jsonc"
- ".github/workflows/code-quality.yml"
types:
- opened
- ready_for_review
- reopened
- synchronize

permissions:
contents: read

jobs:
lint-and-types:
name: Lint & types
runs-on: ubuntu-slim

if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}

steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
show-progress: false

- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
cache: "npm"
node-version: "lts/*"

- run: npm ci
- run: node --run check
- run: node --run typecheck

test:
name: Before/After tests
runs-on: ${{ matrix.os }}

if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}

strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
with:
egress-policy: audit

- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
show-progress: false

- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
cache: "npm"
node-version: "lts/*"

- run: npm ci

- name: Run tests related to changes
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
base_sha="${{ github.event.pull_request.base.sha }}"
elif [[ "${{ github.event.before }}" =~ ^0+$ ]]; then
base_sha="$(git merge-base origin/${{ github.event.repository.default_branch }} HEAD)"
else
base_sha="${{ github.event.before }}"
fi

changed_paths="$(git diff --name-only "$base_sha" "${{ github.sha }}")"

# Run everything when shared configuration or workflow behavior changes.
if echo "$changed_paths" | grep -qE '^(package(-lock)?\.json|tsconfig\.json|biome\.jsonc|\.github/workflows/code-quality\.yml)$'; then
npm run test --workspaces --if-present
exit 0
fi

codemod_paths="$(echo "$changed_paths" | grep '^codemods/' || true)"
workspaces="$(
echo "$codemod_paths" \
| cut -d/ -f1,2 \
| sort -u \
| sed 's/^/--workspace=/'
)"

if [[ -z "$workspaces" ]]; then
echo "No codemod workspaces changed; skipping before/after tests."
exit 0
fi

npm run test --if-present $workspaces
9 changes: 4 additions & 5 deletions .github/workflows/codemod-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,11 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 22
node-version: 'lts/*'

- name: Install project dependencies
run: |
npm install --no-frozen-lockfile
npm install -g codemod@latest
npm ci

# Run test before login to not waste time if it fails
- name: Validate workflow
Expand All @@ -191,12 +190,12 @@ jobs:
- name: Install codemod dependencies
if: steps.check-package-json.outputs.has-package-json == 'true'
working-directory: ${{ steps.find-codemod.outputs.codemod-path }}
run: npm install --no-frozen-lockfile
run: npm ci

- name: Run javascript ast-grep codemod Tests
if: steps.check-package-json.outputs.has-package-json == 'true'
working-directory: ${{ steps.find-codemod.outputs.codemod-path }}
run: npm test
run: node --run test

- name: Publish codemod
uses: codemod/publish-action@v1
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Thanks for helping users adopt the latest features with your codemods!
cd /path/to/sample/project
npx codemod workflow run -w /path/to/my-codemod/workflow.yaml
```

### Project Layout

- Place all codemods in the `codemods/` directory.
Expand Down
6 changes: 0 additions & 6 deletions _typecheck.ts

This file was deleted.

8 changes: 7 additions & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{"$schema":"https://biomejs.dev/schemas/2.4.4/schema.json","files":{"includes":["."]},"formatter":{"enabled":true,"lineWidth":100},"linter":{"enabled":true},"javascript":{"formatter":{"quoteStyle":"double"}}}
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": { "includes": ["**", "!**/package-lock.json", "!codemods/**/tests"] },
"formatter": { "enabled": true, "lineWidth": 100 },
"linter": { "enabled": true },
"javascript": { "formatter": { "quoteStyle": "double" } }
}
2 changes: 0 additions & 2 deletions codemods/.gitkeep

This file was deleted.

1 change: 1 addition & 0 deletions codemods/sample-codemod/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ author: "Codemod Authors"
license: "MIT"
workflow: "workflow.yaml"
category: "migration"
repository: "https://github.com/codemod/migrations-template/tree/main/codemods/sample-codemod"
targets:
languages: ["typescript"]
keywords: ["react", "upgrade", "standardization", "performance"]
Expand Down
2 changes: 1 addition & 1 deletion codemods/sample-codemod/codemod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ author: "Codemod Authors"
license: "MIT"
workflow: "workflow.yaml"
category: "migration"

repository: "https://github.com/codemod/migrations-template/tree/main/codemods/sample-codemod"
targets:
languages: ["typescript"]

Expand Down
45 changes: 0 additions & 45 deletions codemods/sample-codemod/package-lock.json

This file was deleted.

23 changes: 10 additions & 13 deletions codemods/sample-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"name": "sample-codemod",
"version": "0.1.0",
"description": "Move React components defined inside other components to module scope",
"type": "module",
"scripts": {
"test": "npx codemod@latest jssg test -l tsx ./scripts/codemod.ts",
"check-types": "tsc --noEmit"
},
"devDependencies": {
"@codemod.com/jssg-types": "latest",
"@jssg/utils": "latest",
"typescript": "latest"
}
"name": "sample-codemod",
"version": "0.1.0",
"description": "Move React components defined inside other components to module scope",
"type": "module",
"scripts": {
"test": "npx codemod@latest jssg test -l tsx ./scripts/codemod.ts"
},
"devDependencies": {
"@jssg/utils": "latest"
}
}
Loading
Loading