Skip to content

feature: add github actions for pull request #8

feature: add github actions for pull request

feature: add github actions for pull request #8

Workflow file for this run

name: Build
on:
pull_request:
branches:
- main
- dev
env:
DST_BASE: /data1/k230/github-actions/k230_linux_sdk
SUB_BASE: ${{ github.event.number }}_${{ github.run_id }}
TFTP_ROOT: /data1/tftp_server
NFS_ROOT: /data/nfs_server
HW_VER: v0.1
defaults:
run:
shell: bash
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
build_image:
name: Build
runs-on: [self-hosted, k230_linux_sdk]
timeout-minutes: 45
container:
image: ai.b-bug.org:5000/k230_sdk:latest
env:
CONF: ${{ matrix.hw_type }}_${{ matrix.hw_model }}_defconfig
volumes:
- /data:/data
- /data1:/data1
options: --hostname runner
strategy:
matrix:
hw_type: ["k230"]
hw_model: ["canmv"]
outputs:
image_md5: ${{ steps.save_tftp.outputs.image_md5 }}
image_path: ${{ steps.save_tftp.outputs.image_path }}
steps:
- name: Install node for action/checkout
id: install_node
run: |
set -x
PR_REPO=${{ github.event.pull_request.head.repo.full_name }}
PR_BRANCH=${{ github.event.pull_request.head.ref }}
BASE_REPO=${{ github.repository }}
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
echo "PR_REPO: ${PR_REPO}, PR_BRANCH: ${PR_BRANCH}"
echo "BASE_REPO: ${BASE_REPO}, BASE_BRANCH: ${BASE_BRANCH}"
# cache from https://nodejs.org/en/download/prebuilt-binaries
pwd
whoami
ls -alht
sudo wget https://ai.b-bug.org/k230/test_resources/ci/packages/node-v20.15.0-linux-x64.tar.xz || exit 1
ls -alht
sudo mkdir /opt/node/ || exit 1
tar -xf node-v20.15.0-linux-x64.tar.xz --strip-components=1 -C /opt/node/ || exit 1
sudo chmod -R 755 /opt/node || exit 1
ls /opt/node/bin/
echo "show version with path"
/opt/node/bin/node --version
export NODEJS_HOME=/opt/node/bin/
export PATH=$NODEJS_HOME:$PATH
echo "confirm version without path"
node --version || exit 1
npm --version
which node
which npm
set +x
- name: Checkout Source Code
uses: actions/checkout@v4
with:
fetch-depth: 0
clean: true
- name: Build Env Setup
id: build_env
run: |
echo '----------Build ENV Prepare----------'
echo 'Add SSH KEY for Multiple repo'
'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
eval $(ssh-agent -s)
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "$SSH_PRIVATE_KEY" | ssh-add - > ~/.ssh/id_ed25519 || exit 1
'[[ -f /.dockerenv ]] && echo -e "Host *\n StrictHostKeyChecking no\n" > ~/.ssh/config'
echo $SHELL
echo "increate ssh timeout for github"
echo " ServerAliveInterval 30" >> ~/.ssh/config
echo " ServerAliveCountMax 60" >> ~/.ssh/config
echo " TCPKeepAlive yes" >> ~/.ssh/config
cat ~/.ssh/config
whoami
uptime
pwd
uname -a
cat /etc/issue
echo '----------fetch all tags----------'
git fetch --tags
HW_TYPE=$(echo $CONF | awk -F '_' '{print $1}')
HW_MODEL=$(echo $CONF | awk -F "_" '{if ($3 == "v2") print $2"_"$3; else print $2}')
echo "HW_TYPE ${HW_TYPE}, HW_MODEL ${HW_MODEL}"
- name: Build Image
id: build_image
run: |
pwd
echo "----------start to build linux sdk image----------"
time make CONF=${CONF} BR2_PRIMARY_SITE=${DL_SITE} || exit 1
echo "----------show linux sdk image build output----------"
pwd
du -h -d 2 output/${CONF}/ || exit 1
ls -alht output/${CONF}/images || exit 1
echo "----------remove img----------"
rm -rf output/${CONF}/images/sysimage-sdcard.img
echo "----------build sdk image done----------"
- name: Save Image
id: save_image
run: |
pwd
echo "----------save image----------"
SRC_DIR="./output/${CONF}/images"
echo "SRC_DIR: ${SRC_DIR}"
echo ${DST_BASE}
echo "set DST_DIR with different type based on docs/images/src"
DST_DIR="${DST_BASE}/images"
echo "DST_DIR: ${DST_DIR}"
echo "---create repo dir---"
sudo mkdir -p ${DST_DIR}
echo "----------Save build to external path----------"
SUB_DIR="${SUB_BASE}/${CONF}";
echo "---create current image version dir---"
sudo mkdir -p ${DST_DIR}/${SUB_DIR}/ || exit 1
echo "---save sdk build output---"
sudo cp -rf --sparse=always -L ${SRC_DIR}/${HW_TYPE}_${HW_MODEL}_*.img.gz ${DST_DIR}/${SUB_DIR}/
echo "${DST_DIR}/${SUB_DIR}/"
ls "${DST_DIR}/${SUB_DIR}/"
echo "add latest link for current build"
test -h ${DST_DIR}/latest && sudo rm ${DST_DIR}/latest
sudo ln -s ${DST_DIR}/${ver} ${DST_DIR}/latest || exit 1
ls ${DST_DIR}/latest
echo "----------output URL----------"
echo "${DST_DIR}/${SUB_DIR}/" | sed "s/\/data1/https:\/\/ai\.b-bug\.org/g"
echo "----------save image done----------"
- name: Save image to TFTP
id: save_tftp
run: |
echo "start to save test image for config: ${CONF} ------";
echo "SRC_DIR: ${SRC_DIR}"
echo ${TFTP_BASE};
echo "set DST_DIR with different type based on docs/images/src";
DST_DIR="${TFTP_BASE}/${HW_TYPE}/${HW_MODEL}_${HW_VER}";
echo ${DST_DIR};
SUB_DIR=${SUB_BASE}/${CONF}
echo "---create tftp dir---";
sudo mkdir -p ${DST_DIR}/${SUB_DIR}/ || exit 1;
sudo cp -rf --sparse=always -L ${SRC_DIR}/${HW_TYPE}_${HW_MODEL}_*.img.gz ${DST_DIR}/${SUB_DIR}
cp --sparse=always $CONF/images/k510.dtb $SAVE_DIR/k510.dtb
image_md5=$(md5sum ${DST_DIR}/${SUB_DIR}/${HW_TYPE}_${HW_MODEL}_*.img.gz | awk '{print $1}')
image_path="${DST_DIR}/${SUB_DIR}/"
echo $image_md5
echo $image_path
echo "image_md5=$image_md5" >> $GITHUB_OUTPUT
echo "image_path=$image_path" >> $GITHUB_OUTPUT
test_image:
name: Test
needs: build_image
timeout-minutes: 15
runs-on: [self-hosted, k230_linux_sdk]
env:
CONF: ${{ matrix.hw_type }}_${{ matrix.hw_model }}_defconfig
container:
image: ai.b-bug.org:5000/k230_sdk:latest
volumes:
- /data:/data
- /data1:/data1
options: --hostname runner
strategy:
matrix:
hw_type: ["k230"]
hw_model: ["canmv"]
steps:
- name: Run Test
id: run_test
run: |
echo "=============================="
echo "There is NO test job NOW"
echo "=============================="
echo "add this stage for future job"
echo "=============================="
echo "image md5: ${{needs.build_image.outputs.image_md5}}"
echo "image path: ${{needs.build_image.outputs.image_path}}"
whoami
uptime
pwd
uname -a
cat /etc/issue
HW_TYPE=$(echo $CONF | awk -F '_' '{print $1}')
HW_MODEL=$(echo $CONF | awk -F "_" '{if ($3 == "v2") print $2"_"$3; else print $2}')
echo "HW_TYPE ${HW_TYPE}, HW_MODEL ${HW_MODEL}"