name: "Maintenance: Rewrite 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 timeout-minutes: 60 steps: - name: Update existing repository env: REF_NAME: ${{ github.ref_name }} REPO: ${{ github.repository }} run: | # Clone or update the repository if [ -d .git ]; then # Repo exists: update it git fetch origin "$REF_NAME" git checkout "$REF_NAME" git reset --hard "origin/$REF_NAME" git clean -fd else # No repo: clone it git clone --depth 1 --filter=blob:none -b "$REF_NAME" "https://github.com/${REPO}" . git checkout "$REF_NAME" fi - name: "Run ${{ inputs.whattodo }}" 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 env: WHATTODO: ${{ inputs.whattodo }} id: check_changes run: | set -euo pipefail if git diff --quiet; then echo "has_changes=false" >> "$GITHUB_OUTPUT" echo "::notice::No changes detected after ${WHATTODO}" else echo "has_changes=true" >> "$GITHUB_OUTPUT" echo "::notice::Changes detected after ${WHATTODO} - PR will be created" fi - name: Build PR body env: WHATTODO: ${{ inputs.whattodo }} 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 }}]` `${{ inputs.whattodo }}` for `${{ inputs.board }}`" commit-message: "[${{ inputs.branch }}] ${{ inputs.whattodo }} 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