Skip to content

add add-reviewers.yml automatically adds reviewers to pull requests #16

add add-reviewers.yml automatically adds reviewers to pull requests

add add-reviewers.yml automatically adds reviewers to pull requests #16

Workflow file for this run

# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
pull_request_target:
types: [opened, reopened, synchronize]
# reusable
workflow_call:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Get Repo Name
run: |
echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Get Current Action URL
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_SERVER_URL: ${{ github.server_url }}
run: |
echo "Current Action URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
echo "CURRENT_ACTION_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV
- name: Parse PR Description for Dependencies
id: parse-dependencies
run: |
set -x
# 获取当前 PR 的描述
cat > pull_request.body.txt <<EOF
${{ github.event.pull_request.body }}
EOF
DEPENDS_ON=$(grep -oP 'depends-on:\K(.*)' pull_request.body.txt | sed 's/^ *//;s/ *$//')
echo "PR DEPENDS_ON: $DEPENDS_ON"
ALL_PR="$DEPENDS_ON ${{ github.repository }}:${{ github.event.pull_request.number }}"
manifest_part=$(echo "$ALL_PR" | grep -o 'open-vela/manifests[^ ]*') || true
if [ "$manifest_part"X != ""X ]; then
without_manifest_pr=$(echo "$ALL_PR" | sed "s|$manifest_part||" | xargs)
ALL_PR="$manifest_part $without_manifest_pr"
fi
echo "ALL_PR=$ALL_PR" >> $GITHUB_ENV
echo "DEPENDS_ON=$DEPENDS_ON" >> $GITHUB_ENV
for DEPENDENCY in $DEPENDS_ON; do
REPO_NAME=$(echo $DEPENDENCY | cut -d ':' -f 1)
PR_NUMBER=$(echo $DEPENDENCY | cut -d ':' -f 2)
PR_COMMITS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$REPO_NAME/pulls/$PR_NUMBER")
LATEST_SHA=$(echo "$PR_COMMITS" | jq -r '.head.sha')
if [[ -z "$LATEST_SHA" ]]; then
echo "No commits found for PR #$PR_NUMBER or invalid API response."
exit 1
fi
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO_NAME/statuses/$LATEST_SHA \
-d '{
"state": "pending",
"description": "In progress",
"context": "CI triggered by other PR",
"target_url": "${{ env.CURRENT_ACTION_URL }}"
}'
done
- name: Download and install repo
run: |
mkdir ~/bin
echo 'export PATH=~/bin:$PATH' >> $HOME/.bashrc
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
- name: Clean up disk space
run: |
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /etc/apt/sources.list.d/* /usr/local/lib/android /etc/mysql /etc/php /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
sudo docker builder prune -a
sudo docker system prune -af
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
sudo -E apt-get -qq update
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
df -h
- name: Verify repo installation
run: |
~/bin/repo --version
- name: Get PR source branch name
id: get_branch_name
run: |
PR_BRANCH=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")
echo "branch_name=$PR_BRANCH" >> $GITHUB_OUTPUT
- name: Repo Init
run: |
~/bin/repo init -u https://github.com/open-vela/manifests -b ${{ github.event.pull_request.base.ref }} -m openvela.xml --depth=1 --git-lfs
echo "REPO_INIT=true" >> $GITHUB_ENV
- name: Repo Sync
run: |
df -h
~/bin/repo sync -c -d --no-tags -j12
df -h
- name: Fetch PR
if: ${{ github.event_name == 'pull_request_target' }}
run: |
current_path=$(pwd)
echo "REPO_ROOT=$current_path" >> $GITHUB_ENV
echo $(ls -atl)
git config --global user.email "[email protected]"
git config --global user.name "openvela-robot"
set -x
repo_sync_code=0
cp_code=0
cp_log=$current_path/cp.log
for DEPENDENCY in ${{ env.ALL_PR }}; do
REPO_FULL_PATH=$(echo $DEPENDENCY | cut -d ':' -f 1)
PR_NUMBER=$(echo $DEPENDENCY | cut -d ':' -f 2)
PROJECT_NAME=$(echo $REPO_FULL_PATH | cut -d '/' -f 2)
if [ $PROJECT_NAME == "manifests" ]; then
cd .repo/manifests
echo "git fetch origin pull/$PR_NUMBER/head:pr-branch"
git fetch origin pull/$PR_NUMBER/head:pr-branch
echo "git cherry-pick $(git rev-list --reverse HEAD..pr-branch)"
set +e
cp_pr_result=$(git cherry-pick $(git rev-list --reverse HEAD..pr-branch) >> $cp_log 2>&1)
cp_pr_code=$?
if [ $cp_pr_code -ne 0 ]; then
cp_code=1
fi
echo $cp_pr_result
cd -
~/bin/repo sync -c -d --no-tags -j12
if [ $? -ne 0 ]; then
repo_sync_code=1
fi
else
manifest_content=$(cat .repo/manifests/openvela.xml)
echo $manifest_content
REPO_PATH=$(cat .repo/manifests/openvela.xml | grep "\"$PROJECT_NAME\"" | awk -F'"' '{print $2}')
echo $REPO_PATH
cd $REPO_PATH
echo "git fetch openvela pull/$PR_NUMBER/head:pr-branch"
git fetch openvela pull/$PR_NUMBER/head:pr-branch
echo "git cherry-pick $(git rev-list --reverse HEAD..pr-branch)"
set +e
cp_pr_result=$(git cherry-pick $(git rev-list --reverse HEAD..pr-branch) >> $cp_log 2>&1)
cp_pr_code=$?
if [ $cp_pr_code -ne 0 ]; then
cp_code=1
fi
echo $cp_pr_result
cd -
fi
done
echo "REPO_SYNC_CODE=$repo_sync_code" >> $GITHUB_ENV
echo "CP_PR_CODE=$cp_code" >> $GITHUB_ENV
continue-on-error: true
- name: check cherry-pick pr result
run: |
if [ -n "${{ env.REPO_SYNC_CODE }}" ] && [ ${{ env.REPO_SYNC_CODE }} != 0 ]; then
echo "repo sync after cherry-pick manifest PR failed."
exit 1
else
echo "repo sync after cherry-pick manifest PR success."
fi
if [ ${{ env.CP_PR_CODE }} == 0 ]; then
echo "cherry-pick PR success and continue."
else
cat ${{ env.REPO_ROOT }}/cp.log | grep "is a merge"
if [ $? -eq 0 ]; then
echo "There's merge commit in your PR. Please use rebase insteadof merge."
exit 1
else
echo "cherry-pick PR failed with error message: ${{ env.CP_PR_RESULT }}"
exit 1
fi
fi
- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Pull
run: docker pull ghcr.io/open-vela/openvela-ci-linux_from_apache-nuttx
- name: Run CI tasks inside Docker container
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/open-vela/openvela-ci-linux_from_apache-nuttx:latest \
/bin/bash -c "ls -atl && ./build.sh vendor/openvela/boards/vela/configs/goldfish-armeabi-v7a-ap -e -Werror -j8"
- name: Upload goldfish-armeabi-v7a-ap Artifact
uses: actions/upload-artifact@v3
with:
name: goldfish-armeabi-v7a-ap_${{ env.REPO_NAME }}-${{ github.event.pull_request.number }}
path: nuttx/nuttx
- name: Clean
run: |
echo 'export PATH=~/bin:$PATH' >> $HOME/.bashrc
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
sudo ~/bin/repo forall -v -c git clean -dfx; git reset --hard HEAD
continue-on-error: true
- name: Run test build inside Docker container
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/open-vela/openvela-ci-linux_from_apache-nuttx:latest \
/bin/bash -c "./build.sh vendor/openvela/boards/vela/configs/goldfish-armeabi-v7a-ap-citest -e -Werror -j8"
- name: Run autotest tasks inside Docker container
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/open-vela/openvela-ci-linux_from_apache-nuttx:latest \
/bin/bash -c "cd tests/scripts/script && pytest -m 'common or goldfish_armeabi_v7a_ap' ./ -B goldfish-armeabi-v7a-ap -L /workspace -P /workspace -F /tmp -R qemu -v --disable-warnings --count=1 --json=/workspace/autotest.json"
- name: Check autotest result
id: autotest_result
run: |
cd ${{ github.workspace }}
mkdir output
cp nuttx/nuttx ./*.log ./autotest.json output
failed=$(cat autotest.json | jq '.report.summary.failed')
if [ "$failed" != "null" ] && [ "$failed" != "0" ]; then
echo "autotest failed: $failed"
result="failed"
else
echo "autotest passed"
result="success"
fi
echo "::set-output name=AUTOTEST_RESULT::${result}"
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: goldfish-armeabi-v7a-ap-citest_${{ env.REPO_NAME }}-${{ github.event.pull_request.number }}
path: output/
- name: Exit with autotest exit code
run: |
if [ ${{ steps.autotest_result.outputs.AUTOTEST_RESULT }} == "success" ]; then
exit 0;
else
exit 1;
fi
- name: Post Processing
if: always() # 确保无论之前的步骤成功或失败,都会执行
run: |
echo "Job status: ${{ job.status }}"
if [[ "${{ job.status }}" == "success" ]]; then
ci_status="success"
else
ci_status="failure"
fi
for DEPENDENCY in ${{ env.DEPENDS_ON }}; do
REPO_NAME=$(echo $DEPENDENCY | cut -d ':' -f 1)
PR_NUMBER=$(echo $DEPENDENCY | cut -d ':' -f 2)
PR_COMMITS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$REPO_NAME/pulls/$PR_NUMBER")
LATEST_SHA=$(echo "$PR_COMMITS" | jq -r '.head.sha')
if [[ -z "$LATEST_SHA" ]]; then
echo "No commits found for PR #$PR_NUMBER or invalid API response."
exit 1
fi
set -x
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO_NAME/statuses/$LATEST_SHA \
-d '{
"state": '"\"$ci_status\""',
"description": "CI '"$ci_status"'",
"context": "CI triggered by other PR",
"target_url": "${{ env.CURRENT_ACTION_URL }}"
}'
set +x
done