Skip to content

PG Award Proposal: Hyperledger Solang #64

PG Award Proposal: Hyperledger Solang

PG Award Proposal: Hyperledger Solang #64

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