Skip to content

Commit d18be26

Browse files
committed
WIP: post
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent a8e9972 commit d18be26

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

.github/workflows/test-post.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Test
2+
on:
3+
push:
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
fail: ['true', 'false']
12+
steps:
13+
- uses: actions/checkout@v5
14+
- uses: ./check-run
15+
- name: Do${{ matrix.fail == 'false' && ' not' || '' }} fail
16+
run: set -x && exit ${{ matrix.fail == 'false' && '0' || '1' }}

check-run/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ inputs:
3838
conclusion:
3939
description: 'If set, the Check Run will be marked as completed'
4040
default: ''
41+
job-status:
42+
description: 'Needed at the end of the job'
43+
default: ${{ job.status }}
4144
outputs:
4245
check-run-id:
4346
description: 'The ID of the created or updated Check Run'
4447
runs:
4548
using: 'node20'
4649
main: './index.js'
50+
post: './post.js'
4751
branding:
4852
icon: 'git-commit'
4953
color: 'orange'

check-run/post.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
async function run() {
2+
const { CIHelper } = await import("../dist/index.js")
3+
4+
try {
5+
const ci = new CIHelper()
6+
ci.setupGitHubAction({ createOrUpdateCheckRun: "post" })
7+
} catch (e) {
8+
console.error(e)
9+
process.exitCode = 1
10+
}
11+
}
12+
13+
run()

lib/ci-helper.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class CIHelper {
116116
needsUpstreamBranches?: boolean;
117117
needsMailToCommitNotes?: boolean;
118118
createGitNotes?: boolean;
119-
createOrUpdateCheckRun?: boolean;
119+
createOrUpdateCheckRun?: boolean | "post";
120120
}): Promise<void> {
121121
// configure the Git committer information
122122
process.env.GIT_CONFIG_PARAMETERS = [
@@ -158,7 +158,9 @@ export class CIHelper {
158158
console.log("Using debug SMTP options:", this.smtpOptions);
159159
}
160160

161-
if (setupOptions?.createOrUpdateCheckRun) return await this.createOrUpdateCheckRun();
161+
if (setupOptions?.createOrUpdateCheckRun) {
162+
return await this.createOrUpdateCheckRun(setupOptions.createOrUpdateCheckRun === "post");
163+
}
162164

163165
// help dugite realize where `git` is...
164166
const gitExecutable = os.type() === "Windows_NT" ? "git.exe" : "git";
@@ -358,7 +360,16 @@ export class CIHelper {
358360

359361
protected static validateConclusion = typia.createValidate<ConclusionType>();
360362

361-
protected async createOrUpdateCheckRun(): Promise<void> {
363+
protected async createOrUpdateCheckRun(runPost: boolean): Promise<void> {
364+
if (process.env.GITGITGADGET_DRY_RUN) {
365+
if (!runPost) {
366+
core.saveState("check-run-id", "123456");
367+
} else {
368+
console.log(`saved state: ${core.getState("check-run-id")}`);
369+
}
370+
console.log(JSON.stringify(process.env, null, 2));
371+
return;
372+
}
362373
const { owner, repo, pull_number } = getPullRequestOrCommentKeyFromURL(core.getInput("pr-url"));
363374
let check_run_id = ((id?: string) => (!id ? undefined : Number.parseInt(id, 10)))(
364375
core.getInput("check-run-id"),

0 commit comments

Comments
 (0)