This is an automated email from the ASF dual-hosted git repository.
shuke987 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new bebeb06b335 [chore](build) Add FC pilot commands for TeamCity PR
builds (#70972)
bebeb06b335 is described below
commit bebeb06b3350d70e36bf707a62bd6c6fea62cbf3
Author: shuke <[email protected]>
AuthorDate: Wed Nov 25 09:31:14 2026 +0800
[chore](build) Add FC pilot commands for TeamCity PR builds (#70972)
Maintainers request TeamCity checks by commenting on a PR. The GitHub
workflow checks permissions and changed files, then sends selected
builds directly to TeamCity. Compile dispatches its own downstream
regression builds.
---
.github/workflows/comment-to-trigger-teamcity.yml | 99 +++++++++++++++++++++-
regression-test/pipeline/common/teamcity-utils.sh | 37 +++++++-
.../pipeline/common/tests/test_teamcity_utils.py | 72 +++++++++++++++-
3 files changed, 200 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/comment-to-trigger-teamcity.yml
b/.github/workflows/comment-to-trigger-teamcity.yml
index 48a86e52073..592ab98c1bf 100644
--- a/.github/workflows/comment-to-trigger-teamcity.yml
+++ b/.github/workflows/comment-to-trigger-teamcity.yml
@@ -36,6 +36,8 @@ jobs:
github.event.issue.pull_request &&
!startsWith(github.event.comment.body, '/review') &&
(
+ (github.event.comment.user.id == 37901441 && github.event.sender.id
== 37901441 &&
+ github.event.comment.user.login == 'shuke987' &&
contains(github.event.comment.body, 'run debug')) ||
contains(github.event.comment.body, 'run buildall') ||
contains(github.event.comment.body, 'run compile') ||
contains(github.event.comment.body, 'run beut') ||
@@ -51,12 +53,20 @@ jobs:
)
}}
+ outputs:
+ lanes: ${{ steps.fc_lanes.outputs.lanes }}
+ pr: ${{ steps.parse.outputs.PULL_REQUEST_NUM }}
+ head: ${{ steps.parse.outputs.COMMIT_ID_FROM_TRIGGER }}
+ base: ${{ steps.parse.outputs.TARGET_BRANCH }}
+ repeat: ${{ steps.parse.outputs.COMMENT_REPEAT_TIMES }}
runs-on: ubuntu-latest
env:
COMMENT_BODY: ${{ github.event.comment.body }}
+ COMMENT_LOGIN: ${{ github.event.comment.user.login }}
+ COMMENT_SENDER_ID: ${{ github.event.sender.id }}
COMMENT_USER_ID: ${{ github.event.comment.user.id }}
TEAMCITY_CURRENT_URL: ${{ vars.TEAMCITY_CURRENT_URL }}
- TEAMCITY_CURRENT_TOKEN: ${{ secrets.TEAMCITY_CURRENT_TOKEN }}
+ TEAMCITY_CURRENT_TOKEN: ${{ !contains(github.event.comment.body,
'debug') && secrets.TEAMCITY_CURRENT_TOKEN || '' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
@@ -65,8 +75,26 @@ jobs:
run: |
COMMENT_BODY=$(echo "${COMMENT_BODY}" | xargs)
PULL_REQUEST_NUM="$(echo "${{ github.event.issue.pull_request.url }}"
| awk -F/ '{print $NF}')"
- COMMIT_ID_FROM_TRIGGER="$(curl -s -H "Authorization:Bearer
${GITHUB_TOKEN}" "https://api.github.com/repos/${{ github.repository
}}/pulls/${PULL_REQUEST_NUM}" | jq -r '.head.sha')"
- TARGET_BRANCH="$(curl -s -H "Authorization:Bearer ${GITHUB_TOKEN}"
"https://api.github.com/repos/${{ github.repository
}}/pulls/${PULL_REQUEST_NUM}" | jq -r '.base.ref')"
+ pr_json=$(curl --fail --silent --show-error -H "Authorization: Bearer
${GITHUB_TOKEN}" \
+ "https://api.github.com/repos/${{ github.repository
}}/pulls/${PULL_REQUEST_NUM}")
+ COMMIT_ID_FROM_TRIGGER=$(jq -er '.head.sha' <<< "$pr_json")
+ TARGET_BRANCH=$(jq -er '.base.ref' <<< "$pr_json")
+ # Debug commands exercise the FC transport with the same production
lane rules.
+ if [[ "$COMMENT_BODY" == 'run debug'* ]]; then
+ [[ "$COMMENT_LOGIN" == shuke987 && "$COMMENT_USER_ID" == 37901441 &&
"$COMMENT_SENDER_ID" == 37901441 ]] || exit 1
+ debug_command='^run
debug(all|compile|p0|feut|beut|cloudut|external|cloud_p0|vault_p0|nonconcurrent|performance)(
([1-9][0-9]*))?$'
+ [[ "$COMMENT_BODY" =~ $debug_command ]] || { echo 'Unsupported FC
debug command'; exit 1; }
+ lane=${BASH_REMATCH[1]}
+ repeat=${BASH_REMATCH[3]:-1}
+ [[ "$repeat" =~ ^([1-9]|1[0-9]|20)$ ]] || { echo 'Repeat must be
between 1 and 20'; exit 1; }
+ [[ "$lane" != all ]] || lane=buildall
+ COMMENT_BODY="run $lane $repeat"
+ echo "fc=true" >> "$GITHUB_OUTPUT"
+ base_sha=$(jq -er '.base.sha' <<< "$pr_json")
+ file_count=$(jq -er '.changed_files' <<< "$pr_json")
+ echo "base_sha=$base_sha" >> "$GITHUB_OUTPUT"
+ echo "file_count=$file_count" >> "$GITHUB_OUTPUT"
+ fi
if [[ "${COMMENT_BODY}" == *'run buildall'* ||
"${COMMENT_BODY}" == *'run compile'* ||
"${COMMENT_BODY}" == *'run beut'* ||
@@ -149,7 +177,7 @@ jobs:
if: ${{ fromJSON(steps.parse.outputs.comment_trigger) ||
fromJSON(steps.parse.outputs.comment_skip) }}
uses: actions/checkout@v4
with:
- ref: ${{ github.event.repository.default_branch }}
+ ref: ${{ github.sha }}
persist-credentials: false
- name: "Check if pr need run build"
@@ -248,6 +276,23 @@ jobs:
exit 1
fi
+ - name: Prepare FC lane selection
+ if: steps.parse.outputs.fc == 'true'
+ env:
+ PR: ${{ steps.parse.outputs.PULL_REQUEST_NUM }}
+ HEAD_SHA: ${{ steps.parse.outputs.COMMIT_ID_FROM_TRIGGER }}
+ BASE_SHA: ${{ steps.parse.outputs.base_sha }}
+ FILE_COUNT: ${{ steps.parse.outputs.file_count }}
+ run: |
+ # The file filters and the approval record must describe the same PR
revision.
+ [[ "$FILE_COUNT" =~ ^[0-9]+$ && $(wc -l < all_files) -eq "$FILE_COUNT"
]]
+ curl --fail --silent --show-error -H "Authorization: Bearer
$GITHUB_TOKEN" \
+ "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/$PR" |
+ jq -e --arg head "$HEAD_SHA" --arg base "$BASE_SHA" --arg branch
"$TARGET_BRANCH" \
+ '.state == "open" and .head.sha == $head and .base.sha == $base
and .base.ref == $branch' >/dev/null
+ : > "$RUNNER_TEMP/teamcity-fc-lanes"
+ echo "TEAMCITY_FC_PLAN=$RUNNER_TEMP/teamcity-fc-lanes" >> "$GITHUB_ENV"
+
- name: "Trigger feut"
if: ${{ fromJSON(steps.parse.outputs.comment_trigger) &&
contains(fromJSON('["feut", "buildall"]'),
steps.parse.outputs.COMMENT_TRIGGER_TYPE) }}
run: |
@@ -385,6 +430,13 @@ jobs:
"performance" \
"${{ steps.parse.outputs.COMMENT_REPEAT_TIMES }}"
+ - name: Collect selected FC lanes
+ id: fc_lanes
+ if: steps.parse.outputs.fc == 'true'
+ run: |
+ lanes=$(jq -Rsc 'split("\n") | map(select(length > 0))'
"$TEAMCITY_FC_PLAN")
+ echo "lanes=$lanes" >> "$GITHUB_OUTPUT"
+
- name: "Skip buildall"
if: ${{ fromJSON(steps.parse.outputs.comment_skip) }}
run: |
@@ -401,3 +453,42 @@ jobs:
skip_build "${{ steps.parse.outputs.COMMIT_ID_FROM_TRIGGER }}" cloudut
skip_build "${{ steps.parse.outputs.COMMIT_ID_FROM_TRIGGER }}" vault_p0
skip_build "${{ steps.parse.outputs.COMMIT_ID_FROM_TRIGGER }}"
nonconcurrent
+
+ approve-fc:
+ needs: check-comment-if-need-to-trigger-teamcity
+ if: needs.check-comment-if-need-to-trigger-teamcity.outputs.lanes != '' &&
needs.check-comment-if-need-to-trigger-teamcity.outputs.lanes != '[]'
+ strategy:
+ matrix:
+ lane: ${{
fromJSON(needs.check-comment-if-need-to-trigger-teamcity.outputs.lanes) }}
+ name: fc-approve/v1/${{
needs.check-comment-if-need-to-trigger-teamcity.outputs.pr }}/${{
needs.check-comment-if-need-to-trigger-teamcity.outputs.head }}/${{
needs.check-comment-if-need-to-trigger-teamcity.outputs.base }}/${{ matrix.lane
}}/${{ needs.check-comment-if-need-to-trigger-teamcity.outputs.repeat }}
+ runs-on: ubuntu-latest
+ permissions: {}
+ steps:
+ - run: 'true'
+
+ submit-fc:
+ needs: [check-comment-if-need-to-trigger-teamcity, approve-fc]
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ ref: ${{ github.sha }}
+ persist-credentials: false
+ sparse-checkout: regression-test/pipeline/common
+ - name: Queue approved TeamCity builds
+ env:
+ TEAMCITY_FC_TRIGGER_URL: ${{ vars.TEAMCITY_FC_TRIGGER_URL }}
+ LANES: ${{
needs.check-comment-if-need-to-trigger-teamcity.outputs.lanes }}
+ PR: ${{ needs.check-comment-if-need-to-trigger-teamcity.outputs.pr }}
+ HEAD_SHA: ${{
needs.check-comment-if-need-to-trigger-teamcity.outputs.head }}
+ BASE_BRANCH: ${{
needs.check-comment-if-need-to-trigger-teamcity.outputs.base }}
+ REPEAT: ${{
needs.check-comment-if-need-to-trigger-teamcity.outputs.repeat }}
+ run: |
+ source regression-test/pipeline/common/teamcity-utils.sh
+ lanes=$(jq -er '.[]' <<< "$LANES")
+ while IFS= read -r lane; do
+ teamcity_fc_submit "$lane" "$PR" "$HEAD_SHA" "$BASE_BRANCH"
"$REPEAT"
+ done <<< "$lanes"
diff --git a/regression-test/pipeline/common/teamcity-utils.sh
b/regression-test/pipeline/common/teamcity-utils.sh
index 195efda8904..444e6d37e5f 100644
--- a/regression-test/pipeline/common/teamcity-utils.sh
+++ b/regression-test/pipeline/common/teamcity-utils.sh
@@ -102,6 +102,35 @@ teamcity_current_trigger() (
teamcity_current_enqueue "${comment_to_pipeline[$lane]}" "$params" "$count"
)
+# Run only in the OIDC-enabled job after GitHub records the lane approvals.
+teamcity_fc_submit() (
+ set -euo pipefail
+ set +x
+ local lane=$1 pr=$2 head=$3 branch=$4 repeat=$5 token body receipt
+ local endpoint=${TEAMCITY_FC_TRIGGER_URL:?Set the repository variable
TEAMCITY_FC_TRIGGER_URL}
+ [[ "$endpoint" =~ ^https://[A-Za-z0-9.-]+/trigger$ ]] || { echo 'Invalid
FC HTTPS trigger URL' >&2; return 1; }
+ token=$(printf 'Authorization: Bearer %s\n'
"${ACTIONS_ID_TOKEN_REQUEST_TOKEN:?}" |
+ curl -q --proto '=https' --fail --silent --show-error --max-time 20
--header @- \
+ --get --data-urlencode
'audience=urn:apache:doris:ci:teamcity-trigger'
"${ACTIONS_ID_TOKEN_REQUEST_URL:?}" |
+ jq -er '.value | select(type == "string" and length > 0)') || return 1
+ echo "::add-mask::$token"
+ body=$(jq -cn --arg lane "$lane" --argjson pr "$pr" --arg head "$head"
--arg base "$branch" --argjson repeat "$repeat" \
+ '{pipeline:$lane, pr:$pr, head_sha:$head, base_branch:$base,
repeat:$repeat}') || return 1
+ local response status
+ response=$(printf 'Authorization: Bearer %s\n' "$token" |
+ curl -q --proto '=https' --silent --show-error --max-time 300 --header
@- \
+ -H 'Content-Type: application/json' --write-out '\n%{http_code}'
--data-binary "$body" "$endpoint") || return 1
+ status=${response##*$'\n'}
+ receipt=${response%$'\n'*}
+ if [[ $status != 200 ]]; then
+ jq -c '{error, request_key, completed}' <<< "$receipt" >&2
+ return 1
+ fi
+ jq -e --argjson repeat "$repeat" '.build_ids | type == "array" and length
== $repeat and
+ all(.[]; type == "number" and . > 0 and floor == .)' <<< "$receipt"
>/dev/null || return 1
+ printf '%s queued build IDs: %s\n' "$lane" "$(jq -c '.build_ids' <<<
"$receipt")"
+)
+
skip_build() {
set +x
# 对于不需要跑teamcity pipeline的PR,直接调用github的接口返回成功
@@ -186,7 +215,13 @@ trigger_or_skip_build() {
echo "No pipeline for $COMMENT_TRIGGER_TYPE on
$PULL_REQUEST_TARGET_BRANCH" >&2; return 1;
}
case "$FILE_CHANGED" in
- true) trigger_build "$PULL_REQUEST_NUM" "$COMMIT_ID_FROM_TRIGGER"
"$COMMENT_TRIGGER_TYPE" "${COMMENT_REPEAT_TIMES:-1}" ;;
+ true)
+ if [[ -n ${TEAMCITY_FC_PLAN:-} ]]; then
+ printf '%s\n' "$COMMENT_TRIGGER_TYPE" >> "$TEAMCITY_FC_PLAN"
+ else
+ trigger_build "$PULL_REQUEST_NUM" "$COMMIT_ID_FROM_TRIGGER"
"$COMMENT_TRIGGER_TYPE" "${COMMENT_REPEAT_TIMES:-1}"
+ fi
+ ;;
false) teamcity_skip_unaffected ;;
*) echo "Invalid FILE_CHANGED: $FILE_CHANGED" >&2; return 1 ;;
esac
diff --git a/regression-test/pipeline/common/tests/test_teamcity_utils.py
b/regression-test/pipeline/common/tests/test_teamcity_utils.py
index a98ea2d0ac6..9218eef213d 100644
--- a/regression-test/pipeline/common/tests/test_teamcity_utils.py
+++ b/regression-test/pipeline/common/tests/test_teamcity_utils.py
@@ -227,7 +227,8 @@ curl(){
commands = re.search(r'reg="\^run \(([^)]+)\)',
workflow).group(1).split('|')
self.assertEqual(set(commands), set(mappings) | {'buildall'})
- def parse_comment(self, command, branch='master', permission='write',
check=True, user_id='27881198'):
+ def parse_comment(self, command, branch='master', permission='write',
check=True, user_id='27881198',
+ login='tester', sender_id=None):
workflow = (HELPER.parents[3] /
'.github/workflows/comment-to-trigger-teamcity.yml').read_text()
block = workflow.split(' - name: "Parse PR comment"\n',
1)[1].split(' - name:', 1)[0]
script = textwrap.dedent(block.split(' run: |\n', 1)[1])
@@ -237,9 +238,10 @@ curl(){
prefix = 'curl(){ printf "%s\\n" "$MOCK_GITHUB_RESPONSE"; };\n'
result = subprocess.run(['bash', '-eo', 'pipefail', '-c', prefix +
script], text=True, capture_output=True,
env={**self.env, 'COMMENT_BODY': command,
'COMMENT_USER_ID': user_id,
+ 'COMMENT_LOGIN': login,
'COMMENT_SENDER_ID': sender_id or user_id,
'GITHUB_TOKEN': 'test-github-token',
'GITHUB_OUTPUT': str(output),
'GITHUB_ENV': str(self.root /
'workflow-env'),
- 'MOCK_GITHUB_RESPONSE':
json.dumps({'head': {'sha': HEAD}, 'base': {'ref': branch}, 'permission':
permission})})
+ 'MOCK_GITHUB_RESPONSE':
json.dumps({'head': {'sha': HEAD}, 'base': {'ref': branch, 'sha': 'c' * 40},
'changed_files': 1, 'permission': permission})})
if check:
self.assertEqual(result.returncode, 0, result.stdout +
result.stderr)
return result, output.read_text()
@@ -254,6 +256,70 @@ curl(){
result, output = self.parse_comment(command, check=False)
self.assertNotIn('COMMENT_TRIGGER_TYPE=', output)
+ def test_debug_commands_require_the_pilot_author_and_editor(self):
+ pilot = {'login': 'shuke987', 'user_id': '37901441'}
+ for lane in ['compile', 'feut', 'beut', 'cloudut', 'p0', 'cloud_p0',
'vault_p0',
+ 'external', 'nonconcurrent', 'performance', 'all']:
+ _, output = self.parse_comment('run debug' + lane + ' 2', **pilot)
+ self.assertIn('fc=true', output)
+ self.assertIn('COMMENT_TRIGGER_TYPE=' + ('buildall' if lane ==
'all' else lane) + '\n', output)
+ self.assertIn('COMMENT_REPEAT_TIMES=2', output)
+ for kwargs in [{'login': 'other'}, {'user_id': '123'}, {'sender_id':
'123'}]:
+ result, output = self.parse_comment('run debugall', **{**pilot,
**kwargs}, check=False)
+ self.assertNotEqual(result.returncode, 0)
+ self.assertNotIn('fc=true', output)
+ for cmd in ['run debugcompile 21', 'run debugall extra', 'run
debugunknown']:
+ result, _ = self.parse_comment(cmd, **pilot, check=False)
+ self.assertNotEqual(result.returncode, 0)
+ _, output = self.parse_comment('run compile', **pilot)
+ self.assertNotIn('fc=true', output)
+
+ def test_debug_selection_never_enqueues_directly(self):
+ plan = self.root / 'fc-lanes'
+ for lane in ['compile', 'p0', 'feut']:
+ self.trigger(lane, env={'TEAMCITY_FC_PLAN': str(plan)})
+ self.run_shell('trigger_or_skip_build false 123 master ' + HEAD + '
cloudut 1',
+ env={'TEAMCITY_FC_PLAN': str(plan)})
+ self.assertEqual(plan.read_text().splitlines(), ['compile', 'p0',
'feut'])
+ self.assertFalse(self.state().get('posts'))
+ self.assertEqual(self.skipped_contexts(), ['TeamCity/cloudut'])
+
+ def test_fc_submission_validates_receipts_and_never_reposts(self):
+ mock = '''curl(){
+ local header
+ read -r header
+ if [[ "$*" == *'audience=urn:apache:doris:ci:teamcity-trigger'* ]]; then
+ [[ "$header" == 'Authorization: Bearer job-token' ]] || return 1
+ echo '{"value":"fixture-oidc"}'
+ else
+ [[ "${!#}" == 'https://fc.example/trigger' &&
+ "$header" == 'Authorization: Bearer fixture-oidc' ]] || return 1
+ while [[ $# -gt 0 && "$1" != --data-binary ]]; do shift; done
+ echo "$2" >> "$FIXTURE_ROOT/fc-posts"
+ echo "$FC_REPLY"
+ echo "$FC_STATUS"
+ return "$FC_EXIT"
+ fi
+}
+'''
+ for reply, status, exit_code, success in [({'build_ids': [17, 18]},
200, 0, True),
+ ({'build_ids': [17]}, 200,
0, False),
+ ({'build_ids': [0, '18']},
200, 0, False),
+ ({'build_ids': [17, 18]},
202, 0, False),
+ ({'error':
'reconciliation_required'}, 409, 0, False),
+ ({}, 0, 28, False)]:
+ posts = self.root / 'fc-posts'
+ posts.unlink(missing_ok=True)
+ env = {'TEAMCITY_FC_TRIGGER_URL': 'https://fc.example/trigger',
+ 'ACTIONS_ID_TOKEN_REQUEST_URL':
'https://oidc.example/token',
+ 'ACTIONS_ID_TOKEN_REQUEST_TOKEN': 'job-token',
+ 'FC_REPLY': json.dumps(reply), 'FC_STATUS': str(status),
'FC_EXIT': str(exit_code)}
+ result = self.run_shell(mock + 'teamcity_fc_submit p0 123 ' + HEAD
+ ' master 2',
+ mock=False, check=False, env=env)
+ self.assertEqual(result.returncode == 0, success, result.stdout +
result.stderr)
+ self.assertEqual([json.loads(row) for row in
posts.read_text().splitlines()],
+ [{'pr': 123, 'head_sha': HEAD, 'base_branch':
'master', 'pipeline': 'p0', 'repeat': 2}])
+
def test_skip_buildall_authorization_is_preserved(self):
_, output = self.parse_comment('skip buildall')
self.assertIn('comment_skip=true', output)
@@ -264,7 +330,7 @@ curl(){
def test_skip_buildall_statuses(self):
workflow = (HELPER.parents[3] /
'.github/workflows/comment-to-trigger-teamcity.yml').read_text()
- block = workflow.split(' - name: "Skip buildall"\n', 1)[1]
+ block = workflow.split(' - name: "Skip buildall"\n',
1)[1].split('\n approve-fc:', 1)[0]
script = textwrap.dedent(block.split(' run: |\n', 1)[1])
script = script.replace('source
./regression-test/pipeline/common/teamcity-utils.sh', ':')
script = script.replace('${{
steps.parse.outputs.COMMIT_ID_FROM_TRIGGER }}', HEAD)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]