Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: TEST

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
compile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
g++ -Wall -Wextra -o test source.cpp > compilation.log 2>&1
- uses: actions/upload-artifact@v4
with:
name: compilation_log
path: compilation.log
- run: ./test

test:
needs:
- compile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- run: npm run build
- uses: actions/download-artifact@v4
with:
name: compilation_log
- run: node dist/index.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 9 additions & 0 deletions source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

[[nodiscard]] int func() { return 42; }

int main() {
int unused_variable = 42;
func();
std::cout << "Hello, World!" << std::endl;
}
36 changes: 9 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
import { Octokit } from "@octokit/action";
import { readFileSync } from "fs";

// if the action is triggered by not a pull request, exit
if (!process.env.GITHUB_REF?.startsWith("refs/pull/")) {
console.log("Not a pull request, exiting.");
process.exit(0);
}

const octokit = new Octokit();

const [owner, repo] = process.env.GITHUB_REPOSITORY?.split("/")!;
const pull_request_number = parseInt(process.env.GITHUB_REF?.split("/")[2]!);

const { data: pullRequest } = await octokit.rest.pulls.get({
owner,
repo,
pull_number: pull_request_number,
});

const { data: actions } = await octokit.rest.actions.listWorkflowRunsForRepo({
owner,
repo,
});

const workflow_runs = actions.workflow_runs.filter((action) => {
return (
action.head_branch === pullRequest.head.ref &&
action.head_sha === pullRequest.head.sha &&
action.status === "completed"
);
});

const latest = workflow_runs.reduce((latest, action) => {
if (!latest) return action;
return new Date(action.created_at) > new Date(latest.created_at)
? action
: latest;
});
const compilation_output = readFileSync("compilation.log");

octokit.rest.issues.createComment({
owner,
repo,
issue_number: pull_request_number,
body: `The latest workflow run for this pull request is [#${latest.run_number}](${latest.html_url})`,
body: `compilation output is:\n\n\`\`\`\n${compilation_output}\n\`\`\``,
});