Merge pull request #48 from codemod-com/fix_test_netlify-sdk/0.8.5/de… #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Codemod publish | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- "codemods/**" | |
branches: | |
- main | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: pnpm/action-setup@v4 | |
with: | |
version: 9 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Check prettier | |
uses: creyD/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
prettier_options: --check | |
- name: Install dependencies | |
run: pnpm install | |
- name: Run test | |
run: pnpm recursive run test | |
paths-filter: | |
name: Check for .codemodrc.json files changes | |
runs-on: ubuntu-latest | |
outputs: | |
codemods: ${{ steps.filter.outputs.codemods }} | |
codemods_files: ${{ steps.filter.outputs.codemods_files }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
name: Filter codemods | |
with: | |
list-files: json | |
filters: | | |
codemods: | |
- '**/.codemodrc.json' | |
publish: | |
runs-on: ubuntu-latest | |
needs: paths-filter | |
if: always() && needs.paths-filter.outputs.codemods == 'true' | |
env: | |
CODEMOD_API_KEY: ${{ secrets.CODEMOD_API_KEY }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: export files | |
run: | | |
echo "Modified files: ${{needs.paths-filter.outputs.codemods_files}}" | |
echo "Modified status: ${{needs.paths-filter.outputs.codemods}}" | |
echo "CODEMOD_STATUS=${{needs.paths-filter.outputs.codemods}}" >> $GITHUB_ENV | |
echo "${{needs.paths-filter.outputs.codemods}}" | |
if [ "${{needs.paths-filter.outputs.codemods}}" == 'true' ]; then | |
echo "CODEMOD_FILES=${{needs.paths-filter.outputs.codemods_files}}" >> $GITHUB_ENV | |
else | |
echo "CODEMOD_FILES=$(find codemods -name '.codemodrc.json' -type f -exec echo -n '\"{}\" ' \;)" >> $GITHUB_ENV | |
fi | |
- uses: pnpm/action-setup@v4 | |
with: | |
version: 9 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: pnpm install -g codemod | |
- name: Run publish codemod | |
run: | | |
echo "Modified files: $CODEMOD_FILES" | |
ROOT_DIR=$(pwd) | |
if [[ "$CODEMOD_FILES" == *"["* ]]; then | |
# Handle array format | |
# Use IFS to handle spaces in filenames | |
IFS=',' read -ra FILES <<< "$(echo "$CODEMOD_FILES" | tr -d '[]')" | |
for FILE in "${FILES[@]}"; do | |
CLEANED_PATH="${FILE//[\'\"]}" | |
DIR=$(dirname "$CLEANED_PATH") | |
echo "Checking codemod: $DIR" | |
cd "$ROOT_DIR/$DIR" | |
pnpm install | |
npx codemod publish || true | |
done | |
else | |
# Handle single file format | |
CLEANED_PATH="${CODEMOD_FILES//[\'\"]}" | |
DIR=$(dirname "$CLEANED_PATH") | |
echo "Checking codemod: $DIR" | |
cd "$ROOT_DIR/$DIR" | |
pnpm install | |
npx codemod publish || true | |
fi |