Skip to content

Commit

Permalink
Ianjennings/dynamic-context (#40)
Browse files Browse the repository at this point in the history
* use trigger event context

* build

* better log

* build

* build

* try again for better sha of workflow_run

* try workflow_run call

* more debug

* update syntax

* remove pra
  • Loading branch information
ianjennings authored Jan 24, 2025
1 parent bb03cc2 commit d286334
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test PRa
name: Test PR
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/workflow_run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on:
workflow_run:
workflows:
- setup
types:
- completed

jobs:
test-job:
name: Test Step
runs-on: ubuntu-latest
steps:
- run: env
- uses: ./
with:
prompt: |
1. open youtube
os: windows
prerun: |
cd $env:TEMP
npm init -y
npm install dashcam-chrome
Start-Process "C:/Program Files/Google/Chrome/Application/chrome.exe" -ArgumentList "--start-maximized","--load-extension=$(pwd)/node_modules/dashcam-chrome/build"
exit
key: ${{ secrets.DASHCAM_WORKSPACE_API }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FORCE_COLOR: "3"
12 changes: 12 additions & 0 deletions .github/workflows/workflow_setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: setup

on:
- pull_request
- push

jobs:
preflight-job:
name: Preflight Step
runs-on: ubuntu-latest
steps:
- run: env
51 changes: 43 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ formatters.O = function (v) {

/***/ }),

/***/ 8818:
/***/ 7404:
/***/ ((module) => {

"use strict";
Expand Down Expand Up @@ -1058,7 +1058,7 @@ function plural(ms, msAbs, n, name) {

const os = __nccwpck_require__(2037);
const tty = __nccwpck_require__(6224);
const hasFlag = __nccwpck_require__(8818);
const hasFlag = __nccwpck_require__(7404);

const {env} = process;

Expand Down Expand Up @@ -8414,7 +8414,7 @@ function removeHook(state, name, method) {

/***/ }),

/***/ 3040:
/***/ 8818:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

"use strict";
Expand Down Expand Up @@ -34824,6 +34824,7 @@ function wrappy (fn, cb) {

const core = __nccwpck_require__(2186);
const github = __nccwpck_require__(5438);
const chalk = __nccwpck_require__(8818);

class Config {
constructor() {
Expand All @@ -34847,6 +34848,40 @@ class Config {
prTitle: createPR ? core.getInput("pr-title") : "",
prTestFilename: createPR ? core.getInput("pr-test-filename") : "",
};

let branchInfo = () => {


let sha = github.context.sha;
let ref = github.context.ref;
let context = '';

if (github.context.event_name == "workflow_run") {
context = 'workflow_run';
sha = github.context.event.workflow_run.pull_requests[0].head.sha;
ref = github.context.event.workflow_run.pull_requests[0].head.ref;
} else if (github.context.payload?.pull_request) {
context = 'pull_request';
sha = github.context.payload.pull_request.head.sha;
ref = github.context.payload.pull_request.head.ref;
} else {
context = 'default'
sha = github.context.sha;
ref = github.context.ref;
}

let res = {sha, ref, context};

console.log("");
console.log(chalk.green("Context"));
console.log(chalk.yellow("method:"), context);
console.log(chalk.yellow("ref:"), ref);
console.log(chalk.yellow("sha:"), sha);

return res;
}

let {sha, ref, context} = branchInfo();

// the values of github.context.repo.owner and github.context.repo.repo are taken from
// the environment variable GITHUB_REPOSITORY specified in "owner/repo" format and
Expand All @@ -34857,9 +34892,8 @@ class Config {
issueNumber: github.context.issue.number,
branch: github.context.ref,
token: github.context.token || github.token,
sha: github.context.payload?.pull_request?.head.sha || github.context.sha,
head_ref: github.context.head_ref,
ref: github.context.ref,
sha,
ref,
workflow: github.context.workflow,
run_id: github.context.runId
};
Expand Down Expand Up @@ -41162,7 +41196,7 @@ var __webpack_exports__ = {};
const core = __nccwpck_require__(2186);
const config = __nccwpck_require__(4570);
const axios = __nccwpck_require__(8757);
const chalk = __nccwpck_require__(3040);
const chalk = __nccwpck_require__(8818);
const { getOctokit } = __nccwpck_require__(5438);

(__nccwpck_require__(2437).config)();
Expand Down Expand Up @@ -41228,6 +41262,7 @@ axios.interceptors.response.use(
let prTitle = config.input.prTitle;
let prTestFilename = config.input.prTestFilename;

console.log(chalk.green("Version"));
console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);

Expand Down Expand Up @@ -41447,7 +41482,7 @@ axios.interceptors.response.use(
replayUrl: extractedFromMarkdown,
instructions: prompt,
repo: repo,
branch: config.githubContext.head_ref || config.githubContext.ref,
branch: config.githubContext.ref,
commit: config.githubContext.sha,
platform: os,
success: isPassed,
Expand Down
40 changes: 37 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require("@actions/core");
const github = require("@actions/github");
const chalk = require("chalk");

class Config {
constructor() {
Expand All @@ -23,6 +24,40 @@ class Config {
prTitle: createPR ? core.getInput("pr-title") : "",
prTestFilename: createPR ? core.getInput("pr-test-filename") : "",
};

let branchInfo = () => {


let sha = github.context.sha;
let ref = github.context.ref;
let context = '';

if (github.context.event_name == "workflow_run") {
context = 'workflow_run';
sha = github.context.event.workflow_run.pull_requests[0].head.sha;
ref = github.context.event.workflow_run.pull_requests[0].head.ref;
} else if (github.context.payload?.pull_request) {
context = 'pull_request';
sha = github.context.payload.pull_request.head.sha;
ref = github.context.payload.pull_request.head.ref;
} else {
context = 'default'
sha = github.context.sha;
ref = github.context.ref;
}

let res = {sha, ref, context};

console.log("");
console.log(chalk.green("Context"));
console.log(chalk.yellow("method:"), context);
console.log(chalk.yellow("ref:"), ref);
console.log(chalk.yellow("sha:"), sha);

return res;
}

let {sha, ref, context} = branchInfo();

// the values of github.context.repo.owner and github.context.repo.repo are taken from
// the environment variable GITHUB_REPOSITORY specified in "owner/repo" format and
Expand All @@ -33,9 +68,8 @@ class Config {
issueNumber: github.context.issue.number,
branch: github.context.ref,
token: github.context.token || github.token,
sha: github.context.payload?.pull_request?.head.sha || github.context.sha,
head_ref: github.context.head_ref,
ref: github.context.ref,
sha,
ref,
workflow: github.context.workflow,
run_id: github.context.runId
};
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ axios.interceptors.response.use(
let prTitle = config.input.prTitle;
let prTestFilename = config.input.prTestFilename;

console.log(chalk.green("Version"));
console.log(`testdriver@${pgkVersion}`);
console.log(`testdriver-action@${testdriverBranch}`);

Expand Down Expand Up @@ -286,7 +287,7 @@ axios.interceptors.response.use(
replayUrl: extractedFromMarkdown,
instructions: prompt,
repo: repo,
branch: config.githubContext.head_ref || config.githubContext.ref,
branch: config.githubContext.ref,
commit: config.githubContext.sha,
platform: os,
success: isPassed,
Expand Down

0 comments on commit d286334

Please sign in to comment.