Browse Source

feat(commit-status): add workflow for generating commit status report

TheWildJames 3 months ago
parent
commit
76f3b31dd3
2 changed files with 128 additions and 1 deletions
  1. 25 1
      .github/actions/download-kernel/action.yml
  2. 103 0
      .github/workflows/commit-status.yml

+ 25 - 1
.github/actions/download-kernel/action.yml

@@ -122,4 +122,28 @@ runs:
       if: ${{ inputs.use_repo != 'true' }}
       working-directory: ${{ github.workspace }}/kernel
       run: |
-        python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"
+        python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"
+
+    - name: Capture Kernel Common Commit Metadata
+      shell: bash
+      working-directory: ${{ github.workspace }}/kernel
+      run: |
+        set -euo pipefail
+
+        if [[ ! -d common ]]; then
+          echo "WARNING: common folder not found; skipping commit metadata capture."
+          exit 0
+        fi
+
+        cd common
+
+        if [[ ! -d .git ]]; then
+          echo "WARNING: common is not a git checkout; skipping commit metadata capture."
+          exit 0
+        fi
+
+        COMMIT_DATE=$(git log -1 --format=%cI)
+        COMMIT_MSG=$(git log -1 --format=%s)
+
+        echo "Kernel common commit date: $COMMIT_DATE"
+        echo "Kernel common commit msg: $COMMIT_MSG"

+ 103 - 0
.github/workflows/commit-status.yml

@@ -0,0 +1,103 @@
+name: Commit Status Report
+
+on:
+  workflow_dispatch:
+
+jobs:
+  report:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v5
+
+      - name: Build commit summary
+        shell: bash
+        env:
+          COMMITS_JSON: .github/config/commits.json
+        run: |
+          set -euo pipefail
+
+          summary_file="$GITHUB_STEP_SUMMARY"
+
+          sanitize_cell() {
+            local value="$1"
+            value="${value//$'\r'/ }"
+            value="${value//$'\n'/ }"
+            value="${value//|/\\|}"
+            printf '%s' "$value"
+          }
+
+          gitlab_commit_message() {
+            local sha="$1"
+            curl -fsSL "https://gitlab.com/api/v4/projects/simonpunk%2Fsusfs4ksu/repository/commits/${sha}" | jq -r '.message | split("\n")[0]'
+          }
+
+          gitlab_latest_commit() {
+            local branch="$1"
+            curl -fsSL "https://gitlab.com/api/v4/projects/simonpunk%2Fsusfs4ksu/repository/commits?ref_name=${branch}&per_page=1" | jq -r '.[0].id'
+          }
+
+          gitlab_latest_message() {
+            local branch="$1"
+            curl -fsSL "https://gitlab.com/api/v4/projects/simonpunk%2Fsusfs4ksu/repository/commits?ref_name=${branch}&per_page=1" | jq -r '.[0].message | split("\n")[0]'
+          }
+
+          github_commit_message() {
+            local sha="$1"
+            curl -fsSL "https://api.github.com/repos/KernelSU-Next/KernelSU-Next/commits/${sha}" | jq -r '.commit.message | split("\n")[0]'
+          }
+
+          github_latest_commit() {
+            curl -fsSL "https://api.github.com/repos/KernelSU-Next/KernelSU-Next/commits/dev" | jq -r '.sha'
+          }
+
+          github_latest_message() {
+            curl -fsSL "https://api.github.com/repos/KernelSU-Next/KernelSU-Next/commits/dev" | jq -r '.commit.message | split("\n")[0]'
+          }
+
+          {
+            echo "# Commit Status Report"
+            echo ""
+            echo "This report shows the pinned commit from this repository and the latest upstream commit for each supported SUSFS branch plus KernelSU-Next."
+            echo ""
+          } >> "$summary_file"
+
+          {
+            echo "## SUSFS"
+            echo ""
+            echo "| Branch | Current Commit | Current Message | Latest Commit | Latest Message |"
+            echo "| --- | --- | --- | --- | --- |"
+          } >> "$summary_file"
+
+          while IFS= read -r branch; do
+            current_commit="$(jq -r --arg key "$branch" '.susfs[$key]' "$COMMITS_JSON")"
+            latest_commit="$(gitlab_latest_commit "$branch")"
+            current_message="$(gitlab_commit_message "$current_commit")"
+            latest_message="$(gitlab_latest_message "$branch")"
+
+            current_message="$(sanitize_cell "$current_message")"
+            latest_message="$(sanitize_cell "$latest_message")"
+
+            printf '| %s | %s | %s | %s | %s |\n' "$branch" "$current_commit" "$current_message" "$latest_commit" "$latest_message" >> "$summary_file"
+          done < <(jq -r '.susfs | keys[]' "$COMMITS_JSON" | sort)
+
+          {
+            echo ""
+            echo "## KernelSU-Next"
+            echo ""
+            echo "| Branch | Current Commit | Current Message | Latest Commit | Latest Message |"
+            echo "| --- | --- | --- | --- | --- |"
+          } >> "$summary_file"
+
+          current_kernelsu_commit="$(jq -r '.kernelsu.dev' "$COMMITS_JSON")"
+          latest_kernelsu_commit="$(github_latest_commit)"
+          current_kernelsu_message="$(github_commit_message "$current_kernelsu_commit")"
+          latest_kernelsu_message="$(github_latest_message)"
+
+          current_kernelsu_message="$(sanitize_cell "$current_kernelsu_message")"
+          latest_kernelsu_message="$(sanitize_cell "$latest_kernelsu_message")"
+
+          printf '| %s | %s | %s | %s | %s |\n' "dev" "$current_kernelsu_commit" "$current_kernelsu_message" "$latest_kernelsu_commit" "$latest_kernelsu_message" >> "$summary_file"