-
Notifications
You must be signed in to change notification settings - Fork 1
139 lines (113 loc) · 4.88 KB
/
pg-award-proposal-sync.yml
File metadata and controls
139 lines (113 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: PG Award Proposal - Sync PR Body
on:
pull_request:
types: [opened, synchronize]
paths:
- "docs/projects/**.md"
permissions:
contents: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Automatic Rebase and Linearize
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REBASE_MSG: |
:robot: **Automated Housekeeping:** I detected merge commits in this branch. To keep our history linear, I have automatically rebased your changes onto `main`.
:warning: **Note for CLI users:** If you are working locally, please run `git pull --rebase` before your next push to sync your local history.
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
MERGES=$(git rev-list --merges origin/main..HEAD)
if [ -n "$MERGES" ]; then
echo "Merge commits detected. Converting to rebase..."
# Pipe the env var directly to gh to avoid shell escaping issues
echo "$REBASE_MSG" | gh pr comment "$PR_NUMBER" --body-file -
git fetch origin main
git rebase origin/main
git push origin HEAD:${{ github.head_ref }} --force-with-lease
else
echo "History is already linear."
fi
- name: Find changed files
id: files
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ALL_CHANGED=$(gh pr diff ${{ github.event.pull_request.number }} \
-R ${{ github.repository }} \
--name-only)
PROJECT_FILES=$(echo "$ALL_CHANGED" \
| grep '^docs/projects/.*\.md$' \
| grep -v '/index\.md$' \
|| true)
OTHER_FILES=$(echo "$ALL_CHANGED" \
| grep -v '^docs/projects/' \
|| true)
PROJECT_COUNT=$(echo "$PROJECT_FILES" | grep -c . || true)
OTHER_COUNT=$(echo "$OTHER_FILES" | grep -c . || true)
echo "project_count=${PROJECT_COUNT}" >> "$GITHUB_OUTPUT"
echo "other_count=${OTHER_COUNT}" >> "$GITHUB_OUTPUT"
if [[ "$PROJECT_COUNT" -eq 1 ]]; then
echo "path=${PROJECT_FILES}" >> "$GITHUB_OUTPUT"
fi
- name: Skip if no project files changed
if: steps.files.outputs.project_count == '0'
run: echo "::notice::No project page changes detected — skipping sync."
- name: Fail if non-project files changed
if: steps.files.outputs.other_count != '0' && steps.files.outputs.project_count != '0'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }} \
-R ${{ github.repository }} \
--body ":warning: This PR modifies files outside \`docs/projects/\`. Proposal PRs should only contain changes to your project page."
exit 1
- name: Fail if multiple project files changed
if: steps.files.outputs.project_count > 1
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }} \
-R ${{ github.repository }} \
--body ":warning: This PR modifies multiple project pages. Please only modify one project page per PR so the proposal can be synced correctly."
exit 1
- name: Strip front matter and sync PR body
if: steps.files.outputs.project_count == '1' && steps.files.outputs.other_count == '0'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
FILE="${{ steps.files.outputs.path }}"
MAX_CHARS=64000
# Strip YAML front matter (first --- to second --- inclusive)
BODY=$(sed '1{/^---$/!q}; 1,/^---$/d' "$FILE")
BODY_LEN=${#BODY}
TRUNCATED="false"
if [[ "$BODY_LEN" -gt "$MAX_CHARS" ]]; then
BODY="${BODY:0:$MAX_CHARS}"
BODY+=$'\n\n---\n:warning: This preview has been truncated due to length. View the full proposal in the [Files changed](../pull/'"$PR_NUMBER"'/files) tab.'
TRUNCATED="true"
fi
echo "$BODY" | gh pr edit "$PR_NUMBER" \
-R ${{ github.repository }} \
--body-file -
# Step summary
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
## Proposal Sync
| | |
| --- | --- |
| **PR** | #${PR_NUMBER} |
| **File** | \`${FILE}\` |
| **Content length** | ${BODY_LEN} chars |
| **Truncated** | ${TRUNCATED} |
EOF