feat: automate readme table #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check for new presentations | |
on: | |
pull_request: | |
paths: | |
- 'presentations/**' | |
jobs: | |
check-new-folder: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up environment | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
- name: Get the list of changed folders | |
id: diff | |
run: | | |
# Get only the added folders in presentations directory | |
diff_folders=$(git diff --name-status origin/main | grep '^A' | grep 'presentations/' | awk '{print $2}' | cut -d'/' -f2 | sort -u) | |
echo "Folders detected: $diff_folders" | |
echo "::set-output name=folders::$diff_folders" | |
- name: Check new folders against table | |
run: | | |
# Path to your markdown table | |
MD_FILE="scripts/table.md" | |
# Get the date of the top row in the table | |
top_row_date=$(grep -oP '^\|[0-9]{4}-[0-9]{2}-[0-9]{2}' $MD_FILE | head -n 1 | tr -d '|') | |
# Loop through the folders detected | |
for folder in ${{ steps.diff.outputs.folders }}; do | |
folder_date=$(echo $folder | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}') | |
echo "Comparing folder date: $folder_date with top row date: $top_row_date" | |
if [[ "$folder_date" > "$top_row_date" ]]; then | |
echo "New folder $folder is newer than the latest entry in the table ($top_row_date)." | |
exit 1 | |
else | |
echo "Table is up to date." | |
fi | |
done | |
- name: Success message | |
if: success() | |
run: echo "Table is up to date." | |
- name: Fail message | |
if: failure() | |
run: echo "Please run the generation command to update the table." |