Add platform label

This commit is contained in:
Jarred Sumner
2024-06-14 14:51:52 -07:00
parent 48cefe14bd
commit bcc2289ddb
2 changed files with 95 additions and 0 deletions

39
.github/workflows/labeled.yml vendored Normal file
View File

@@ -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 }}

56
scripts/read-issue.ts Normal file
View File

@@ -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");
}