diff --git a/.github/actions/reports-group/codacy-uploader-action/action.yml b/.github/actions/reports-group/codacy-uploader-action/action.yml index 45348508..af354a90 100644 --- a/.github/actions/reports-group/codacy-uploader-action/action.yml +++ b/.github/actions/reports-group/codacy-uploader-action/action.yml @@ -79,7 +79,7 @@ runs: - name: Upload to codacy id: upload # Temporarily rely on internal fork, waiting for updates to be merges on original action - uses: yoanm/codacy-coverage-reporter-action@e8bf406ddc38eb22a7d302eb1d20df5090d36da1 + uses: yoanm/codacy-coverage-reporter-action@d641c0af7ba34e9ddd18422ca95827100307ad71 with: coverage-reports: ${{ steps.build-uploader-options.outputs.coverage-reports }} project-token: ${{ inputs.project-token }} diff --git a/.github/actions/reports-group/fetch-workflow-metadata-action/action.yml b/.github/actions/reports-group/fetch-workflow-metadata-action/action.yml index a9a84ca3..f15887be 100644 --- a/.github/actions/reports-group/fetch-workflow-metadata-action/action.yml +++ b/.github/actions/reports-group/fetch-workflow-metadata-action/action.yml @@ -18,11 +18,21 @@ outputs: commit-sha: description: | Full commit SHA. + - `push` event => Branch where the push happened + - `pull_request` event => Head branch name + - `workflow_run` event => Commit upon which the triggering workflow has been executed (should match behaviors described on other cases then) + - Other events => Fallback on `github.sha` value + branch: + description: | + Branch name - `push` event => latest commit pushed - `pull_request` event => latest commit pushed on the pull request - - Other events => null + - `workflow_run` event => Branch where the triggering workflow has been executed (should match behaviors described on other cases then) + - Other events => Fallback on `github.ref` value if it's a branch ref, else the repository default branch is returned pull-request: description: Pull request number. Available only in case of `pull_request` event ! + is-pr-from-fork: + description: Weither PR head is outside of current repository. Obviously accurate 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: diff --git a/.github/actions/reports-group/fetch-workflow-metadata-action/index.js b/.github/actions/reports-group/fetch-workflow-metadata-action/index.js index a2ccc888..baffdb85 100644 --- a/.github/actions/reports-group/fetch-workflow-metadata-action/index.js +++ b/.github/actions/reports-group/fetch-workflow-metadata-action/index.js @@ -8,7 +8,9 @@ async function run() { core.setOutput('repository-owner', context.repositoryOwner); core.setOutput('repository-name', context.repositoryName); core.setOutput('commit-sha', context.commitSha); + core.setOutput('branch', context.branch); core.setOutput('pull-request', context.prNumber ?? null); // Ensure `null` rather than `undefined` (better/easier for end-user)! + core.setOutput('is-pr-from-fork', context.isPrFromFork); core.setOutput('workflow-name', context.workflowName); core.setOutput('run-id', context.runId); core.setOutput('server-url', context.serverUrl); diff --git a/.github/actions/reports-group/node-gha-helpers/src/current-workflow-context.js b/.github/actions/reports-group/node-gha-helpers/src/current-workflow-context.js index 045844da..45db5adc 100644 --- a/.github/actions/reports-group/node-gha-helpers/src/current-workflow-context.js +++ b/.github/actions/reports-group/node-gha-helpers/src/current-workflow-context.js @@ -1,9 +1,8 @@ -import {buildWorkflowRunUrl} from "./common"; - const {context: ghaContext} = require('@actions/github'); const {payload: ghaEvent} = ghaContext; const {isPullRequestEvent, isPushEvent} = require('./current-workflow-event'); +import {buildWorkflowRunUrl} from "./common"; /** * @type {GHAContextGetter} @@ -16,7 +15,9 @@ export const getContext = () => { repositoryOwner: ghaContext.repo.owner, repositoryName: ghaContext.repo.repo, commitSha: getCommitSha(), + branch: getBranch(), prNumber: prNumber, + isPrFromFork: isPRFromFork(), workflowName: getWorkflowName(), serverUrl: ghaContext.serverUrl, runId: runId, @@ -52,3 +53,21 @@ export const getWorkflowName = () => ghaContext.workflow; * @returns {string} */ export const getRunId = () => ghaContext.runId.toString(); + +/** + * @return {string} + */ +export const getBranch = () => { + if (isPullRequestEvent()) { + return ghaEvent.pull_request.head.ref; + } + + // In case ref is not a branch (e.g. a tag), fallback to repository default branch + return ghaEvent.ref.startsWith('refs/heads') ? ghaEvent.ref.replace('refs/heads/', '') : ghaEvent.repository.default_branch; +}; + + +/** + * @return {boolean} + */ +export const isPRFromFork = () => isPullRequestEvent() && ghaEvent.pull_request.head.repo.id === ghaEvent.pull_request.base.repo.id; diff --git a/.github/actions/reports-group/node-gha-helpers/src/interfaces.js b/.github/actions/reports-group/node-gha-helpers/src/interfaces.js index e3912860..591c2380 100644 --- a/.github/actions/reports-group/node-gha-helpers/src/interfaces.js +++ b/.github/actions/reports-group/node-gha-helpers/src/interfaces.js @@ -1,5 +1,5 @@ /** - * @typedef {{repositoryOwner: string, repositoryName: string, commitSha: string, prNumber: number|undefined, workflowName: string, runId: string, workflowRunUrl: string}} GHAContext + * @typedef {{repositoryOwner: string, repositoryName: string, commitSha: string, branch: string, prNumber: number|undefined, isPrFromFork: boolean, workflowName: string, runId: string, workflowRunUrl: string}} GHAContext */ /** * @typedef {() => GHAContext} GHAContextGetter diff --git a/.github/actions/reports-group/node-gha-helpers/src/workflow-run-context.js b/.github/actions/reports-group/node-gha-helpers/src/workflow-run-context.js index 64b85775..485e7057 100644 --- a/.github/actions/reports-group/node-gha-helpers/src/workflow-run-context.js +++ b/.github/actions/reports-group/node-gha-helpers/src/workflow-run-context.js @@ -15,7 +15,9 @@ export const getContext = () => { repositoryOwner: ghaContext.repo.owner, repositoryName: ghaContext.repo.repo, commitSha: getCommitSha(), + branch: getBranch(), prNumber: prNumber, + isPrFromFork: isPRFromFork(), workflowName: getWorkflowName(), serverUrl: ghaContext.serverUrl, runId: runId, @@ -42,3 +44,13 @@ export const getWorkflowName = () => ghaEvent.workflow.name; * @returns {string} */ export const getRunId = () => ghaEvent.workflow_run.id.toString(); + +/** + * @return {string} + */ +export const getBranch = () => ghaEvent.workflow_run.head_branch; + +/** + * @return {boolean} + */ +export const isPRFromFork = () => isPullRequestEvent() && ghaEvent.workflow_run.head_repository.id === ghaEvent.workflow_run.repository.id; diff --git a/.github/workflows/coverage-upload.yml b/.github/workflows/coverage-upload.yml index 4cec2f16..3e3b27fe 100644 --- a/.github/workflows/coverage-upload.yml +++ b/.github/workflows/coverage-upload.yml @@ -22,6 +22,7 @@ jobs: - uses: ./custom-action-repo/.github/actions/reports-group/attach-check-run-to-triggering-workflow-action with: + name: "Fetch coverage info" github-token: ${{ github.token }} job-status: ${{ job.status }} fails-on-triggering-workflow-failure: true @@ -51,6 +52,10 @@ jobs: artifacts-pattern: coverage-groups-* run-id: ${{ needs.fetch-info.outputs.run-id }} override-commit: ${{ needs.fetch-info.outputs.commit-sha }} + override-branch: ${{ needs.fetch-info.outputs.branch }} + override-pr: ${{ needs.fetch-info.outputs.pr-number }} + override-build: ${{ needs.fetch-info.outputs.run-id }} + override-build-url: ${{ needs.fetch-info.outputs.run-url }} permissions: contents: read checks: write # For the check run creation !