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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,99 +1,9 @@
const github = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
const {getOctokit} = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
const core = require('@actions/core');

const {GITHUB_REPOSITORY, RUNNER_NAME} = process.env;
const {GITHUB_REPOSITORY} = process.env;

/**
* @returns {number|undefined}
*/
function guessTriggeringPrNumber() {
if ('pull_request' === github.context.eventName) {
return github.context.payload.number;
} else if ('workflow_run' === github.context.eventName && 'pull_request' === github.context.payload.workflow_run.event) {
return github.context.payload.workflow_run.pull_requests[0]?.number;
}

return undefined;
}

/**
* @returns {string|undefined}
*/
function guessTriggeringCommitSha() {
if ('pull_request' === github.context.eventName) {
return github.context.payload.pull_request.head.sha;
}
if ('push' === github.context.eventName) {
return github.context.payload.after;
}
if ('workflow_run' === github.context.eventName && ['pull_request', 'push'].includes(github.context.payload.workflow_run.event)) {
return github.context.payload.workflow_run.head_sha;
}

throw new Error('Unable to guess the commit SHA !');
}

/**
* @returns {string}
*/
function guessTriggeringWorkflowName() {
if ('workflow_run' === github.context.eventName) {
return github.context.payload.workflow.name;
}

return github.context.workflow;
}

/**
* @returns {string}
*/
function guessTriggeringRunId() {
if ('workflow_run' === github.context.eventName) {
return github.context.payload.workflow.id.toString();
}

return github.context.runId.toString();
}

/**
* @returns {Promise<Record<string, any>|undefined>}
*/
async function retrieveCurrentJob(octokit, owner, repo, runId) {
const jobList = await getWorkflowJobsForRunId(octokit, owner, repo, runId);
core.info('TMP DEBUG jobsForCurrentWorkflow=' + JSON.stringify(jobList));
const candidateList = [];
for (const job of jobList) {
if (RUNNER_NAME === job.runner_name && 'in_progress' === job.status) {
candidateList.push(job);
}
}
if (candidateList.length === 0) {
core.info('Unable to retrieve the current job !');
return undefined;
}
if (candidateList.length > 1) {
core.warning(
'Multiple running jobs rely on runners with the same name, unable to retrieve the current job !'
+ '\nCandidates: ' + Object.entries(candidateList).map(([k, v]) => v.name + '(' + k + ')').join(', ')
);
return undefined;
}

return candidateList.shift();
}

async function getWorkflowJobsForRunId(octokit, owner, repo, runId) {
return octokit.paginate(
'GET /repos/{owner}/{repo}/actions/runs/{run_id}/jobs',
{
//filter: 'latest',
// Url path parameters
owner: owner,
repo: repo,
run_id: runId
}
);
}
const ghaHelpers = require('../node-gha-helpers');

async function run() {
/** INPUTS **/
Expand All @@ -102,60 +12,43 @@ async function run() {
const checkName = core.getInput('name');

const isSuccessfulJobAsOfNow = 'success' === jobStatus;
const octokit = github.getOctokit(githubToken);
const octokit = getOctokit(githubToken);

const requestParams = await core.group(
'Build API params',
async () => {
const repoInfo = github.context.repo;
const triggeringWorkflowRunId = guessTriggeringRunId();
core.info('TMP DEBUG context=' + JSON.stringify(github.context));
//const jobsForCurrentWorkflow = await getWorkflowJobsForRunId(octokit, repoInfo.owner, repoInfo.repo, github.context.runId);
//core.info('TMP DEBUG jobsForCurrentWorkflow=' + JSON.stringify(jobsForCurrentWorkflow));
//const jobsForTriggeringWorkflow = await getWorkflowJobsForRunId(octokit, repoInfo.owner, repoInfo.repo, triggeringWorkflowRunId);
//core.info('TMP DEBUG jobsForTriggeringWorkflow=' + JSON.stringify(jobsForTriggeringWorkflow));
core.info('TMP DEBUG GITHUB_ACTION=' + process.env.GITHUB_ACTION);
core.info('TMP DEBUG GITHUB_ACTION_PATH=' + process.env.GITHUB_ACTION_PATH);
core.info('TMP DEBUG GITHUB_ACTION_REPOSITORY=' + process.env.GITHUB_ACTION_REPOSITORY);
core.info('TMP DEBUG GITHUB_JOB=' + process.env.GITHUB_JOB);
core.info('TMP DEBUG GITHUB_RUN_ATTEMPT=' + process.env.GITHUB_RUN_ATTEMPT);
core.info('TMP DEBUG GITHUB_WORKFLOW=' + process.env.GITHUB_WORKFLOW);
core.info('TMP DEBUG GITHUB_WORKFLOW_REF=' + process.env.GITHUB_WORKFLOW_REF);
core.info('TMP DEBUG RUNNER_ARCH=' + process.env.RUNNER_ARCH);
core.info('TMP DEBUG RUNNER_NAME=' + process.env.RUNNER_NAME);
core.info('TMP DEBUG RUNNER_OS=' + process.env.RUNNER_OS);
const currentJob = await retrieveCurrentJob(octokit, repoInfo.owner, repoInfo.repo, github.context.runId);
core.info('TMP DEBUG CURRENT JOB=' + JSON.stringify(currentJob));
const commitSha = guessTriggeringCommitSha();
const currentWorkflowContext = ghaHelpers.getContext();
const triggeringWorkflowContext = ghaHelpers.triggeringWorkflow.getContext();
if (!triggeringWorkflowContext.commitSha) {
throw new Error('Unable to guess the commit SHA !');
}
const currentJob = await ghaHelpers.fetchCurrentJob(octokit);

const startedAt = (new Date()).toISOString();
const prNumber = guessTriggeringPrNumber();
//const originalWorkflowName = guessTriggeringWorkflowName();
const currentWorkflowName = github.context.workflow;
const outputTitle = '🔔 ' + currentWorkflowName;
const prLink = (undefined !== prNumber ? '?pr=' + prNumber : '');
const currentWorkflowUrl = github.context.serverUrl + '/' + GITHUB_REPOSITORY + '/actions/runs/' + github.context.runId.toString() + prLink;
const prLink = (undefined !== triggeringWorkflowContext.prNumber ? '?pr=' + triggeringWorkflowContext.prNumber : '');
const currentWorkflowUrl = currentWorkflowContext.serverUrl + '/' + GITHUB_REPOSITORY + '/actions/runs/' + currentWorkflowContext.runId + prLink;
const outputSummary = '🪢 Check added by '
+ (currentJob ? '<a href="' + currentJob.html_url + prLink + '" target="blank">**' + currentJob.name + '**</a>' : '')
+ (currentJob ? ' (' : '') + '<a href="' + currentWorkflowUrl + '" target="blank">**' + currentWorkflowName + '** workflow</a>' + (currentJob ? ')' : '')
+ (currentJob ? ' (' : '') + '<a href="' + currentWorkflowUrl + '" target="blank">**' + currentWorkflowContext.workflowName + '** workflow</a>' + (currentJob ? ')' : '')
;

return {
name: checkName ? checkName : (currentJob?.name ?? currentWorkflowName + ' Check run'),
head_sha: commitSha,
name: !!checkName ? checkName : (currentJob?.name ?? currentWorkflowContext.workflowName + ' Check run'),
head_sha: triggeringWorkflowContext.commitSha,
//details_url: detailsUrl,
external_id: triggeringWorkflowRunId?.toString(),
external_id: triggeringWorkflowContext.runId,
status: isSuccessfulJobAsOfNow ? 'in_progress' : 'completed',
output: {
title: outputTitle,
title: '🔔 ' + currentWorkflowContext.workflowName,
summary: outputSummary,
},
// Conclusion
conclusion: isSuccessfulJobAsOfNow ? undefined : jobStatus,
started_at: startedAt,
completed_at: isSuccessfulJobAsOfNow ? undefined : startedAt,
// Url path parameters
owner: repoInfo.owner,
repo: repoInfo.repo
owner: currentWorkflowContext.repositoryOwner,
repo: currentWorkflowContext.repositoryName
};
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/** -diff linguist-generated=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.yarn
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
22 changes: 22 additions & 0 deletions .github/actions/reports-group/fetch-workflow-metadata/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: install
install:
yarn install

.PHONY: build
build: install package

.PHONY: package
package:
rm -Rf dist/* && ./node_modules/.bin/ncc build index.js --minify --source-map --license LICENSE --out dist

.PHONY: lint
lint:
./node_modules/.bin/eslint index.js

.PHONY: test
test:
echo "Error: no test specified"
exit 1

get-action-nodejs-version: ## Display node version configured on action.yml
@grep -E "using:\s*'?node" action.yml | sed -e "s/^.*using: '*node\([0-9][0-9]\)'*.*$$/\1/"
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: TODO
description: TODO

inputs:
from-triggering-workflow:
description: |
Weither to look for triggering workflow context or just current workflow context (default `true`).
- True: In case current workflow event is `workflow_run`, the context of the workflow which **triggered** the current one will be returned.
- False: Return the context for the current workflow.
default: 'true'

outputs:
commit-sha:
description: |
Full commit SHA.
- `push` event => latest commit pushed
- `pull_request` event => latest commit pushed on the pull request
- Other events => null
pull-request:
description: Pull request number. Available only in case of `pull_request` event !
workflow-name:
description: Name of the workflow, either current one or the triggering one (based on `from-triggering-workflow` value).
run-id:
description: Workflow run ID, either current one or the triggering one (based on `from-triggering-workflow` value).


runs:
using: 'node20'
main: 'dist/index.js'
Empty file.
Loading