diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b1d2a7d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,59 @@ +name: Publish to codemod registry + +on: + push: + branches: ["main"] + paths: ["recipes/**"] + pull_request: + types: [closed] + paths: ["recipes/**"] + branches: ["main"] + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: dorny/paths-filter@v3 + id: filter + name: Filter codemods + with: + list-files: shell + filters: | + codemods: + - '**/.codemodrc.json' + + - name: export files + run: | + echo "Modified files: ${{steps.filter.outputs.codemods_files}}" + echo "CODEMOD_FILES=${{steps.filter.outputs.codemods_files}}" >> $GITHUB_ENV + echo "Modified status: ${{steps.filter.outputs.codemods}}" + echo "CODEMOD_STATUS=${{steps.filter.outputs.codemods}}" >> $GITHUB_ENV + + - uses: actions/setup-node@v4 + with: + node-version: node + cache: 'npm' + - name: Install "codemod" binary + run: npm install codemod + + - name: Run publish codemod + run: | + if [ -n "$CODEMOD_STATUS" ]; then + echo "Modified files: $CODEMOD_FILES" + ROOT_DIR=$(pwd) + for FILE in $CODEMOD_FILES; do + DIR=$(dirname "$FILE") + echo "Checking codemod: $DIR" + cd "$ROOT_DIR/$DIR" + npx codemod publish + echo "Codemod published" + done + else + echo "No codemods found" + fi