Merge pull request #15 from codemod/testing-2 #11
This file contains hidden or 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: Auto-publish Codemods | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'recipes/**' | |
| - '.github/workflows/auto-publish.yml' | |
| - 'scripts/auto-publish.mjs' | |
| jobs: | |
| auto-publish: | |
| runs-on: ubuntu-latest | |
| environment: production | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 # Need previous commit for diff | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Check if auto-publishing is configured | |
| id: check-config | |
| run: | | |
| if [ -z "${{ secrets.CODEMOD_API_KEY }}" ]; then | |
| echo "configured=false" >> $GITHUB_OUTPUT | |
| echo "⚠️ Auto-publishing is disabled: No CODEMOD_API_KEY secret configured" | |
| echo " To enable auto-publishing, set up your API key:" | |
| echo " 1. Get API key from https://app.codemod.com/api-keys" | |
| echo " 2. Add CODEMOD_API_KEY as a GitHub secret" | |
| echo " 3. Optionally set CODEMOD_REGISTRY_SCOPE and CODEMOD_REGISTRY_URL as variables" | |
| else | |
| echo "configured=true" >> $GITHUB_OUTPUT | |
| echo "✅ Auto-publishing is configured and enabled" | |
| fi | |
| - name: Auto-publish codemods | |
| if: steps.check-config.outputs.configured == 'true' | |
| run: node scripts/auto-publish.mjs | |
| env: | |
| CODEMOD_API_KEY: ${{ secrets.CODEMOD_API_KEY }} | |
| CODEMOD_REGISTRY_SCOPE: ${{ vars.CODEMOD_REGISTRY_SCOPE || 'codemod' }} | |
| CODEMOD_REGISTRY_URL: ${{ vars.CODEMOD_REGISTRY_URL || 'https://registry.codemod.com' }} | |
| - name: Commit version updates | |
| if: steps.check-config.outputs.configured == 'true' && success() | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add recipes/*/codemod.yaml | |
| git commit -m "chore: auto-bump versions for published codemods [skip ci]" | |
| git push | |
| fi |