diff --git a/.github/workflows/labeled.yml b/.github/workflows/labeled.yml new file mode 100644 index 0000000000..ed5c9ce0d3 --- /dev/null +++ b/.github/workflows/labeled.yml @@ -0,0 +1,39 @@ +name: Issue Labeled +env: + BUN_VERSION: 1.1.13 + +on: + issues: + types: [labeled] + +jobs: + reply-labeled: + runs-on: ubuntu-latest + if: github.event.label.name == 'crash' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + sparse-checkout: | + scripts + .github + - name: Setup Bun + uses: ./.github/actions/setup-bun + with: + bun-version: ${{ env.BUN_VERSION }} + - name: "add platform and command label" + id: add-labels + env: + GITHUB_ISSUE_BODY: ${{ github.event.issue.body }} + GITHUB_ISSUE_TITLE: ${{ github.event.issue.title }} + shell: bash + run: | + LABELS=$(bun scripts/read-issue.ts) + echo "labels=$LABELS" >> $GITHUB_OUTPUT + - name: Add labels + uses: actions-cool/issues-helper@v3 + with: + actions: 'add-labels' + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.issue.number }} + labels: ${{ steps.add-labels.outputs.labels }} diff --git a/scripts/read-issue.ts b/scripts/read-issue.ts new file mode 100644 index 0000000000..a0cfc26101 --- /dev/null +++ b/scripts/read-issue.ts @@ -0,0 +1,56 @@ +const body = process.env.GITHUB_ISSUE_BODY; + +if (!body) { + throw new Error("GITHUB_ISSUE_BODY must be set"); +} + +const labels: string[] = []; +let command = ""; +if (body.includes("[TestCommand]")) { + command = "jest"; +} else if (body.includes("[BuildCommand]")) { + command = "bundler"; +} else if (body.includes("[InstallCommand]") || body.includes("[AddCommand]") || body.includes("[RemoveCommand]")) { + command = "npm"; +} + +let featuresLine = ""; +const featuresI = body.indexOf("\nFeatures: "); +const featuresEndI = body.indexOf("\n", featuresI + 1); +if (featuresI > -1 && featuresEndI > -1) { + featuresLine = body.slice(featuresI + 1, featuresEndI).trim(); +} + +const features = featuresLine.split(" ").map(a => a.trim().toLowerCase()); + +if (features.includes("jsc")) { + labels.push("runtime"); +} + +if (features.includes("shell")) { + labels.push("shell"); +} + +const lines = body.split("\n"); +for (const line of lines) { + if (line.startsWith("Bun v") && line.includes(" on ")) { + const onI = line.indexOf(" on "); + const onI2 = line.indexOf("\n", onI + 1); + const on = line + .slice(onI + 4, onI2 > -1 ? onI2 : undefined) + .trim() + .toLowerCase(); + + if (on.includes("macos") || on.includes("darwin")) { + labels.push("macos"); + } else if (on.includes("linux")) { + labels.push("linux"); + } else if (on.includes("windows") || on.includes("nt")) { + labels.push("windows"); + } + } +} + +if (labels.length > 0) { + console.write(labels.join(",") + "\n"); +}