1+ name : Paddle Repos Sync Triggered by Commit Using Repository Dispatch
2+ run-name : Paddle repos sync runs triggered by commit using ${{ github.event_name }}
3+ on :
4+ repository_dispatch :
5+ types : [sync-event-commit]
6+
7+ jobs :
8+ paddleqa-checkout :
9+ environment : CodeSync
10+ runs-on : ubuntu-latest
11+ name : Repo Checkout and Upload
12+ steps :
13+ - name : PaddleTest Checkout
14+ uses : actions/checkout@v4
15+ with :
16+ sparse-checkout : |
17+ tools
18+ - name : Code Checkout
19+ id : checkout
20+ uses :
XieYunshen/[email protected] 21+ with :
22+ repository : ${{ github.event.client_payload.repository }}
23+ ref : ${{ github.event.client_payload.ref }}
24+ submodules : ${{ github.event.client_payload.submodules }}
25+ fetch_depth : ${{ github.event.client_payload.fetch_depth }}
26+ path : ${{ github.event.client_payload.path }}
27+ commit_sha : ${{ github.event.client_payload.commit_sha }}
28+ repo_compress : ${{ github.event.client_payload.repo_compress }}
29+ - uses : actions/setup-python@v5
30+ with :
31+ python-version : ' 3.10'
32+ - name : Upload Code
33+ env :
34+ AK : ${{ secrets.BOS_AK }}
35+ SK : ${{ secrets.BOS_SK }}
36+ run : |
37+ git log -n 3
38+ tree -L 3
39+ current_commit=$(git rev-parse HEAD)
40+ REPO_NAME=${{ github.event.client_payload.repository }}
41+ REPO_NAME=${REPO_NAME##*/}
42+ file_name=$REPO_NAME.tar
43+ cd ${{ github.event.client_payload.path }}
44+ current_commit=$(git rev-parse HEAD)
45+ current_commit_time=$(git show -s --format=%ct HEAD)
46+ cd -
47+ tar -cf $REPO_NAME.tar ${{ github.event.client_payload.path }}
48+ python -m pip install bce-python-sdk==0.8.74
49+ # 获取远端的最新提交时间
50+ latest_commit_time_remote=$(curl --silent --fail https://paddle-qa.bj.bcebos.com/CodeSync/GitInfo/${{ github.event.client_payload.repository }}/${{ github.event.client_payload.ref }}/${{ github.event.client_payload.commit_sha }}/latest_commit_time) || latest_commit_time_remote=0
51+ # 判断 latest_commit_time_remote 是否晚于 current_commit_time 时间
52+ if [ -n "$latest_commit_time_remote" ] && [ "$latest_commit_time_remote" -lt "$current_commit_time" ]; then
53+ echo "Executing upload as latest commit time ($latest_commit_time_remote) is earlier than current commit time ($current_commit_time)."
54+ python tools/bos_upload.py ${file_name} paddle-qa/CodeSync/${{ github.event.client_payload.ref }}/${{ github.event.client_payload.commit_sha }}
55+ echo "Bos link: https://paddle-qa.bj.bcebos.com/CodeSync/${{ github.event.client_payload.ref }}/${{ github.event.client_payload.commit_sha }}/$file_name"
56+ echo "${current_commit_time}" >> latest_commit_time
57+ python tools/bos_upload.py latest_commit_time paddle-qa/CodeSync/GitInfo/${{ github.event.client_payload.repository }}/${{ github.event.client_payload.ref }}/${{ github.event.client_payload.commit_sha }}
58+ echo "${current_commit}" >> latest_commit
59+ python tools/bos_upload.py latest_commit paddle-qa/CodeSync/GitInfo/${{ github.event.client_payload.repository }}/${{ github.event.client_payload.ref }}/${{ github.event.client_payload.commit_sha }}
60+ echo "GitInfo link: https://paddle-qa.bj.bcebos.com/CodeSync/GitInfo/${{ github.event.client_payload.repository }}/${{ github.event.client_payload.ref }}/${{ github.event.client_payload.commit_sha }}/latest_commit_sha"
61+ echo "GitInfo link: https://paddle-qa.bj.bcebos.com/CodeSync/GitInfo/${{ github.event.client_payload.repository }}/${{ github.event.client_payload.ref }}/${{ github.event.client_payload.commit_sha }}/latest_commit_time"
62+ else
63+ echo "The latest commit time is later than the current commit. Skipping the commit operation."
64+ fi
0 commit comments