Skip to content

Commit 0e987e4

Browse files
authored
Refactor CI for forked repositories - enhance (yoanm#116)
1 parent 337a447 commit 0e987e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+399
-354
lines changed

.github/actions/reports-group/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PKG_LIST := node-sdk find load-metadata create codecov-uploader codacy-uploader attach-check-run-to-triggering-workflow-action
1+
PKG_LIST := node-gha-helpers node-sdk find-action load-metadata-action create-action codecov-uploader-action codacy-uploader-action attach-check-run-to-triggering-workflow-action fetch-workflow-metadata-action
22
TARGETS := configure install build package lint test
33

44
define FOR_EACH_PKG

.github/actions/reports-group/attach-check-run-to-triggering-workflow-action/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
name:
1111
description: Status check name. Default to current job name
1212
required: false
13+
fails-on-triggering-workflow-failure:
14+
description: If `true` and triggering workflow is not sucessfull (error, cancellation, etc), add the check and throw an error in order to stop ongoing job
15+
default: 'false'
1316

1417
outputs:
1518
check-run-id:

.github/actions/reports-group/attach-check-run-to-triggering-workflow-action/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/attach-check-run-to-triggering-workflow-action/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
const {getOctokit} = require('@actions/github'); // @TODO move to 'imports from' when moved to TS !
22
const core = require('@actions/core');
33

4-
const {GITHUB_REPOSITORY} = process.env;
5-
64
const ghaHelpers = require('../node-gha-helpers');
75

6+
const formatMarkdownUrl = (title, link) => '<a href="' + link + '" target="blank">' + title + '</a>';
7+
88
async function run() {
99
/** INPUTS **/
1010
const githubToken = core.getInput('github-token', {required: true});
1111
const jobStatus = core.getInput('job-status', {required: true});
1212
const checkName = core.getInput('name');
13+
const failsOnTriggeringWorkflowFailure = core.getBooleanInput('fails-on-triggering-workflow-failure', {required: true});
1314

1415
const isSuccessfulJobAsOfNow = 'success' === jobStatus;
1516
const octokit = getOctokit(githubToken);
@@ -23,29 +24,28 @@ async function run() {
2324
throw new Error('Unable to guess the commit SHA !');
2425
}
2526
const currentJob = await ghaHelpers.fetchCurrentJob(octokit);
26-
2727
const startedAt = (new Date()).toISOString();
28-
const prLink = (undefined !== triggeringWorkflowContext.prNumber ? '?pr=' + triggeringWorkflowContext.prNumber : '');
29-
const currentWorkflowUrl = currentWorkflowContext.serverUrl + '/' + GITHUB_REPOSITORY + '/actions/runs/' + currentWorkflowContext.runId + prLink;
30-
const outputSummary = '🪢 Check added by '
31-
+ (currentJob ? '<a href="' + currentJob.html_url + prLink + '" target="blank">**' + currentJob.name + '**</a>' : '')
32-
+ (currentJob ? ' (' : '') + '<a href="' + currentWorkflowUrl + '" target="blank">**' + currentWorkflowContext.workflowName + '** workflow</a>' + (currentJob ? ')' : '')
33-
;
28+
const summaryRedirectMrkLink = formatMarkdownUrl(
29+
'**' + currentWorkflowContext.workflowName + (!currentJob ? '' : '** → **' + currentJob.name )+ '** ' + (!currentJob ? 'workflow' : 'job' ),
30+
!currentJob ? currentWorkflowContext.workflowRunUrl : ghaHelpers.buildWorkflowJobRunUrl(currentJob, triggeringWorkflowContext.prNumber)
31+
);
3432

3533
return {
3634
name: !!checkName ? checkName : (currentJob?.name ?? currentWorkflowContext.workflowName + ' Check run'),
3735
head_sha: triggeringWorkflowContext.commitSha,
38-
//details_url: detailsUrl,
39-
external_id: triggeringWorkflowContext.runId,
36+
started_at: startedAt,
37+
conclusion: isSuccessfulJobAsOfNow ? undefined : jobStatus,
38+
completed_at: isSuccessfulJobAsOfNow ? undefined : startedAt,
4039
status: isSuccessfulJobAsOfNow ? 'in_progress' : 'completed',
4140
output: {
4241
title: '🔔 ' + currentWorkflowContext.workflowName,
43-
summary: outputSummary,
42+
summary: '🪢 Check added by ' + summaryRedirectMrkLink,
4443
},
45-
// Conclusion
46-
conclusion: isSuccessfulJobAsOfNow ? undefined : jobStatus,
47-
started_at: startedAt,
48-
completed_at: isSuccessfulJobAsOfNow ? undefined : startedAt,
44+
external_id: triggeringWorkflowContext.runId,
45+
details_url: (!currentJob
46+
? currentWorkflowContext.workflowRunUrl
47+
: ghaHelpers.buildWorkflowJobRunUrl(currentJob, triggeringWorkflowContext.prNumber)
48+
),
4949
// Url path parameters
5050
owner: currentWorkflowContext.repositoryOwner,
5151
repo: currentWorkflowContext.repositoryName
@@ -62,9 +62,12 @@ async function run() {
6262

6363
core.setOutput('check-run-id', apiResponse.data.id);
6464
core.saveState('check-run-id', apiResponse.data.id); // In order to use it during POST hook
65-
if (true === isSuccessfulJobAsOfNow) {
65+
if (isSuccessfulJobAsOfNow) {
6666
core.saveState('check-run-already-concluded', 'yes'); // In order to use it during POST hook
6767
}
68+
if (failsOnTriggeringWorkflowFailure && !isSuccessfulJobAsOfNow) {
69+
core.setFailed('Triggering workflow status is "' + jobStatus + '" !');
70+
}
6871
}
6972

7073
run();
File renamed without changes.

.github/actions/reports-group/codacy-uploader/action.yml renamed to .github/actions/reports-group/codacy-uploader-action/action.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ inputs:
88
project-token:
99
description: Codacy project token for the repository
1010
required: true
11-
follow-symbolic-links:
12-
description: |
13-
Indicates whether to follow symbolic links when resolving `path`
14-
default: 'true'
1511
override-commit:
1612
description: |
17-
Commit to link to the uploaded reports.
18-
Default value:
19-
- `push` workflow: `github.sha`
20-
- `pull_request` workflow: `github.event.pull_request.head.sha`
21-
- `workflow_run` workflow triggered by a `pull_request` or `push` workflow: `github.event.workflow_run.head_sha`
22-
default: "${{ ('workflow_run' == github.event_name && ('pull_request' == github.event.workflow_run.event || 'push' == github.event.workflow_run.event) && github.event.workflow_run.head_sha) || ('pull_request' == github.event_name && github.event.pull_request.head.sha) || ('push' == github.event_name && github.sha) || null }}"
13+
Force the commit SHA linked to the uploaded reports.
14+
Mostly useful for specific cases (e.g. `workflow_run` workflow).
15+
required: false
16+
follow-symbolic-links:
17+
description: Indicates whether to follow symbolic links when resolving `path`
18+
default: 'false'
2319

2420
outputs:
2521
groups:
@@ -36,16 +32,14 @@ runs:
3632
- name: Validate inputs
3733
uses: actions/github-script@v7
3834
env:
39-
INPUT_MAP: ${{ toJson(inputs) }}
35+
INPUT_PATH: ${{ inputs.path }}
36+
INPUT_PROJECT-TOKEN: ${{ inputs.project-token }}
4037
with:
4138
script: |
42-
return core.group(
43-
'Validate inputs',
44-
async () => Object.entries(JSON.parse(process.env.INPUT_MAP))
45-
.forEach(([key, val]) => {
46-
if (!val.trim()) { throw new Error(`Input required and not supplied: ${key}`); }
47-
})
48-
);
39+
core.info('Validate inputs');
40+
41+
core.getInput('path', {required: true});
42+
core.getInput('project-token', {required: true});
4943
5044
# @TODO move actions to a dedicated repo and remove the checkout
5145
- uses: actions/checkout@v4
@@ -54,15 +48,13 @@ runs:
5448

5549
- name: Load groups metadata
5650
id: load-metadata
57-
uses: ./custom-action-repo/.github/actions/reports-group/load-metadata
51+
uses: ./custom-action-repo/.github/actions/reports-group/load-metadata-action
5852
with:
5953
path: ${{ inputs.path }}
6054
format: string # String in order to concatenate interesting values
6155
glue-string: ',' # Ensure glue string as it's the expected one by the uploader
6256
follow-symbolic-links: ${{ inputs.follow-symbolic-links }}
6357

64-
# @TODO Use bash instead and rely on JQ ?
65-
# Or create an *internal* action (not published on marketplace and stored inside this action repo) taking metadata JSON as input and returning each property the uploader has ?
6658
- name: Build uploader option
6759
id: build-uploader-options
6860
uses: actions/github-script@v7
File renamed without changes.

.github/actions/reports-group/codecov-uploader/action.yml renamed to .github/actions/reports-group/codecov-uploader-action/action.yml

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,46 @@ inputs:
88
token:
99
description: Codecov upload token
1010
required: true
11-
follow-symbolic-links:
12-
description: |
13-
Indicates whether to follow symbolic links when resolving `path`
14-
default: 'true'
1511
override-commit:
1612
description: |
17-
Commit to link to the uploaded reports.
18-
Default value:
19-
- `push` workflow: `github.sha`
20-
- `pull_request` workflow: `github.event.pull_request.head.sha`
21-
- `workflow_run` workflow triggered by a `pull_request` or `push` workflow: `github.event.workflow_run.head_sha`
22-
default: "${{ ('workflow_run' == github.event_name && ('pull_request' == github.event.workflow_run.event || 'push' == github.event.workflow_run.event) && github.event.workflow_run.head_sha) || ('pull_request' == github.event_name && github.event.pull_request.head.sha) || ('push' == github.event_name && github.sha) || null }}"
13+
Force the commit SHA linked to the uploaded reports.
14+
Mostly useful for specific cases (e.g. `workflow_run` workflow).
15+
16+
In case input is filled, `override-branch` input (as well as `override-pr` in case of `pull_request` event)
17+
should be filled too in order to keep consitency between values !
18+
required: false
2319
override-branch:
2420
description: |
25-
Branch to link to the uploaded reports.
26-
Default value:
27-
- `push` workflow: `github.ref_name` *if `github.ref_type` equals `branch`
28-
- `pull_request` workflow: `github.event.pull_request.head.ref`
29-
- `workflow_run` workflow triggered by a `pull_request` or `push` workflow: `github.event.workflow_run.head_branch`
30-
default: "${{ ('workflow_run' == github.event_name && ('pull_request' == github.event.workflow_run.event || 'push' == github.event.workflow_run.event) && github.event.workflow_run.head_branch) || ('pull_request' == github.event_name && github.event.pull_request.head.ref) || ('push' == github.event_name && 'branch' == github.ref_type && github.ref_name) || null }}"
21+
Force the branch linked to the uploaded reports.
22+
Mostly useful for specific cases (e.g. `workflow_run` workflow).
23+
24+
In case input is filled, `override-commit` input (as well as `override-pr` in case of `pull_request` event)
25+
should be filled too in order to keep consitency between values !
26+
required: false
3127
override-pr:
3228
description: |
33-
PR to link to the uploaded reports.
34-
Default value:
35-
- `pull_request` workflow: `github.event.number`
36-
- `workflow_run` workflow triggered by a `pull_request` workflow: `github.event.workflow_run.pull_requests[0].number`
37-
default: "${{ ( 'workflow_run' == github.event_name && 'pull_request' == github.event.workflow_run.event && github.event.workflow_run.pull_requests[0] && github.event.workflow_run.pull_requests[0].number) || ('pull_request' == github.event_name && github.event.number) || null }}"
38-
# commit-parent: # @TODO Not sure what it is (enable debug mode during upload to see what is actually sent by the uploader)
39-
# description: |
40-
# Parent commit to link to the uploaded reports. Most likely only useful for PR.
41-
# Default value:
42-
# - `pull_request` workflow: `github.event.number`
43-
# - `workflow_run` workflow triggered by a `pull_request` workflow: `github.event.workflow_run.pull_requests[0].number`
44-
# default: "${{ ('workflow_run' == github.event_name && ('pull_request' == github.event.workflow_run.event || 'push' == github.event.workflow_run.event) && github.event.workflow_run.head_branch) || ('pull_request' == github.event_name && github.event.pull_request.head.ref) || ('push' == github.event_name && github.sha) || null }}"
29+
Force the PR linked to the uploaded reports.
30+
Mostly useful for specific cases (e.g. `workflow_run` workflow triggered by a `pull_request` workflow).
31+
32+
In case input is filled, `override-commit` and `override-branch` inputs should be filled too in order
33+
to keep consitency between values !
34+
required: false
4535
override-build:
4636
description: |
47-
Workflow run to link to the uploaded reports
48-
Default value:
49-
- `workflow_run` workflow: `github.event.workflow_run.id`
50-
- Else: `github.run_id`
51-
default: "${{ ('workflow_run' == github.event_name && github.event.workflow_run.id) || github.run_id || null }}"
37+
Workflow run ID to link to the uploaded reports.
38+
Mostly useful for specific cases (e.g. `workflow_run` workflow).
39+
required: false
5240
override-build-url:
5341
description: |
54-
Workflow run url to link to the uploaded reports
55-
Default value:
56-
- `workflow_run` workflow: `github.event.workflow_run.id`
57-
- Else: `github.run_id`
58-
default: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ ('workflow_run' == github.event_name && github.event.workflow_run.id) || github.run_id }}"
42+
Workflow run url to link to the uploaded reports.
43+
Usually something like `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}` (based on GHA environment variables).
44+
Mostly useful for specific cases (e.g. `workflow_run` workflow).
45+
46+
In case input is filled, `override-build` input most likely need to be filled too in order to keep consitency between values !
47+
required: false
48+
follow-symbolic-links:
49+
description: Indicates whether to follow symbolic links when resolving `path`
50+
default: 'false'
5951

6052
outputs:
6153
groups:
@@ -78,18 +70,14 @@ runs:
7870
- name: Validate inputs
7971
uses: actions/github-script@v7
8072
env:
81-
INPUT_MAP: ${{ toJson(inputs) }}
73+
INPUT_PATH: ${{ inputs.path }}
74+
INPUT_TOKEN: ${{ inputs.token }}
8275
with:
8376
script: |
84-
return core.group(
85-
'Validate inputs',
86-
async () => Object.entries(JSON.parse(process.env.INPUT_MAP))
87-
.forEach(([key, val]) => {
88-
if (!key.startsWith('override-') && !val.trim()) {
89-
throw new Error(`Input required and not supplied: ${key}`);
90-
}
91-
})
92-
);
77+
core.info('Validate inputs');
78+
79+
core.getInput('path', {required: true});
80+
core.getInput('token', {required: true});
9381
9482
# @TODO move actions to a dedicated repo and remove the checkout
9583
- uses: actions/checkout@v4
@@ -98,15 +86,13 @@ runs:
9886

9987
- name: Load groups metadata
10088
id: load-metadata
101-
uses: ./custom-action-repo/.github/actions/reports-group/load-metadata
89+
uses: ./custom-action-repo/.github/actions/reports-group/load-metadata-action
10290
with:
10391
path: ${{ inputs.path }}
10492
format: string # String in order to concatenate interesting values
10593
glue-string: ',' # Ensure glue string as it's the expected one by the uploader
10694
follow-symbolic-links: ${{ inputs.follow-symbolic-links }}
10795

108-
# @TODO Use bash instead and rely on JQ ?
109-
# Or create an *internal* action (not published on marketplace and stored inside this action repo) taking metadata JSON as input and returning each property the uploader has ?
11096
- name: Build uploader option
11197
id: build-uploader-options
11298
uses: actions/github-script@v7
@@ -165,7 +151,7 @@ runs:
165151
const {REPORT_NAME, REPORT_FILES, REPORT_FLAGS, METADATA} = process.env;
166152
167153
const metadata = JSON.parse(METADATA);
168-
core.setOutput('group', metadata.path.split(',').join('\n')); // Trusted path as it comes from trusted metadata (=from `reports-group/load-metadata`)
154+
core.setOutput('groups', metadata.path.split(',').join('\n')); // Trusted path as it comes from trusted metadata (=from `reports-group/load-metadata`)
169155
core.setOutput('name', REPORT_NAME);
170156
core.setOutput('reports', REPORT_FILES.split(',').join('\n')); // Trusted path, see `build-uploader-options` step
171157
core.setOutput('flags', undefined !== REPORT_FLAGS ? REPORT_FLAGS.split(',').join('\n') : '');
File renamed without changes.

0 commit comments

Comments
 (0)