Skip to content

Merge branch 'main' of https://github.com/tinyBigGAMES/libLLVM #4

Merge branch 'main' of https://github.com/tinyBigGAMES/libLLVM

Merge branch 'main' of https://github.com/tinyBigGAMES/libLLVM #4

name: Push → Discussion
on:
push:
branches: ['**']
workflow_dispatch: {} # allows manual run for testing
permissions:
contents: read
discussions: write
env:
DISCUSSIONS_CATEGORY: Push Updates # must match the category name in Discussions
jobs:
post:
runs-on: ubuntu-latest
steps:
- name: Create a discussion for this push
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const desiredName = (process.env.DISCUSSIONS_CATEGORY || "").trim();
// 1) Fetch categories
let categories;
try {
const res = await github.request(
"GET /repos/{owner}/{repo}/discussions/categories",
{ owner, repo }
);
categories = res.data || [];
} catch (e) {
core.setFailed(`Failed to fetch categories: ${e.message}`);
return;
}
// 2) Find category
const category = categories.find(
c => c.name.toLowerCase() === desiredName.toLowerCase()
);
if (!category) {
const names = categories.map(c => `- ${c.name} (id: ${c.id})`).join("\n");
core.setFailed(
`Category "${desiredName}" not found.\nAvailable categories:\n${names}`
);
return;
}
// 3) Build discussion content
const push = context.payload;
const branch = (push.ref || "").replace("refs/heads/", "") || "(unknown)";
const pusher = push.pusher?.name || push.sender?.login || "unknown";
const commits = push.commits || [];
const commitCount = commits.length;
const title = `Push to ${branch} by ${pusher} — ${commitCount} commit${commitCount === 1 ? "" : "s"}`;
const lines = commits.map(c => {
const sha7 = (c.id || "").slice(0,7);
const first = (c.message || "").split("\n")[0];
const author = c.author?.name || "unknown";
return `- [\`${sha7}\`](${c.url}) ${first} — _${author}_`;
});
const compareUrl =
push.compare ||
`https://github.com/${owner}/${repo}/compare/${push.before}...${push.after}`;
const body = [
`> _This discussion was created automatically by GitHub Actions from a \`push\` event._`,
"",
`**Branch:** \`${branch}\``,
`**Pusher:** ${pusher}`,
`**Compare:** ${compareUrl}`,
"",
"### Commits",
lines.length ? lines.join("\n") : "_No commit details available._",
"",
"<sub>— end of automated log —</sub>"
].join("\n");
// 4) Create the discussion
try {
const { data: discussion } = await github.request(
"POST /repos/{owner}/{repo}/discussions",
{ owner, repo, title, body, category_id: category.id }
);
core.info(`Created discussion: ${discussion.html_url}`);
} catch (e) {
core.setFailed(`Failed to create discussion: ${e.message}`);
}