Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add codemod publish workflow #50

Merged
merged 4 commits into from
Apr 9, 2025
Merged
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
108 changes: 108 additions & 0 deletions .github/workflows/codemod_publish.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Codemod publish

on:
workflow_dispatch:
push:
paths:
- "recipes/**"
- "codemods/**"
branches:
- main

permissions:
contents: read

jobs:
paths-filter:
permissions:
contents: read
pull-requests: read
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:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
id: filter
name: Filter codemods
with:
list-files: json
filters: |
codemods:
- '**/.codemodrc.json'

prepare-matrix:
name: Prepare matrix
runs-on: ubuntu-latest
needs: paths-filter
if: always() && needs.paths-filter.outputs.codemods == 'true'
outputs:
codemod_files: ${{ steps.set-matrix.outputs.codemod_files }}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf
with:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0

- name: Set matrix for codemods
id: set-matrix
run: |
FILES_JSON=$(echo '${{ needs.paths-filter.outputs.codemods_files }}' | jq -c '{include: map({file: .})}')
echo "codemod_files=$FILES_JSON" >> "$GITHUB_OUTPUT"
echo "Matrix JSON: $FILES_JSON"

publish:
name: Publish ${{ matrix.file }}
runs-on: ubuntu-latest
needs: prepare-matrix
strategy:
fail-fast: false
matrix: ${{fromJson(needs.prepare-matrix.outputs.codemod_files)}}
env:
CODEMOD_API_KEY: ${{ secrets.CODEMOD_API_KEY }}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf
with:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0

- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e
with:
node-version-file: ".nvmrc"

- name: Install dependencies
run: |
sudo apt-get install libsecret-1-dev
npm install -g codemod

- name: Test codemod
run: |
DIR=$(dirname "${{ matrix.file }}")
echo "Testing codemod in: $DIR"
cd "$DIR"
npm install
npm run --if-present test

- name: Publish codemod
run: |
DIR=$(dirname "${{ matrix.file }}")
echo "Publishing codemod in: $DIR"
cd "$DIR"
npx codemod publish