From 932cdbfbc41a25c75aa19b10c8f7aa2df1eb9b7a Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 09:32:35 +0000 Subject: [PATCH] refactor(ci): move metadata suggestions into a dedicated composite action Move scripts/suggestMetaData.mts to .github/actions/suggest-metadata and wrap it in a composite action with explicit inputs. The workflow now uses the local action; package.json scripts point to the new location. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MThCx7cVXV3XWfo5C327Ci --- .github/actions/suggest-metadata/action.yml | 33 +++++++++++++++++++ .../suggest-metadata}/suggestMetaData.mts | 5 +-- .../pull-request-metadata-suggestions.yml | 14 ++++---- package.json | 6 ++-- 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 .github/actions/suggest-metadata/action.yml rename {scripts => .github/actions/suggest-metadata}/suggestMetaData.mts (98%) diff --git a/.github/actions/suggest-metadata/action.yml b/.github/actions/suggest-metadata/action.yml new file mode 100644 index 000000000..fbd985d20 --- /dev/null +++ b/.github/actions/suggest-metadata/action.yml @@ -0,0 +1,33 @@ +name: Suggest icon metadata +description: Asks an OpenAI model for tags, categories and use-cases for changed icons in a pull request and posts them as review suggestions. + +inputs: + openai-api-key: + description: OpenAI API key used to generate the suggestions. + required: true + github-token: + description: "GitHub token with `pull-requests: write` permission to post the review." + required: true + pull-request-number: + description: Number of the pull request to review. + required: true + commit-sha: + description: Head commit SHA of the pull request the review comments are anchored to. + required: true + model: + description: OpenAI model used to generate the suggestions. + required: false + default: gpt-5-mini + +runs: + using: composite + steps: + - name: Generate metadata suggestions + shell: bash + run: node "$GITHUB_ACTION_PATH/suggestMetaData.mts" + env: + OPENAI_API_KEY: ${{ inputs.openai-api-key }} + GITHUB_TOKEN: ${{ inputs.github-token }} + PULL_REQUEST_NUMBER: ${{ inputs.pull-request-number }} + COMMIT_SHA: ${{ inputs.commit-sha }} + OPENAI_API_MODEL: ${{ inputs.model }} diff --git a/scripts/suggestMetaData.mts b/.github/actions/suggest-metadata/suggestMetaData.mts similarity index 98% rename from scripts/suggestMetaData.mts rename to .github/actions/suggest-metadata/suggestMetaData.mts index cf166b465..d2967fa3b 100644 --- a/scripts/suggestMetaData.mts +++ b/.github/actions/suggest-metadata/suggestMetaData.mts @@ -9,9 +9,10 @@ import { parseArgs } from "node:util"; import z from "zod"; // Resolve repo paths relative to this script so they work no matter which -// directory the script is invoked from (the workflow runs it from the repo root). +// directory the script is invoked from. The script lives in +// `.github/actions/suggest-metadata`, three levels below the repo root. const scriptDir = path.dirname(fileURLToPath(import.meta.url)); -const repoRoot = path.join(scriptDir, ".."); +const repoRoot = path.join(scriptDir, "../../.."); const iconsDir = path.join(repoRoot, "icons"); const categoriesDir = path.join(repoRoot, "categories"); const metadataInstructionsPath = path.join( diff --git a/.github/workflows/pull-request-metadata-suggestions.yml b/.github/workflows/pull-request-metadata-suggestions.yml index fc7341353..5af66854a 100644 --- a/.github/workflows/pull-request-metadata-suggestions.yml +++ b/.github/workflows/pull-request-metadata-suggestions.yml @@ -31,10 +31,10 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile - - name: Generate comment markup - run: node ./scripts/suggestMetaData.mts - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - PULL_REQUEST_NUMBER: ${{ github.event.number }} - COMMIT_SHA: ${{ github.event.pull_request.head.sha }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Suggest metadata + uses: ./.github/actions/suggest-metadata + with: + openai-api-key: ${{ secrets.OPENAI_API_KEY }} + github-token: ${{ secrets.GITHUB_TOKEN }} + pull-request-number: ${{ github.event.number }} + commit-sha: ${{ github.event.pull_request.head.sha }} diff --git a/package.json b/package.json index 8dc1296c1..58cfb2edb 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,9 @@ "generate:sponsors": "node scripts/updateSponsors.mts", "generate:contributors": "node ./scripts/updateContributors.mts icons/*.svg", "generate:nextJSAliases": "node ./scripts/generateNextJSAliases.mts", - "suggest:metadata": "node ./scripts/suggestMetaData.mts", - "suggest:metadata:debug": "node --env-file .env ./scripts/suggestMetaData.mts --debug", - "suggest:metadata:watch": "node --env-file .env --watch ./scripts/suggestMetaData.mts", + "suggest:metadata": "node ./.github/actions/suggest-metadata/suggestMetaData.mts", + "suggest:metadata:debug": "node --env-file .env ./.github/actions/suggest-metadata/suggestMetaData.mts --debug", + "suggest:metadata:watch": "node --env-file .env --watch ./.github/actions/suggest-metadata/suggestMetaData.mts", "postinstall": "husky", "lint:es": "eslint . --ignore-pattern 'icons/*.json' --ignore-pattern 'categories/*.json'", "lint:format": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --check",