From d15563f93bb36c8557cacf028bafc7fd2bb5e988 Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Thu, 7 Sep 2023 17:39:42 +0100 Subject: [PATCH] Misc workflows: fix quotes in bash (#5235) --- .github/workflows/approved-for-ci-run.yml | 2 +- .github/workflows/build_and_test.yml | 2 +- scripts/comment-test-report.js | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/approved-for-ci-run.yml b/.github/workflows/approved-for-ci-run.yml index 9e9a46b354..bcd042e608 100644 --- a/.github/workflows/approved-for-ci-run.yml +++ b/.github/workflows/approved-for-ci-run.yml @@ -74,7 +74,7 @@ jobs: Feel free to review/comment/discuss the original PR #${PR_NUMBER}. EOF - ALREADY_CREATED="$(gh pr --repo '${GITHUB_REPOSITORY}' list --head '${HEAD}' --base 'main' --json 'number' --jq '.[].number')" + ALREADY_CREATED="$(gh pr --repo ${GITHUB_REPOSITORY} list --head ${HEAD} --base main --json number --jq '.[].number')" if [ -z "${ALREADY_CREATED}" ]; then gh pr --repo "${GITHUB_REPOSITORY}" create --title "CI run for PR #${PR_NUMBER}" \ --body-file "body.md" \ diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 88fd5a7d7c..bd57d5bd5a 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -36,7 +36,7 @@ jobs: if [ "${{ contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) }}" = "true" ]; then MESSAGE="Please create a PR from a branch of ${GITHUB_REPOSITORY} instead of a fork" else - MESSAGE="The PR should be reviewed and labelled with `approved-for-ci-run` to trigger a CI run" + MESSAGE="The PR should be reviewed and labelled with 'approved-for-ci-run' to trigger a CI run" fi echo >&2 "We don't run CI for PRs from forks" diff --git a/scripts/comment-test-report.js b/scripts/comment-test-report.js index 92a016e053..ce92534dea 100755 --- a/scripts/comment-test-report.js +++ b/scripts/comment-test-report.js @@ -205,20 +205,22 @@ const parseCoverageSummary = async ({ summaryJsonUrl, coverageUrl, fetch }) => { } module.exports = async ({ github, context, fetch, report, coverage }) => { + // If we run the script in the PR or in the branch (main/release/...) + const isPullRequest = !!context.payload.pull_request // Which PR to comment (for ci-run/pr-* it will comment the parent PR, not the ci-run/pr-* PR) let prToComment - const branchName = context.payload.pull_request.base.ref.replace(/^refs\/heads\//, "") - const match = branchName.match(/^ci-run\/pr-(?\d+)$/)?.groups - if (match) { - ({ prNumber } = match) - prToComment = parseInt(prNumber, 10) - } else { - prToComment = context.payload.number + if (isPullRequest) { + const branchName = context.payload.pull_request.base.ref.replace(/^refs\/heads\//, "") + const match = branchName.match(/ci-run\/pr-(?\d+)/)?.groups + if (match) { + ({ prNumber } = match) + prToComment = parseInt(prNumber, 10) + } else { + prToComment = context.payload.number + } } // Marker to find the comment in the subsequent runs const startMarker = `` - // If we run the script in the PR or in the branch (main/release/...) - const isPullRequest = !!context.payload.pull_request // Latest commit in PR or in the branch const commitSha = isPullRequest ? context.payload.pull_request.head.sha : context.sha // Let users know that the comment is updated automatically