add test ci #42
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
pull_request: | |
branches: | |
- main | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- edited | |
permissions: | |
contents: read | |
pull-requests: write | |
issues: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
pre-test: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
need_to_run: ${{ steps.set-matrix.outputs.need_to_run }} | |
steps: | |
- name: generate matrix from PR body | |
id: set-matrix | |
env: | |
RAW_BODY: ${{ github.event.pull_request.body }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const result = []; | |
const taskRegexp = /- \[x\] (.*)/g; | |
let match; | |
while ((match = taskRegexp.exec(process.env.RAW_BODY)) !== null) { | |
result.push(match[1]) | |
} | |
core.setOutput("matrix", result); | |
core.setOutput("need_to_run", result.length > 0); | |
test: | |
runs-on: ubuntu-latest | |
needs: pre-test | |
if: ${{ needs.pre-test.outputs.need_to_run == 'true' }} | |
outputs: | |
matrix: ${{ needs.pre-test.outputs.matrix }} | |
strategy: | |
fail-fast: true | |
matrix: | |
target-arch: ${{ fromJSON(needs.pre-test.outputs.matrix) }} | |
steps: | |
# - name: Checkout | |
# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
# - name: Update kernel submodules | |
# if: ${{ startsWith(matrix.target-arch, 'kernel') }} | |
# run: git submodule update --init kernel | |
# - name: Update buildroot submodules | |
# if: ${{ startsWith(matrix.target-arch, 'kernel') }} | |
# run: git submodule update --init buildroot | |
# - name: Install deps | |
# run: sudo apt-get install -y build-essential flex bison libssl-dev libelf-dev bc | |
# - name: Install kernel arm64 deps | |
# if: ${{ matrix.target-arch == 'kernel-arm64' }} | |
# run: sudo apt-get install -y gcc-aarch64-linux-gnu | |
# - name: Defconfig | |
# run: make defconfig-${{ matrix.target-arch }} | |
# - name: Build | |
# run: make build-${{ matrix.target-arch }} | |
- name: Get output file size | |
run: | | |
# FILE_PATH=$(make print-outpath-${{ matrix.target-arch }}) | |
FILE_PATH=/usr/bin/ls | |
SIZE_B=$(stat -c%s "$FILE_PATH") | |
SIZE_MB=$(echo $SIZE_B | awk '{ printf "%.4f", $1 / 1024 / 1024 }') | |
mkdir outputs-size | |
echo "${{ matrix.target-arch }} $SIZE_MB $SIZE_B" > outputs-size/${{ matrix.target-arch }}.txt | |
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 | |
with: | |
name: ${{ github.run_id }}-${{ github.run_number }}-${{ matrix.target-arch }} | |
path: outputs-size/*.txt | |
retention-days: 1 | |
post-test: | |
runs-on: ubuntu-latest | |
needs: | |
- pre-test | |
- test | |
if: ${{ needs.pre-test.outputs.need_to_run == 'true' }} | |
steps: | |
- name: Load outputs-size | |
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2 | |
with: | |
pattern: ${{ github.run_id }}-${{ github.run_number }}-* | |
path: outputs-size | |
merge-multiple: true | |
- name: Format outputs-size | |
id: size | |
run: | | |
RESULT=`sort outputs-size/*.txt | awk '{ printf "|**"$1"**|*"$2"MB ("$3" bytes)*|\n" }'` | |
echo 'result=<<EOF' >> $GITHUB_OUTPUT | |
echo "$RESULT" >> $GITHUB_OUTPUT | |
echo 'EOF' >> $GITHUB_OUTPUT | |
# echo 'result="$RESULT"' > a | |
# cat ./a | |
# cat ./a >> $GITHUB_OUTPUT | |
# cat > $GITHUB_OUTPUT <<EOF | |
# result=|Target|Size| | |
# |-|-| | |
# $RESULT | |
# EOF | |
# echo -n -e "result=|Target|Size|\n|-|-|\n"$RESULT > $GITHUB_OUTPUT | |
- name: generate matrix from PR body | |
id: comment | |
uses: actions/github-script@v7 | |
env: | |
SIZE: ${{ steps.size.outputs.result }} | |
with: | |
result-encoding: string | |
script: | | |
const result = `|Target|Size| | |
|-|-| | |
${process.env.SIZE}`; | |
return result; | |
- name: Find comment | |
uses: peter-evans/find-comment@d5fe37641ad8451bdd80312415672ba26c86575e # v3.0.0 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: Build Output Summary | |
- name: Create or update comment | |
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
Build Output Summary | |
${{ steps.comment.outputs.result }} | |
edit-mode: replace |