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
11 changes: 11 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changesets

This folder is used by [Changesets](https://github.com/changesets/changesets) to manage versioning and changelogs for the codemods in this repository.

To add a changeset, run:

```
pnpm changeset
```

Then follow the prompts to select which codemod(s) changed and the type of version bump.
15 changes: 15 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [],
"privatePackages": {
"version": true,
"tag": true
}
}
204 changes: 195 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,209 @@
name: CI

on:
push:
pull_request:
branches:
- main
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
checks:
pull-request:
name: Pull request checks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0

- uses: pnpm/action-setup@v4
with:
version: 9.14.2
- uses: actions/setup-node@v4

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 20
node-version-file: '.nvmrc'
cache: pnpm

- run: pnpm install --frozen-lockfile

- name: Get changed files
id: changed
run: |
files=$(git diff --name-only --diff-filter=ACMR origin/main...HEAD | tr '\n' ' ')
echo "files=$files" >> "$GITHUB_OUTPUT"

- name: Get changed codemod package dirs
id: codemods
run: |
roots=""
for f in $(git diff --name-only origin/main...HEAD -- 'codemods/' || true); do
[ -z "$f" ] && continue
d=$(dirname "$f")
while [ "$d" != "." ] && [ "$d" != "/" ]; do
if [ -f "$d/package.json" ] && [[ "$d" == codemods/* ]]; then
roots="${roots}"$'\n'"$d"
break
fi
parent=$(dirname "$d")
[ "$parent" = "$d" ] && break
d=$parent
done
done
dirs=$(printf '%s\n' "$roots" | sort -u | grep -v '^$' | tr '\n' ' ')
echo "dirs=$dirs" >> "$GITHUB_OUTPUT"

- name: Format check (changed files)
if: steps.changed.outputs.files != ''
run: pnpm run format:check ${{ steps.changed.outputs.files }}

- name: Lint (changed files)
if: steps.changed.outputs.files != ''
run: pnpm run lint ${{ steps.changed.outputs.files }}

- name: Test (changed codemods)
if: steps.codemods.outputs.dirs != ''
run: |
for dir in ${{ steps.codemods.outputs.dirs }}; do
(cd "$dir" && pnpm test)
done

- name: Typecheck (changed codemods)
if: steps.codemods.outputs.dirs != ''
run: |
for dir in ${{ steps.codemods.outputs.dirs }}; do
(cd "$dir" && pnpm run check-types)
done

push-verify:
name: Full workspace (main)
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- uses: pnpm/action-setup@v4
with:
version: 9.14.2

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm

- run: pnpm install --frozen-lockfile
- run: pnpm run test
- run: pnpm run check-types
- run: pnpm run ci

changeset-check:
name: Changeset Check
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0

- uses: pnpm/action-setup@v4
with:
version: 9.14.2

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm

- run: pnpm install --frozen-lockfile

- name: Check for changeset
env:
SKIP_LABEL: skip-changeset
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
run: |
changed_dirs=""
for f in $(git diff --name-only --diff-filter=ACMR origin/main...HEAD -- 'codemods/' | grep -v '/tests/' || true); do
[ -z "$f" ] && continue
d=$(dirname "$f")
while [ "$d" != "." ] && [ "$d" != "/" ]; do
if [ -f "$d/package.json" ] && [[ "$d" == codemods/* ]]; then
changed_dirs="${changed_dirs}"$'\n'"$d"
break
fi
parent=$(dirname "$d")
[ "$parent" = "$d" ] && break
d=$parent
done
done
changed_dirs=$(printf '%s\n' "$changed_dirs" | sort -u | grep -v '^$')

if [ -z "$changed_dirs" ]; then
echo "No codemod source files changed. Changeset not required."
exit 0
fi

changed_packages=""
for dir in $changed_dirs; do
if [ -f "$dir/package.json" ]; then
pkg=$(node -p "require('./$dir/package.json').name")
changed_packages="$changed_packages $pkg"
fi
done
changed_packages=$(echo "$changed_packages" | xargs)

if [ -z "$changed_packages" ]; then
echo "Changed directories have no package.json. Changeset not required."
exit 0
fi

echo "Changed packages:"
echo "$changed_packages" | tr ' ' '\n'

if echo "$PR_LABELS" | grep -q "$SKIP_LABEL"; then
echo "skip-changeset label found. Skipping changeset requirement."
exit 0
fi

changeset_files=$(git diff --name-only --diff-filter=ACMR origin/main...HEAD -- '.changeset/*.md' \
| grep -v 'README.md' \
|| true)

covered_packages=""
for f in $changeset_files; do
pkgs=$(sed -n '/^---$/,/^---$/{ /^---$/d; s/['\''`]//g; s/:.*//; p; }' "$f")
covered_packages="$covered_packages $pkgs"
done
covered_packages=$(echo "$covered_packages" | xargs)

missing=""
for pkg in $changed_packages; do
if ! echo "$covered_packages" | grep -qw "$pkg"; then
missing="$missing $pkg"
fi
done
missing=$(echo "$missing" | xargs)

if [ -z "$missing" ]; then
echo "All changed packages have changesets."
exit 0
fi

echo "::error::Missing changeset for: $missing"
echo ""
echo "The following packages were changed but not covered by a changeset:"
for pkg in $missing; do
echo " - $pkg"
done
echo ""
echo "You have three options:"
echo " 1. Run 'pnpm changeset' to add a changeset covering the missing packages"
echo " 2. Add an empty changeset (no packages selected) if no version bump is needed"
echo " 3. Add the 'skip-changeset' label to this PR"
exit 1
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish Codemod (Manual)

on:
workflow_dispatch:
inputs:
codemod_path:
description: 'Path under codemods/ (e.g. apm/nodejs/dd-trace-js/v6/add-link-object-argument)'
required: true
type: string

permissions:
id-token: write
contents: read

jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- uses: pnpm/action-setup@v4
with:
version: 9.14.2

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm

- run: pnpm install --frozen-lockfile

- name: Publish codemod
uses: codemod/publish-action@dd6c8dbc5ceb1a6146feba41481d88b43da50024 # v1
with:
path: codemods/${{ inputs.codemod_path }}
114 changes: 114 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Release

on:
push:
branches:
- main

concurrency: release

permissions:
id-token: write
contents: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
changed_dirs: ${{ steps.tag.outputs.changed_dirs || '[]' }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
fetch-tags: true

- uses: pnpm/action-setup@v4
with:
version: 9.14.2

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm

- run: pnpm install --frozen-lockfile

- name: Check for pending changesets
id: check
run: |
changeset_files=$(find .changeset -name '*.md' ! -name 'README.md' 2>/dev/null || true)
if [ -z "$changeset_files" ]; then
echo "No pending changesets found. Skipping release."
echo "has_changesets=false" >> "$GITHUB_OUTPUT"
else
echo "Pending changesets found:"
echo "$changeset_files"
echo "has_changesets=true" >> "$GITHUB_OUTPUT"
fi

- name: Version packages
if: steps.check.outputs.has_changesets == 'true'
run: pnpm run version-packages

- name: Check for version changes
if: steps.check.outputs.has_changesets == 'true'
id: diff
run: |
if git diff --quiet; then
echo "No version changes produced. Skipping commit."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi

- name: Commit version bumps
if: steps.diff.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Version Packages"

- name: Push to main
if: steps.diff.outputs.has_changes == 'true'
run: |
git pull --rebase origin main
git push origin main

- name: Tag released versions
if: steps.diff.outputs.has_changes == 'true'
id: tag
run: bash scripts/tag-and-publish.sh

publish:
name: Publish ${{ matrix.dir }}
needs: release
if: needs.release.outputs.changed_dirs != '[]' && needs.release.outputs.changed_dirs != ''
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.release.outputs.changed_dirs) }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: main

- uses: pnpm/action-setup@v4
with:
version: 9.14.2

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: pnpm

- run: pnpm install --frozen-lockfile

- name: Publish codemod
uses: codemod/publish-action@dd6c8dbc5ceb1a6146feba41481d88b43da50024 # v1
with:
path: ${{ matrix.dir }}
Loading