Skip to content

Commit f6fcd0d

Browse files
authored
ci: publish to codemod (#76)
Signed-off-by: Sebastian Beltran <[email protected]>
1 parent 46e7fc5 commit f6fcd0d

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

.github/workflows/publish.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
# For more information see: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow
4+
5+
name: Publish Codemod
6+
7+
on:
8+
push:
9+
tags:
10+
- "v*@*" # eg: v1.0.0@codemod-name
11+
workflow_dispatch:
12+
inputs:
13+
tag:
14+
description: "Tag to publish (format: v1.0.0@codemod-name)"
15+
required: true
16+
type: string
17+
18+
jobs:
19+
validate-and-publish:
20+
name: Validate and Publish Codemod
21+
environment: publish
22+
runs-on: ubuntu-latest
23+
24+
outputs:
25+
version: ${{ steps.parse-tag.outputs.version }}
26+
codemod-name: ${{ steps.parse-tag.outputs.codemod-name }}
27+
codemod-path: ${{ steps.parse-tag.outputs.codemod-path }}
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Parse tag and extract metadata
36+
id: parse-tag
37+
env:
38+
EVENT_NAME: ${{ github.event_name }}
39+
INPUT_TAG: ${{ github.event.inputs.tag }}
40+
GITHUB_REF: ${{ github.ref }}
41+
run: |
42+
# Determine the tag based on trigger type
43+
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
44+
TAG="$INPUT_TAG"
45+
echo "Using manually provided tag: $TAG"
46+
else
47+
TAG="${GITHUB_REF#refs/tags/}"
48+
echo "Using pushed tag: $TAG"
49+
fi
50+
51+
# Validate tag format
52+
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+@[a-zA-Z0-9_-]+$ ]]; then
53+
echo "❌ Invalid tag format: $TAG"
54+
echo "Expected format: v1.0.0@codemod-name"
55+
exit 1
56+
fi
57+
58+
# Extract components
59+
VERSION="${TAG%@*}" # Everything before @
60+
VERSION="${VERSION#v}" # Remove v prefix
61+
CODEMOD_NAME="${TAG#*@}" # Everything after @
62+
CODEMOD_PATH="recipes/$CODEMOD_NAME"
63+
64+
# Set outputs
65+
echo "version=$VERSION" >> $GITHUB_OUTPUT
66+
echo "codemod-name=$CODEMOD_NAME" >> $GITHUB_OUTPUT
67+
echo "codemod-path=$CODEMOD_PATH" >> $GITHUB_OUTPUT
68+
69+
- name: Verify codemod directory
70+
env:
71+
CODEMOD_PATH: ${{ steps.parse-tag.outputs.codemod-path }}
72+
run: |
73+
if [[ ! -d "$CODEMOD_PATH" ]]; then
74+
echo "❌ Codemod directory not found: $CODEMOD_PATH"
75+
echo "Available directories in recipes/:"
76+
ls -lah recipes/ || echo "No recipes directory found"
77+
exit 1
78+
fi
79+
80+
echo "✓ Found codemod directory: $CODEMOD_PATH"
81+
echo "Directory contents:"
82+
ls -lah "$CODEMOD_PATH"
83+
84+
- name: Setup Node.js environment
85+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
86+
with:
87+
cache: npm
88+
cache-dependency-path: package-lock.json
89+
90+
# We don't use dev dependencies
91+
# But we need npm to put local workspace in `node_modules`
92+
# so codemod can bundle workspaces in the codemod tarball correctly
93+
- name: Install project dependencies
94+
run: npm ci
95+
96+
# Run test before login to not waste time if it fails
97+
- name: Run codemod Tests
98+
working-directory: ${{ steps.parse-tag.outputs.codemod-path }}
99+
run: node --run test
100+
101+
- name: Authenticate with Codemod registry
102+
env:
103+
CODEMOD_TOKEN: ${{ secrets.CODEMOD_TOKEN }}
104+
run: npx codemod login --api-key "$CODEMOD_TOKEN"
105+
106+
- name: Publish codemod
107+
working-directory: ${{ steps.parse-tag.outputs.codemod-path }}
108+
run: npx codemod publish
109+
110+
- name: Create release summary
111+
env:
112+
CODEMOD_NAME: ${{ steps.parse-tag.outputs.codemod-name }}
113+
VERSION: ${{ steps.parse-tag.outputs.version }}
114+
TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
115+
TRIGGER: ${{ github.event_name == 'workflow_dispatch' && 'Manual' || 'Tag Push' }}
116+
ACTOR: ${{ github.triggering_actor }}
117+
run: |
118+
cat >> $GITHUB_STEP_SUMMARY << EOF
119+
# 🚀 Codemod Publication Summary
120+
121+
**Codemod:** \`$CODEMOD_NAME\`
122+
**Version:** \`$VERSION\`
123+
**Tag:** \`$TAG\`
124+
**Trigger:** $TRIGGER by $ACTOR
125+
126+
✅ Codemod has been successfully published to the registry!
127+
EOF

recipes/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)