|
| 1 | +name: Build PR Profile |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +permissions: |
| 7 | + pull-requests: write |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: build-on-pr-${{ github.event.pull_request.number }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-and-build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Parse build command from PR description |
| 19 | + id: parse-command |
| 20 | + run: | |
| 21 | + DESCRIPTION=$(cat <<'EOF' |
| 22 | + ${{ github.event.pull_request.body }} |
| 23 | + EOF |
| 24 | + ) |
| 25 | + if echo "$DESCRIPTION" | grep -q "build [a-zA-Z0-9_-]\+/[a-zA-Z0-9_-]\+/[a-zA-Z0-9_-]\+"; then |
| 26 | + BUILD_PATH=$(echo "$DESCRIPTION" | grep -o "build [a-zA-Z0-9_-]\+/[a-zA-Z0-9_-]\+/[a-zA-Z0-9_-]\+" | head -1 | sed 's/build //') |
| 27 | + TARGET=$(echo "$BUILD_PATH" | cut -d'/' -f1) |
| 28 | + SUBTARGET=$(echo "$BUILD_PATH" | cut -d'/' -f2) |
| 29 | + PROFILE=$(echo "$BUILD_PATH" | cut -d'/' -f3) |
| 30 | + echo "build_requested=true" >> $GITHUB_OUTPUT |
| 31 | + echo "target=$TARGET" >> $GITHUB_OUTPUT |
| 32 | + echo "subtarget=$SUBTARGET" >> $GITHUB_OUTPUT |
| 33 | + echo "profile=$PROFILE" >> $GITHUB_OUTPUT |
| 34 | + echo "build_path=$BUILD_PATH" >> $GITHUB_OUTPUT |
| 35 | + else |
| 36 | + echo "build_requested=false" >> $GITHUB_OUTPUT |
| 37 | + fi |
| 38 | +
|
| 39 | + - name: Find existing build comment |
| 40 | + if: steps.parse-command.outputs.build_requested == 'true' |
| 41 | + id: find-comment |
| 42 | + uses: peter-evans/find-comment@v2 |
| 43 | + with: |
| 44 | + issue-number: ${{ github.event.pull_request.number }} |
| 45 | + comment-author: "github-actions[bot]" |
| 46 | + body-includes: "Build Results for" |
| 47 | + |
| 48 | + - name: Create early build comment |
| 49 | + if: steps.parse-command.outputs.build_requested == 'true' |
| 50 | + id: start-comment |
| 51 | + uses: peter-evans/create-or-update-comment@v3 |
| 52 | + with: |
| 53 | + issue-number: ${{ github.event.pull_request.number }} |
| 54 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 55 | + body: | |
| 56 | + ## Build Results for `${{ steps.parse-command.outputs.build_path }}` |
| 57 | +
|
| 58 | + Build in progress... |
| 59 | +
|
| 60 | + [Follow progress](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 61 | + edit-mode: replace |
| 62 | + |
| 63 | + - name: Checkout repository |
| 64 | + if: steps.parse-command.outputs.build_requested == 'true' |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + fetch-depth: 0 |
| 69 | + |
| 70 | + - name: Setup build environment |
| 71 | + if: steps.parse-command.outputs.build_requested == 'true' |
| 72 | + continue-on-error: true |
| 73 | + run: | |
| 74 | + sudo apt-get update |
| 75 | + sudo apt-get install -y build-essential libncurses5-dev gawk git subversion libssl-dev gettext zlib1g-dev swig unzip time rsync |
| 76 | +
|
| 77 | + - name: Build target |
| 78 | + if: steps.parse-command.outputs.build_requested == 'true' |
| 79 | + id: build |
| 80 | + run: | |
| 81 | + make defconfig |
| 82 | + echo "CONFIG_DEVEL=y" > .config |
| 83 | + echo "CONFIG_BPF_TOOLCHAIN_HOST=y" >> .config |
| 84 | + echo "CONFIG_TARGET_${{ steps.parse-command.outputs.target }}=y" >> .config |
| 85 | + echo "CONFIG_TARGET_${{ steps.parse-command.outputs.target }}_${{ steps.parse-command.outputs.subtarget }}=y" >> .config |
| 86 | + echo "CONFIG_TARGET_${{ steps.parse-command.outputs.target }}_${{ steps.parse-command.outputs.subtarget }}_DEVICE_${{ steps.parse-command.outputs.profile }}=y" >> .config |
| 87 | +
|
| 88 | + make defconfig |
| 89 | + make -j$(nproc) BUILD_LOG=1 |
| 90 | +
|
| 91 | + echo "build_success=true" >> $GITHUB_OUTPUT |
| 92 | +
|
| 93 | + - name: Upload log |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + if: steps.parse-command.outputs.build_requested == 'true' && (success() || failure()) |
| 96 | + with: |
| 97 | + name: build-log-${{ steps.parse-command.outputs.target }}-${{ steps.parse-command.outputs.subtarget }}-${{ steps.parse-command.outputs.profile }} |
| 98 | + path: logs/ |
| 99 | + |
| 100 | + - name: Create artifact archive |
| 101 | + if: steps.build.outputs.build_success == 'true' |
| 102 | + run: | |
| 103 | + cd bin/ |
| 104 | + tar -czf ../build-artifacts.tar.gz * |
| 105 | + cd .. |
| 106 | +
|
| 107 | + - name: Upload build artifacts |
| 108 | + if: steps.build.outputs.build_success == 'true' |
| 109 | + uses: actions/upload-artifact@v4 |
| 110 | + with: |
| 111 | + name: build-${{ steps.parse-command.outputs.target }}-${{ steps.parse-command.outputs.subtarget }}-${{ steps.parse-command.outputs.profile }} |
| 112 | + path: build-artifacts.tar.gz |
| 113 | + |
| 114 | + - name: Update comment with build results |
| 115 | + if: steps.build.outputs.build_success == 'true' |
| 116 | + uses: peter-evans/create-or-update-comment@v3 |
| 117 | + with: |
| 118 | + comment-id: ${{ steps.start-comment.outputs.comment-id }} |
| 119 | + issue-number: ${{ github.event.pull_request.number }} |
| 120 | + body: | |
| 121 | + ## Build Results for `${{ steps.parse-command.outputs.build_path }}` |
| 122 | +
|
| 123 | + Build completed successfully |
| 124 | +
|
| 125 | + **Target:** `${{ steps.parse-command.outputs.target }}` |
| 126 | + **Subtarget:** `${{ steps.parse-command.outputs.subtarget }}` |
| 127 | + **Profile:** `${{ steps.parse-command.outputs.profile }}` |
| 128 | +
|
| 129 | + [Download artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 130 | + edit-mode: replace |
| 131 | + |
| 132 | + - name: Update comment on build failure |
| 133 | + if: steps.parse-command.outputs.build_requested == 'true' && failure() |
| 134 | + uses: peter-evans/create-or-update-comment@v3 |
| 135 | + with: |
| 136 | + comment-id: ${{ steps.start-comment.outputs.comment-id }} |
| 137 | + issue-number: ${{ github.event.pull_request.number }} |
| 138 | + body: | |
| 139 | + ## Build Results for `${{ steps.parse-command.outputs.build_path }}` |
| 140 | +
|
| 141 | + Build failed |
| 142 | +
|
| 143 | + [Check logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 144 | + edit-mode: replace |
0 commit comments