diff --git a/.github/workflows/maintenance-rewrite-kernel-patches.yml b/.github/workflows/maintenance-rewrite-kernel-patches.yml new file mode 100644 index 0000000000..c311fe6839 --- /dev/null +++ b/.github/workflows/maintenance-rewrite-kernel-patches.yml @@ -0,0 +1,127 @@ +name: "Maintenance: Rewrite kernel patches" + +on: + workflow_dispatch: + inputs: + board: + description: "Board name (e.g. bananapim5, khadas-vim3)" + required: true + type: string + branch: + description: "Branch to use" + required: true + type: choice + options: + - legacy + - vendor + - current + - edge + whattodo: + description: "rewrite uboot or kernel patches" + required: true + type: choice + options: + - rewrite-kernel-patches + - rewrite-uboot-patches + +permissions: + contents: write + pull-requests: write + +jobs: + rewrite-patches: + name: "Rewrite ${{ inputs.board }} (${{ inputs.branch }})" + runs-on: rewrite + steps: + - name: Update existing repository + run: | + # Clone or update the repository + if [ -d .git ]; then + # Repo exists: update it + git fetch origin + git reset --hard origin/${{ github.ref_name }} + git checkout ${{ github.ref_name }} + git pull origin ${{ github.ref_name }} + else + # No repo: clone it + git clone --filter=blob:none "https://github.com/${{ github.repository }}" . + git checkout ${{ github.ref_name }} + fi + + - name: Run rewrite-kernel-patches + env: + BOARD: ${{ inputs.board }} + BRANCH: ${{ inputs.branch }} + WHATTODO: ${{ inputs.whattodo }} + run: | + ./compile.sh BOARD=$BOARD BRANCH=$BRANCH $WHATTODO KERNEL_GIT=shallow + + - name: Check for changes + id: check_changes + run: | + set -euo pipefail + if git diff --quiet; then + echo "has_changes=false" >> "$GITHUB_OUTPUT" + echo "::notice::No changes detected after rewrite-kernel-patches" + else + echo "has_changes=true" >> "$GITHUB_OUTPUT" + echo "::notice::Changes detected after rewrite-kernel-patches - PR will be created" + fi + + - name: Build PR body + id: build_pr_body + if: steps.check_changes.outputs.has_changes == 'true' + run: | + set -euo pipefail + + # Per-file stats + tmp_stats=$(mktemp) + tmp_body=$(mktemp) + git diff --numstat > "$tmp_stats" || true + + total_add=0; total_del=0; files=0 + { + echo "| File | + | - | Δ |" + echo "|---|---:|---:|---:|" + while IFS=$'\t' read -r add del path; do + [[ -z "${path:-}" ]] && continue + [[ "$add" =~ ^[0-9]+$ ]] || add=0 + [[ "$del" =~ ^[0-9]+$ ]] || del=0 + delta=$(( add - del )) + total_add=$(( total_add + add )) + total_del=$(( total_del + del )) + files=$(( files + 1 )) + path_esc="${path//|/\\|}" + printf "| %s | %d | %d | %d |\n" "$path_esc" "$add" "$del" "$delta" + done < "$tmp_stats" + echo + printf "**Files:** %d • **Lines:** +%d / -%d (Δ %d)\n" "$files" "$total_add" "$total_del" "$(( total_add - total_del ))" + } > "$tmp_body" + + echo "pr_body_path=$tmp_body" >> "$GITHUB_OUTPUT" + + - name: Open / Update PR + id: create_pr + if: steps.check_changes.outputs.has_changes == 'true' + uses: peter-evans/create-pull-request@v8 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: rewrite-patches/${{ inputs.board }}-${{ inputs.branch }} + delete-branch: true + base: main + title: "`[${{ inputs.branch }}]` kernel patches rewrite for `${{ inputs.board }}`" + commit-message: "[${{ inputs.branch }}] kernel patches rewrite for ${{ inputs.board }}" + body-path: ${{ steps.build_pr_body.outputs.pr_body_path }} + labels: | + Needs review + + - name: Cleanup temp files + if: steps.build_pr_body.outputs.pr_body_path != '' + run: | + rm -f "${{ steps.build_pr_body.outputs.pr_body_path }}" || true + + - name: Reset working directory for next run + if: always() + run: | + git reset --hard HEAD + git clean -fd