diff --git a/.github/actions/generate-pr-title/action.yml b/.github/actions/generate-pr-title/action.yml new file mode 100644 index 000000000..869a0ef13 --- /dev/null +++ b/.github/actions/generate-pr-title/action.yml @@ -0,0 +1,38 @@ +name: Generate PR title +description: Generates a conventional-commit title for a pull request from the files it adds and changes. + +inputs: + added-files: + description: Space-separated list of files the pull request adds. + required: true + changed-files: + description: Space-separated list of all files the pull request changes (added, modified, renamed and deleted). + required: true + current-title: + description: Current title of the pull request. + required: true + +outputs: + title: + description: The new title, or an empty string when no change is needed. + value: ${{ steps.generate.outputs.title }} + +runs: + using: composite + steps: + - name: Generate PR title + id: generate + shell: bash + # The inputs are passed through `env` rather than inlined into the script, + # because the current title is written by the PR author. + run: | + NEW_TITLE="$(node "$GITHUB_ACTION_PATH/generatePullRequestTitle.mts")" + { + echo "title<> "$GITHUB_OUTPUT" + env: + ADDED_FILES: ${{ inputs.added-files }} + CHANGED_FILES: ${{ inputs.changed-files }} + CURRENT_TITLE: ${{ inputs.current-title }} diff --git a/scripts/generatePullRequestTitle.mts b/.github/actions/generate-pr-title/generatePullRequestTitle.mts similarity index 95% rename from scripts/generatePullRequestTitle.mts rename to .github/actions/generate-pr-title/generatePullRequestTitle.mts index 03c014116..f2c88f9c0 100644 --- a/scripts/generatePullRequestTitle.mts +++ b/.github/actions/generate-pr-title/generatePullRequestTitle.mts @@ -6,11 +6,11 @@ * for icon contributions and, for every other kind of PR, inserts or updates the * conventional-commit scope so `lint-pr-title` is satisfied. * - * It follows the convention of `generateChangedIconsCommentMarkup.mts`: it reads - * its input from the environment, prints the result to stdout and has no other - * side effects. It only imports Node built-ins and the shared - * `conventional-commit-types.json` (a native JSON import), so Node can still run - * it natively as an `.mts` file without a `pnpm install` step. + * It runs as the `generate-pr-title` composite action: it reads its input from + * the environment, prints the result to stdout and has no other side effects. + * It only imports Node built-ins and the shared `conventional-commit-types.json` + * (a native JSON import), so Node can still run it natively as an `.mts` file + * without a `pnpm install` step. * * Env input (CLI wrapper at the bottom): * - `ADDED_FILES_FILE`: path to a newline-separated list of added files, or @@ -26,7 +26,7 @@ import { readFileSync } from 'node:fs'; // Single source of truth for the conventional-commit types, shared with // `lint-pr-title` (amannn/action-semantic-pull-request). -import VALID_TYPES from '../.github/conventional-commit-types.json' with { type: 'json' }; +import VALID_TYPES from '../../conventional-commit-types.json' with { type: 'json' }; // Default type used in prefix mode when the current title has no valid type. // The path reliably tells us the scope but nothing about whether a change is a diff --git a/scripts/generatePullRequestTitle.test.mts b/.github/actions/generate-pr-title/generatePullRequestTitle.test.mts similarity index 100% rename from scripts/generatePullRequestTitle.test.mts rename to .github/actions/generate-pr-title/generatePullRequestTitle.test.mts diff --git a/.github/actions/generate-pr-title/package.json b/.github/actions/generate-pr-title/package.json new file mode 100644 index 000000000..12e9069a6 --- /dev/null +++ b/.github/actions/generate-pr-title/package.json @@ -0,0 +1,10 @@ +{ + "name": "@lucide/generate-pr-title-action", + "private": true, + "type": "module", + "description": "GitHub action that generates a conventional-commit title for a pull request from the files it changes", + "scripts": { + "start": "node ./generatePullRequestTitle.mts", + "test": "node --test *.test.mts" + } +} diff --git a/.github/workflows/generate-pr-title.yml b/.github/workflows/generate-pr-title.yml index 0e70e0462..1aad2189b 100644 --- a/.github/workflows/generate-pr-title.yml +++ b/.github/workflows/generate-pr-title.yml @@ -48,25 +48,19 @@ jobs: - name: Generate PR title id: generate - run: | - NEW_TITLE="$(node ./scripts/generatePullRequestTitle.mts)" - { - echo "new_title<> "$GITHUB_OUTPUT" - env: - ADDED_FILES: ${{ steps.changed-files.outputs.added_files }} - CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_and_modified_files }} - CURRENT_TITLE: ${{ github.event.pull_request.title }} + uses: ./.github/actions/generate-pr-title + with: + added-files: ${{ steps.changed-files.outputs.added_files }} + changed-files: ${{ steps.changed-files.outputs.all_changed_and_modified_files }} + current-title: ${{ github.event.pull_request.title }} - name: Update PR title - if: steps.generate.outputs.new_title != '' + if: steps.generate.outputs.title != '' run: gh pr edit "$PR_NUMBER" --title "$NEW_TITLE" env: GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} - NEW_TITLE: ${{ steps.generate.outputs.new_title }} + NEW_TITLE: ${{ steps.generate.outputs.title }} # Runs after the title is generated: an edit made with `GITHUB_TOKEN` does not # trigger new workflow runs, so a separate workflow would lint the old title. diff --git a/package.json b/package.json index 24730dc19..f796e8441 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "test:integrations:vue": "pnpm --filter @lucide/vue build && pnpm -r --workspace-concurrency=1 --filter './integrations/lucide-vue/**' check", "test:integrations:svelte": "pnpm --filter @lucide/svelte build && pnpm -r --workspace-concurrency=1 --filter './integrations/lucide-svelte/**' check", "test:font": "pnpm --filter build-font test", - "test:scripts": "node --test scripts/*.test.mts", + "test:scripts": "pnpm --filter @lucide/generate-pr-title-action test", "lucide": "pnpm --filter lucide", "lucide-angular": "pnpm --filter lucide-angular", "lucide-react": "pnpm --filter lucide-react", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 320007392..93e2a3be7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -123,6 +123,8 @@ importers: specifier: ^18.1.0 version: 18.2.0 + .github/actions/generate-pr-title: {} + .github/actions/suggest-metadata: dependencies: '@octokit/rest':