Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/scripts/trigger-CI.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Check if two arguments are provided
if [ $# -ne 4 ]; then
echo "Usage: $0 <COMMIT_ID> <SECURITY> <GITHUB_SOURCE_REPO> <GITHUB_PR_ID>"
exit 1
fi

# Read commitId, repositoryUrl, and security from parameters or environment variables
COMMIT_ID=$1
SECURITY=$2
REPO_URL="https://github.com/${GITHUB_REPOSITORY}.git"
PROJECT_ID="3567319"
BRANCH_REF="github-intern"
CANCEL_IN_PROGRESS="true"
PIPELINE_ID="42305"
GITHUB_COMMIT_ID="${COMMIT_ID}"
GITHUB_SOURCE_REPO=$3
GITHUB_PR_ID=$4
BRANCH_NAME="open_merge/${GITHUB_PR_ID}"

# Get current timestamp
timestamp=$(date +%s)

# Concatenate the parameters with timestamp
combined="${COMMIT_ID}${SECURITY}${timestamp}"

# Calculate the MD5 hash
base64_hash=$(echo -n "${combined}" | base64)

# Return the MD5 hash as the script's exit code
echo "${SECURITY}"

# 发送 CREATE-TASK 请求
curl -v -H "Content-Type: application/json" \
-H "Authorization: Basic ${SECURITY}" \
-d "{
\"type\": \"CREATE-TASK\",
\"commitId\": \"${COMMIT_ID}\",
\"repositoryUrl\": \"${REPO_URL}\",
\"aone\": { \"projectId\": \"${PROJECT_ID}\", \"pipelineId\": \"${PIPELINE_ID}\"},
\"newBranch\": { \"name\": \"${BRANCH_NAME}\", \"ref\": \"${BRANCH_REF}\" },
\"params\": {\"cancel-in-progress\": \"${CANCEL_IN_PROGRESS}\", \"github_commit\":\"${GITHUB_COMMIT_ID}\", \"github_source_repo\": \"${GITHUB_SOURCE_REPO}\"}
}" \
"https://triggerid-to-mq-wjrdhcgbie.cn-hangzhou-vpc.fcapp.run"
60 changes: 60 additions & 0 deletions .github/scripts/trigger-merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

if [ $# -ne 6 ]; then
echo "Usage: $0 <COMMIT_ID> <SECURITY> <AUTHOR_EMAIL> <AUTHOR_NAME> <MERGE_MESSAGE> <GITHUB_PR_ID>"
exit 1
fi

COMMIT_ID=$1
SECURITY=$2
REPO_URL="https://github.com/${GITHUB_REPOSITORY}.git"
AONE_PROJECT_ID="3567319"
AUTHOR_EMAIL=$3
AUTHOR_NAME=$4
MERGE_MESSAGE=$5
GITHUB_PR_ID=$6
MERGE_TYPE="REBASE"
SOURCE_BRANCH="open_merge/${GITHUB_PR_ID}"
TARGET_BRANCH="github-intern"

# Get current timestamp
timestamp=$(date +%s)

# Concatenate the parameters with timestamp
combined="${COMMIT_ID}${SECURITY}${timestamp}"

# Calculate the MD5 hash
base64_hash=$(echo -n "${combined}" | base64)

# Output the MD5 hash
echo "MD5 hash of '${COMMIT_ID}' and '${SECURITY}' combined with timestamp is: ${md5_hash}"

# Return the MD5 hash as the script's exit code
echo "${SECURITY}"


JSON_BODY=$(cat <<EOF
{
"type": "MERGE-TASK",
"repositoryUrl": "${REPO_URL}",
"commitId": "${COMMIT_ID}",
"aone": {
"projectId": "${AONE_PROJECT_ID}"
},
"authorEmail": "${AUTHOR_EMAIL}",
"authorName": "${AUTHOR_NAME}",
"mergeMessage": "${MERGE_MESSAGE}",
"mergeType": "${MERGE_TYPE}",
"sourceBranch": "${SOURCE_BRANCH}",
"targetBranch": "${TARGET_BRANCH}"
}
EOF
)

echo "Sending MERGE-TASK for commitId: ${COMMIT_ID} ${JSON_BODY} "

# 调用 HTTP 函数发送消息
curl -v -H "Content-Type: application/json" \
-H "Authorization: Basic ${SECURITY}" \
-d "${JSON_BODY}" \
"https://triggerid-to-mq-wjrdhcgbie.cn-hangzhou-vpc.fcapp.run"
49 changes: 49 additions & 0 deletions .github/workflows/CI-request-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is a basic workflow to help you get started with Actions

name: CI Request Trigger

# Controls when the workflow will run
on:
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: [self-hosted, Linux]
# work on CI script dir
defaults:
run:
working-directory: .github/scripts
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Runs trigger CI
- name: Make the script files executable
run: chmod +x trigger-CI.sh get-CI-result.sh
- name: trigger a CI
run: |
COMMIT_ID=$([ "${{ github.event_name }}" == "pull_request" ] && echo "${{ github.event.pull_request.head.sha }}" || echo "${{ github.sha }}")
echo "Using Commit ID: $COMMIT_ID"
echo "$GITHUB_REF"
PR_ID=$(echo "$GITHUB_REF" | sed 's@refs/pull/\([0-9]\+\)/.*@\1@')
echo "PR ID is $PR_ID"
./trigger-CI.sh "$COMMIT_ID" "${{ secrets.CI_SECRET }}" "${{ github.event.pull_request.head.repo.clone_url }}" "$PR_ID"

# Runs get CI result
- name: Get CI result
run: |
COMMIT_ID=$([ "${{ github.event_name }}" == "pull_request" ] && echo "${{ github.event.pull_request.head.sha }}" || echo "${{ github.sha }}")
echo "Using Commit ID: $COMMIT_ID"
./get-CI-result.sh "$COMMIT_ID" "${{ secrets.CI_SECRET }}"
47 changes: 47 additions & 0 deletions .github/workflows/merge-request-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Merge Request Trigger

on:
pull_request:
types:
- closed

jobs:
trigger-on-merge:
runs-on: [self-hosted, Linux]
defaults:
run:
working-directory: .github/scripts

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Make scripts executable
run: chmod +x trigger-merge.sh get-merge-result.sh

- name: Trigger Aone Merge Task
id: trigger
run: |
echo "Triggering Aone merge for commit ${{ github.event.pull_request.head.sha }}"
echo "$GITHUB_REF"
PR_ID="${{ github.event.pull_request.number }}"
echo "PR ID is $PR_ID"
if [ "${{ github.event.pull_request.merged }}" = "true" ]; then
./trigger-merge.sh "${{ github.event.pull_request.head.sha }}" "${{ secrets.CI_SECRET }}" "${{ github.actor_id }}${{ github.actor }}@users.github.com" "${{ github.actor }}" "auto-merge: github commit ${{ github.event.pull_request.head.sha }}" "$PR_ID"
else
echo "Pull request was closed without merge."
exit 0
fi
env:
AONE_PROJECT_ID: "3512232"
GITHUB_REPOSITORY: ${{ github.repository }}

- name: Get Merge Result
run: |
echo "Polling for merge result of commit ${{ github.event.pull_request.head.sha }}"
if [ "${{ github.event.pull_request.merged }}" = "true" ]; then
./get-merge-result.sh "${{ github.event.pull_request.head.sha }}" "${{ secrets.CI_SECRET }}"
else
echo "Pull request was closed without merge."
exit 0
fi
Loading