Skip to content

Commit ad5cc4d

Browse files
committed
Merge branch 'master' of github.com:lovelynewlife/oceanbase
2 parents 6b45e9d + dcea3dc commit ad5cc4d

File tree

4,668 files changed

+3942310
-237720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,668 files changed

+3942310
-237720
lines changed

.github/obfarm/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Container image that runs your code
2+
FROM python:3.6
3+
4+
RUN pip3 install requests -i https://mirrors.aliyun.com/pypi/simple/ && pip3 install art -i https://mirrors.aliyun.com/pypi/simple/
5+
# Copies your code file from your action repository to the filesystem path `/` of the container
6+
COPY obfarm.py /obfarm.py
7+
8+
# Code file to execute when the docker container starts up (`entrypoint.sh`)
9+
ENTRYPOINT ["python3", "-u", "/obfarm.py"]

.github/obfarm/action.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# action.yml
2+
name: 'call OB Farm to run task'
3+
description: ''
4+
inputs:
5+
pipeline_id:
6+
description: 'pipeline_id'
7+
required: true
8+
project:
9+
description: 'project'
10+
required: true
11+
timeout:
12+
description: 'timeout'
13+
required: false
14+
default: '7200'
15+
outputs:
16+
success:
17+
description: 'the status for the task'
18+
runs:
19+
using: 'docker'
20+
image: 'Dockerfile'
21+
args:
22+
- ${{ inputs.pipeline_id }}
23+
- ${{ inputs.project }}
24+
- ${{ inputs.timeout }}
25+
26+

.github/obfarm/obfarm.py

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# -*- coding: utf-8 -*-
2+
import copy
3+
import os
4+
import sys
5+
import traceback
6+
import time
7+
import json
8+
import requests
9+
from enum import Enum
10+
from http import HTTPStatus
11+
12+
from art import text2art
13+
14+
OUTPUT = {}
15+
RESULT_FILE_KEY = "farm/ob_results/"
16+
TASK_QUEUE_FILE_KEY = "farm/ob_jobs/{}.json"
17+
18+
19+
def _range(start, last):
20+
def to_str(pos):
21+
if pos is None:
22+
return ''
23+
else:
24+
return str(pos)
25+
26+
return to_str(start) + '-' + to_str(last)
27+
28+
29+
def _make_range_string(range):
30+
if range is None:
31+
return ''
32+
33+
start = range[0]
34+
last = range[1]
35+
36+
if start is None and last is None:
37+
return ''
38+
39+
return 'bytes=' + _range(start, last)
40+
41+
42+
class OssProxy:
43+
44+
def __init__(self, endpoint=""):
45+
self.endpoint = endpoint
46+
47+
def get_object(self, key, _range=None):
48+
url = "{}/{}".format(self.endpoint, key)
49+
headers = {}
50+
if _range is not None:
51+
_range = (_range, None)
52+
headers.update({"range": _make_range_string(_range)})
53+
res = requests.get(url, headers=headers)
54+
if res.status_code < 400:
55+
result = res.content.decode()
56+
return result
57+
return ""
58+
59+
def get_object_meta(self, key):
60+
url = "{}/{}".format(self.endpoint, key)
61+
headers = {}
62+
res = requests.head(url, headers=headers)
63+
return res.headers
64+
65+
def exists_object(self, key):
66+
...
67+
68+
69+
class GithubProxy:
70+
71+
def __init__(self, host="api.github.com"):
72+
self.host = host
73+
74+
def get_job_by_id(self, project, pipeline_id):
75+
url = "https://{}/repos/{}/actions/runs/{}".format(
76+
self.host, project, pipeline_id
77+
)
78+
try:
79+
res = requests.get(
80+
url, headers={
81+
"Accept": "application/vnd.github+json"
82+
}
83+
)
84+
status_code = res.status_code
85+
if status_code == HTTPStatus.NOT_FOUND:
86+
return {}
87+
return res.json()
88+
except:
89+
traceback.print_exc()
90+
return {}
91+
92+
93+
class TaskStatusEnum(Enum):
94+
submitting = 0
95+
pending = 1
96+
running = 2
97+
stopping = 3
98+
success = 4
99+
fail = -1
100+
kill = -2
101+
timeout = -3
102+
submit_task_fail = -4
103+
104+
105+
def request(method, url, params=None, payload=None, timeout=10, data=None, without_check_status=False):
106+
params = params or {}
107+
try:
108+
response = requests.request(
109+
method,
110+
url,
111+
params=params,
112+
json=payload,
113+
data=data,
114+
timeout=timeout
115+
)
116+
if not without_check_status and response.status_code >= 300:
117+
try:
118+
msg = response.json()["msg"]
119+
except:
120+
msg = response.text
121+
print("[ERROR] MSG:{}".format(msg))
122+
exit(1)
123+
return response
124+
except Exception:
125+
import traceback
126+
traceback.print_exc()
127+
print("Please contact the management personnel for assistance !")
128+
if not without_check_status:
129+
exit(1)
130+
131+
132+
def monitor_tasks(oss_proxy: OssProxy, github_pipeline_id, timeout):
133+
end_time = time.time() + int(timeout)
134+
end_task = False
135+
while time.time() <= end_time:
136+
if end_task is True:
137+
pass
138+
task_data = get_task_res(oss_proxy, github_pipeline_id)
139+
if task_data:
140+
end_task = True
141+
142+
time.sleep(1)
143+
if task_data is not None:
144+
task_status = int(task_data["status"])
145+
if task_status <= TaskStatusEnum.fail.value:
146+
print(TaskStatusEnum._value2member_map_[task_status])
147+
print("there is the output url: {}".format(
148+
"https://ce-farm.oceanbase-dev.com/farm2/ci/?id={}".format(task_data["task_id"])))
149+
return False
150+
elif task_status >= TaskStatusEnum.success.value:
151+
print(TaskStatusEnum._value2member_map_[task_status])
152+
print("there is the output url: {}".format(
153+
"https://ce-farm.oceanbase-dev.com/farm2/ci/?id={}".format(task_data["task_id"])))
154+
return True
155+
156+
time.sleep(5)
157+
else:
158+
...
159+
160+
161+
def get_task_res(oss_proxy: OssProxy, github_pipeline_id):
162+
try:
163+
result_key = RESULT_FILE_KEY + "{}.json".format(github_pipeline_id)
164+
origin_task_data = oss_proxy.get_object(result_key)
165+
return json.loads(origin_task_data)
166+
except:
167+
return
168+
169+
170+
def main(pipeline_id, project, timeout):
171+
print("create a new task")
172+
print("working....")
173+
logo = text2art('OceanBase Farm')
174+
print(logo)
175+
oss_proxy = OssProxy("https://obfarm-ce.oss-cn-hongkong.aliyuncs.com")
176+
github_proxy = GithubProxy()
177+
job_info = github_proxy.get_job_by_id(project, pipeline_id)
178+
attempt_number = job_info["run_attempt"]
179+
run_pipeline_id = "{}-{}".format(pipeline_id, attempt_number)
180+
result = monitor_tasks(oss_proxy, run_pipeline_id, timeout)
181+
if not result:
182+
exit(1)
183+
184+
185+
if __name__ == "__main__":
186+
print(sys.argv)
187+
if len(sys.argv) < 4:
188+
print("Missing relevant parameters !")
189+
OUTPUT.update({"success": -1})
190+
sys.exit(1)
191+
main(sys.argv[1], sys.argv[2], sys.argv[3])
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Build base"
2+
3+
inputs:
4+
save_cache:
5+
description: 'whether to save ccache to github action cache'
6+
required: true
7+
os:
8+
description: 'which runner os to run this build action'
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Build init
15+
shell: bash
16+
run: |
17+
bash build.sh init
18+
echo "$GITHUB_WORKSPACE/deps/3rd/usr/local/oceanbase/devtools/bin" >> $GITHUB_PATH
19+
20+
- name: Setup ccache
21+
uses: hendrikmuhs/ccache-action@v1.2
22+
with:
23+
max-size: 800M
24+
save: ${{inputs.save_cache}}
25+
key: ${{inputs.os}}
26+
27+
- name: Build project
28+
shell: bash
29+
run: |
30+
bash build.sh debug -DOB_USE_CCACHE=ON
31+
cd build_debug && make -j4
32+
ccache -s

.github/workflows/codeql.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CodeQL
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * 1" # every Monday
6+
7+
jobs:
8+
codeql:
9+
runs-on: ubuntu-22.04
10+
steps:
11+
- name: Maximize build space
12+
uses: easimon/maximize-build-space@master
13+
with:
14+
root-reserve-mb: 20480 # reserve for CodeQL
15+
remove-dotnet: 'true'
16+
remove-android: 'true'
17+
remove-haskell: 'true'
18+
remove-docker-images: 'true'
19+
20+
- name: Install ubuntu environment
21+
shell: bash
22+
run: |
23+
export DEBIAN_FRONTEND=noninteractive
24+
sudo apt-get update
25+
sudo apt-get install -y git wget rpm rpm2cpio cpio make build-essential binutils m4 libtool-bin libncurses5
26+
27+
- uses: actions/checkout@v3
28+
29+
- name: Cache deps
30+
id: cache-deps
31+
uses: actions/cache@v3
32+
env:
33+
cache-name: cache-deps
34+
with:
35+
key: ${{ runner.os }}-build-${{ env.cache-name }}-el9.x86_64-${{ hashFiles('deps/init/oceanbase.el9.x86_64.deps') }}
36+
path: deps/3rd
37+
38+
- name: Initialize CodeQL
39+
uses: github/codeql-action/init@v2
40+
with:
41+
languages: cpp
42+
43+
- name: Build project
44+
shell: bash
45+
run: |
46+
rm -rf build_debug
47+
bash build.sh debug --init --make -j3
48+
49+
- name: Perform CodeQL Analysis
50+
uses: github/codeql-action/analyze@v2
51+
with:
52+
category: "/language:cpp"

.github/workflows/compile.yml

+35-24
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,19 @@ name: Compile
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, develop ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ master, develop ]
88

99
jobs:
10-
build:
11-
strategy:
12-
matrix:
13-
image: ['ubuntu:22.04', 'centos:7']
10+
centos-build:
1411
runs-on: ubuntu-20.04
15-
container: ${{ matrix.image }}
12+
container: centos:7
1613
steps:
1714
- uses: actions/checkout@v3
1815

19-
- name: Install ubuntu environment
20-
shell: bash
21-
if: ${{ startsWith(matrix.image, 'ubuntu') }}
22-
run: |
23-
export DEBIAN_FRONTEND=noninteractive
24-
apt-get update
25-
apt-get install -y git wget rpm rpm2cpio cpio make build-essential binutils m4 libtool-bin libncurses5
26-
2716
- name: Install centos environment
2817
shell: bash
29-
if: ${{ startsWith(matrix.image, 'centos') }}
3018
run: yum install -y git wget rpm* cpio make glibc-devel glibc-headers binutils m4
3119

3220
- name: Cache deps
@@ -37,13 +25,36 @@ jobs:
3725
with:
3826
key: ${{ runner.os }}-build-${{ env.cache-name }}-el7.x86_64-${{ hashFiles('deps/init/oceanbase.el7.x86_64.deps') }}
3927
path: deps/3rd
40-
enableCrossOsArchive: true
41-
42-
- name: Build init
43-
run: bash build.sh init
44-
45-
- name: Build project
28+
29+
- name: Build
30+
uses: ./.github/workflows/buildbase
31+
with:
32+
save_cache: ${{github.event_name == 'push'}}
33+
os: 'centos7'
34+
35+
ubuntu-build:
36+
runs-on: ubuntu-22.04
37+
steps:
38+
- uses: actions/checkout@v3
39+
40+
- name: Install ubuntu environment
4641
shell: bash
4742
run: |
48-
bash build.sh debug
49-
cd build_debug && make -j4
43+
export DEBIAN_FRONTEND=noninteractive
44+
sudo apt-get update
45+
sudo apt-get install -y git wget rpm rpm2cpio cpio make build-essential binutils m4 libtool-bin libncurses5
46+
47+
- name: Cache deps
48+
id: cache-deps
49+
uses: actions/cache@v3
50+
env:
51+
cache-name: cache-deps
52+
with:
53+
key: ${{ runner.os }}-build-${{ env.cache-name }}-el9.x86_64-${{ hashFiles('deps/init/oceanbase.el9.x86_64.deps') }}
54+
path: deps/3rd
55+
56+
- name: Build
57+
uses: ./.github/workflows/buildbase
58+
with:
59+
save_cache: ${{github.event_name == 'push'}}
60+
os: 'ubuntu22'

0 commit comments

Comments
 (0)