Skip to content

Commit

Permalink
Initial template draft
Browse files Browse the repository at this point in the history
  • Loading branch information
asiermartinez committed Sep 22, 2024
0 parents commit dc3f439
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/scripts/update_toc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Check if README.md contains "## RFDs"
if grep -q '## RFDs' README.md; then
# Extract everything before the "Requests for Discussion" section
head -n $(grep -n '## RFDs' README.md | cut -d: -f1) README.md > temp_README.md
else
# Copy the full README.md if no Requests for Discussion section exists
cat README.md > temp_README.md
echo "## RFDs" >> temp_README.md
fi

# Generate the table header
echo "| RFD | State | Updated | Labels |" >> temp_README.md
echo "|:----|:------|:--------|:-------|" >> temp_README.md

# Initialize an array to store the ordered table rows
rows=()

# Loop through files matching the NNNN.md pattern
for file in [0-9][0-9][0-9][0-9].md; do
# Extract the RFD number from the filename
rfd_number=$((10#$(basename "$file" .md)))

# Extract the state from the front matter
state=$(grep '^state:' "$file" | cut -d ' ' -f2-)

# Extract the title from the first heading of the file
title=$(grep -m 1 '^#' "$file" | sed 's/# RFD [0-9]\{1,4\} *//')

# Get the last updated timestamp of the file and transform it to the YYYY-MM-DD, HH:MM format
updated=$(git log -1 --format="%cI" -- "$file" | sed -E 's/T([0-9]{2}:[0-9]{2}):[0-9]{2}.*/, \1/')

# Extract the labels from the front matter
labels=$(grep '^labels:' "$file" | sed -E 's/labels: *//; s/ *, */, /g; s/([^, ]+)/`\1`/g')

# Add the row to the table
rows+=("| [RFD $rfd_number $title]($file) | $state | $updated | $labels |")
done

# Sort the rows array by the Updated column in descending order (newest first)
sorted_rows=$(printf "%s\n" "${rows[@]}" | sort -t '|' -k 4,4r)

# Add the sorted rows to the table
printf "%s\n" "$sorted_rows" >> temp_README.md

# Replace the original README.md with the updated one
mv temp_README.md README.md
31 changes: 31 additions & 0 deletions .github/workflows/update_toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Update RFD Table of Contents

on:
push:
branches:
- main

jobs:
generate-summary:
runs-on: ubuntu-latest

steps:
# Step 1: Check out the repository
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0

# Step 2: Run the Bash script to update the README.md with the RFD Table of Contents
- name: Update RFD Table of Contents
run: ./.github/scripts/update_toc.sh

# Step 3: Commit and push the updated README.md if changes are made
- name: Commit and push changes
run: |
git config --local user.name "github-actions"
git config --local user.email "[email protected]"
git add README.md
git commit -m "Update RFD Table of Contents"
git push
if: success()
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Requests for Discussion

## RFDs
Empty file added assets/README.md
Empty file.
48 changes: 48 additions & 0 deletions new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Fetch all remote branches following the pattern 'rfd/XXXX' and get the latest number
git fetch origin
latest_branch=$(git branch -r | grep -E 'origin/rfd/[0-9]{4}' | sed 's|origin/rfd/||' | sort -n | tail -1)

# Increment RFD number by one
if [ -z "$latest_branch" ]; then
next_number=0001 # If no branch exists, start from 0001
else
next_number=$(printf "%04d" $(( $(echo "$latest_branch" | sed 's/^0*//') + 1 )))
fi

# Prompt for the placeholder title of the RFD
echo "Enter the title for this RFD:"
read rfd_title

# Reserve the branch name for the new RFD
new_branch="rfd/$next_number"
git checkout -b "$new_branch"

# Generate a new RFD file from the template
new_file="${next_number}.md"
cp XXXX.md "$new_file"

# Update the new file by replacing <number> and <title> placeholders
sed -i "" "s/<number>/$((10#$next_number))/g" "$new_file"
sed -i "" "s/<title>/${rfd_title}/g" "$new_file"

# Get the current git user's name and email
author_name=$(git config user.name)
author_email=$(git config user.email)
author="${author_name} <${author_email}>"

# Append the author information to the existing 'authors' field in the front matter
sed -i "" "/^authors:/ s/$/ $author/" "$new_file"

# Git add the new file
git add "$new_file"

# Commit following the convention: 0000: Add placeholder for RFD <Title>
commit_message="$next_number: Adding placeholder for RFD $rfd_title"
git commit -m "$commit_message"

# Push the new branch to remote
git push origin "$new_branch"

echo "Branch $new_branch created and pushed with file $new_file."
7 changes: 7 additions & 0 deletions xxxx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
authors:
state: draft
labels:
---

# RFD <number> <title>

0 comments on commit dc3f439

Please sign in to comment.