From 3cf24df3260069c10df0eb5fdb35622851f09cb0 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:51:30 -0400 Subject: [PATCH 1/2] fix(ci): address Sonar workflow findings --- .github/workflows/__call-common-lint.yml | 3 +- .../workflows/__mirror-github-to-gitlab.yml | 53 ++++++++++--------- tests/mirror-workflow.test.mjs | 33 ++++++++++++ 3 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 tests/mirror-workflow.test.mjs diff --git a/.github/workflows/__call-common-lint.yml b/.github/workflows/__call-common-lint.yml index d313fff5..66ef63e5 100644 --- a/.github/workflows/__call-common-lint.yml +++ b/.github/workflows/__call-common-lint.yml @@ -117,7 +117,8 @@ jobs: submodule="third-party/lizardbyte-common" find_lint_c_source() { - python - "$1/pyproject.toml" <<'PY' + local project_dir="$1" + python - "${project_dir}/pyproject.toml" <<'PY' import sys import tomllib from pathlib import Path diff --git a/.github/workflows/__mirror-github-to-gitlab.yml b/.github/workflows/__mirror-github-to-gitlab.yml index c762b67c..24e3fb9c 100644 --- a/.github/workflows/__mirror-github-to-gitlab.yml +++ b/.github/workflows/__mirror-github-to-gitlab.yml @@ -185,15 +185,16 @@ jobs: while ((SECONDS < deadline)); do if ! status="$(gitlab_request GET "${GITLAB_API_URL}/projects/${project_id}/import")"; then - echo "::error title=Mirror failed: ${source_name}::Unable to query the GitLab import." + echo "::error title=Mirror failed: ${source_name}::Unable to query the GitLab import." >&2 return 1 fi if [[ "${status}" != "200" ]]; then if [[ "${status}" == "403" ]]; then - echo "::error title=Mirror failed: ${source_name}::GITLAB_TOKEN needs Import API Read access." + echo "::error title=Mirror failed: ${source_name}::GITLAB_TOKEN needs Import API Read access." >&2 return 1 fi - echo "::error title=Mirror failed: ${source_name}::Unable to query the GitLab import (HTTP ${status})." + echo >&2 \ + "::error title=Mirror failed: ${source_name}::Unable to query the GitLab import (HTTP ${status})." return 1 fi @@ -212,17 +213,19 @@ jobs: import_error="${import_error//$'\r'/ }" import_error="${import_error//$'\n'/ }" echo "GitLab import failed: ${import_error}" - echo "::error title=Mirror failed: ${source_name}::GitLab server-side import failed." + echo "::error title=Mirror failed: ${source_name}::GitLab server-side import failed." >&2 return 1 ;; *) - echo "::error title=Mirror failed: ${source_name}::Unexpected GitLab import status: ${import_status}." + echo >&2 \ + "::error title=Mirror failed: ${source_name}::Unexpected GitLab import status: ${import_status}." return 1 ;; esac done - echo "::error title=Mirror failed: ${source_name}::GitLab server-side import timed out after three hours." + echo >&2 \ + "::error title=Mirror failed: ${source_name}::GitLab server-side import timed out after three hours." return 1 } @@ -277,7 +280,7 @@ jobs: gitlab_import_started=false if ! status="$(gitlab_request GET "${GITLAB_API_URL}/projects/${encoded_project_path}")"; then - echo "::error title=Mirror failed: ${source_name}::Unable to query the GitLab project." + echo "::error title=Mirror failed: ${source_name}::Unable to query the GitLab project." >&2 exit 1 fi @@ -316,7 +319,7 @@ jobs: } + if $import_url == "" then {} else {import_url: $import_url} end' )" if ! status="$(gitlab_request POST "${GITLAB_API_URL}/projects" "${payload}")"; then - echo "::error title=Mirror failed: ${source_name}::Unable to create the GitLab project." + echo "::error title=Mirror failed: ${source_name}::Unable to create the GitLab project." >&2 exit 1 fi if [[ "${status}" != "201" ]]; then @@ -325,7 +328,7 @@ jobs: create_error="${create_error//$'\n'/ }" echo "GitLab project creation response: ${create_error}" error_message="Unable to create the GitLab project (HTTP ${status})." - echo "::error title=Mirror failed: ${source_name}::${error_message}" + echo "::error title=Mirror failed: ${source_name}::${error_message}" >&2 exit 1 fi project_created=true @@ -333,7 +336,8 @@ jobs: gitlab_import_started=true fi elif [[ "${status}" != "200" ]]; then - echo "::error title=Mirror failed: ${source_name}::Unable to query the GitLab project (HTTP ${status})." + echo >&2 \ + "::error title=Mirror failed: ${source_name}::Unable to query the GitLab project (HTTP ${status})." exit 1 else echo "Found existing GitLab project ${project_path}." @@ -353,12 +357,12 @@ jobs: if ! status="$( gitlab_request PUT "${GITLAB_API_URL}/projects/${project_id}" "${privacy_payload}" )"; then - echo "::error title=Mirror failed: ${source_name}::Unable to secure the GitLab project." + echo "::error title=Mirror failed: ${source_name}::Unable to secure the GitLab project." >&2 exit 1 fi if [[ "${status}" != "200" ]] || \ [[ "$(jq -er '.visibility' "${response_file}")" != "private" ]]; then - echo "::error title=Mirror failed: ${source_name}::GitLab privacy verification failed." + echo "::error title=Mirror failed: ${source_name}::GitLab privacy verification failed." >&2 exit 1 fi fi @@ -373,22 +377,23 @@ jobs: if ! status="$( gitlab_request PUT "${GITLAB_API_URL}/projects/${project_id}" "${payload}" )"; then - echo "::error title=Mirror failed: ${source_name}::Unable to update the GitLab project." + echo "::error title=Mirror failed: ${source_name}::Unable to update the GitLab project." >&2 exit 1 fi if [[ "${status}" != "200" ]]; then - echo "::error title=Mirror failed: ${source_name}::Unable to update the GitLab project (HTTP ${status})." + echo >&2 \ + "::error title=Mirror failed: ${source_name}::Unable to update the GitLab project (HTTP ${status})." exit 1 fi actual_description="$(jq -er '.description // ""' "${response_file}")" actual_visibility="$(jq -er '.visibility' "${response_file}")" if [[ "${actual_description}" != "${description}" ]]; then - echo "::error title=Mirror failed: ${source_name}::GitLab description verification failed." + echo "::error title=Mirror failed: ${source_name}::GitLab description verification failed." >&2 exit 1 fi if [[ "${actual_visibility}" != "${target_visibility}" ]]; then - echo "::error title=Mirror failed: ${source_name}::GitLab visibility verification failed." + echo "::error title=Mirror failed: ${source_name}::GitLab visibility verification failed." >&2 exit 1 fi @@ -423,11 +428,11 @@ jobs: if ! status="$( gitlab_request POST "${GITLAB_API_URL}/projects/${project_id}/import/git" "${import_payload}" )"; then - echo "::error title=Mirror failed: ${source_name}::Unable to schedule the GitLab import." + echo "::error title=Mirror failed: ${source_name}::Unable to schedule the GitLab import." >&2 exit 1 fi if [[ "${status}" == "403" ]]; then - echo "::error title=Mirror failed: ${source_name}::GITLAB_TOKEN needs Import API Create access." + echo "::error title=Mirror failed: ${source_name}::GITLAB_TOKEN needs Import API Create access." >&2 exit 1 fi @@ -446,14 +451,14 @@ jobs: ;; *) echo "GitLab import conflict: ${import_response_message}" - echo "::error title=Mirror failed: ${source_name}::Unable to schedule the GitLab import." + echo "::error title=Mirror failed: ${source_name}::Unable to schedule the GitLab import." >&2 exit 1 ;; esac elif [[ "${status}" != "201" ]] && [[ "${status}" != "202" ]]; then echo "GitLab import response: ${import_response_message}" echo "::error title=Mirror failed: ${source_name}::Unable to schedule the GitLab import" \ - "(HTTP ${status})." + "(HTTP ${status})." >&2 exit 1 else gitlab_import_started=true @@ -468,7 +473,7 @@ jobs: if ! git \ -c http.https://github.com/.extraheader="AUTHORIZATION: basic ${github_auth}" \ clone --mirror --progress "${source_clone_url}" "${mirror_dir}"; then - echo "::error title=Mirror failed: ${source_name}::Unable to clone the GitHub repository." + echo "::error title=Mirror failed: ${source_name}::Unable to clone the GitHub repository." >&2 exit 1 fi @@ -494,7 +499,7 @@ jobs: echo "The GitHub repository has no refs to mirror." if [[ "${project_empty}" != "true" ]]; then echo "::error title=Mirror failed: ${source_name}::The GitHub repository is empty, but" \ - "the GitLab repository is not. Refusing to leave stale GitLab refs." + "the GitLab repository is not. Refusing to leave stale GitLab refs." >&2 exit 1 fi echo "The GitLab repository is also empty; no Git push is required." @@ -510,7 +515,7 @@ jobs: -C "${mirror_dir}" \ -c core.sshCommand="${gitlab_ssh_command}" \ push --progress "${target_clone_url}" "+${seed_ref}:${seed_ref}"; then - echo "::error title=Mirror failed: ${source_name}::Unable to seed ${seed_ref} on GitLab." + echo "::error title=Mirror failed: ${source_name}::Unable to seed ${seed_ref} on GitLab." >&2 exit 1 fi done @@ -521,7 +526,7 @@ jobs: -C "${mirror_dir}" \ -c core.sshCommand="${gitlab_ssh_command}" \ push --mirror --progress "${target_clone_url}"; then - echo "::error title=Mirror failed: ${source_name}::Unable to push the GitLab mirror." + echo "::error title=Mirror failed: ${source_name}::Unable to push the GitLab mirror." >&2 exit 1 fi fi diff --git a/tests/mirror-workflow.test.mjs b/tests/mirror-workflow.test.mjs new file mode 100644 index 00000000..18380f86 --- /dev/null +++ b/tests/mirror-workflow.test.mjs @@ -0,0 +1,33 @@ +import assert from 'node:assert/strict'; +import {spawnSync} from 'node:child_process'; +import {readFileSync} from 'node:fs'; +import test from 'node:test'; + +const workflow = readFileSync('.github/workflows/__mirror-github-to-gitlab.yml', 'utf8').replaceAll('\r\n', '\n'); +const errorCommands = workflow.replaceAll(/\\\n */g, ' ').split('\n') + .map(line => line.trim()).filter(line => /^echo .*"::error title=Mirror failed:/.test(line)); +const bash = process.env.BASH || 'bash'; + +test('repository mirror failure annotations go to stderr with their context intact', async (t) => { + assert.equal(errorCommands.length, 24); + for (const command of errorCommands) { + await t.test(command, () => { + const result = spawnSync(bash, ['--noprofile', '--norc', '-euo', 'pipefail'], { + input: command, + encoding: 'utf8', + env: { + ...process.env, + source_name: 'example repository', + status: '503', + import_status: 'unexpected', + error_message: 'Unable to create the GitLab project (HTTP 503).', + seed_ref: 'refs/heads/master', + }, + }); + assert.ifError(result.error); + assert.equal(result.status, 0, result.stderr); + assert.equal(result.stdout, ''); + assert.match(result.stderr, /^::error title=Mirror failed: example repository::[^\r\n]+\r?\n$/); + }); + } +}); From 3443efde88b9f6aa31c037e0137b163808dc5a0f Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:56:04 -0400 Subject: [PATCH 2/2] test: remove unnecessary mirror workflow regression checks --- tests/mirror-workflow.test.mjs | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 tests/mirror-workflow.test.mjs diff --git a/tests/mirror-workflow.test.mjs b/tests/mirror-workflow.test.mjs deleted file mode 100644 index 18380f86..00000000 --- a/tests/mirror-workflow.test.mjs +++ /dev/null @@ -1,33 +0,0 @@ -import assert from 'node:assert/strict'; -import {spawnSync} from 'node:child_process'; -import {readFileSync} from 'node:fs'; -import test from 'node:test'; - -const workflow = readFileSync('.github/workflows/__mirror-github-to-gitlab.yml', 'utf8').replaceAll('\r\n', '\n'); -const errorCommands = workflow.replaceAll(/\\\n */g, ' ').split('\n') - .map(line => line.trim()).filter(line => /^echo .*"::error title=Mirror failed:/.test(line)); -const bash = process.env.BASH || 'bash'; - -test('repository mirror failure annotations go to stderr with their context intact', async (t) => { - assert.equal(errorCommands.length, 24); - for (const command of errorCommands) { - await t.test(command, () => { - const result = spawnSync(bash, ['--noprofile', '--norc', '-euo', 'pipefail'], { - input: command, - encoding: 'utf8', - env: { - ...process.env, - source_name: 'example repository', - status: '503', - import_status: 'unexpected', - error_message: 'Unable to create the GitLab project (HTTP 503).', - seed_ref: 'refs/heads/master', - }, - }); - assert.ifError(result.error); - assert.equal(result.status, 0, result.stderr); - assert.equal(result.stdout, ''); - assert.match(result.stderr, /^::error title=Mirror failed: example repository::[^\r\n]+\r?\n$/); - }); - } -});