Skip to content

Commit

Permalink
Fix cd
Browse files Browse the repository at this point in the history
  • Loading branch information
letelete committed Dec 8, 2024
1 parent 8d585c6 commit f42ed03
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
17 changes: 14 additions & 3 deletions .github/scripts/update-year-readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ aoc_year="$1"
day_path="../../$aoc_year"
readme_file="README.md"

echo "Running ./update-year-readme.sh"
echo "aoc_year: $aoc_year"
echo "day_path: $day_path"
echo "readme_file: $readme_file"

table=""
if [ -x "./parse-year.sh" ]; then
echo "Running ./parse-year.sh"
table=$(./parse-year.sh $aoc_year)

if [ -z "$table" ]; then
printf "parse-year returned empty table"
echo "parse-year returned empty table"
exit 1
else
echo "Success"
echo -e "$table"
fi
else
printf "parse-year.sh not found or not executable"
echo "parse-year.sh not found or not executable"
exit 1
fi

output+="$table"$'\n\n'
output+="> Autogenerated using [Custom GitHub Action Workflow](../.github/workflows/update-year-readme.sh)."$'\n'
output+="> Made by [Bruno Kawka](https://kawka.me)."$'\n'

echo "Reading file: $day_path/$readme_file"
if [[ ! -f "$day_path/$readme_file" ]]; then
echo "Error: $readme_file does not exist."
exit 1
Expand All @@ -32,10 +42,11 @@ before_stats=$(echo "$file_content" | awk '/^## Stats$/ {exit} {print}')
stats_section=$(echo "$file_content" | awk '/^## Stats$/,/^#/{if (!/^#/) print}')
after_stats=$(echo "$file_content" | awk '/^## Stats$/ {getline; while (!/^#/) getline; print; while (getline) print}')

# Construct the new content
new_content="${before_stats}\n
## Stats\n
${output}
${after_stats}"

echo "Printing new content to the $day_path/$readme_file file"
echo -e "$new_content"
echo -e "$new_content" >"$day_path/$readme_file"
18 changes: 16 additions & 2 deletions .github/workflows/update-year-readme.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Update README.md file
name: Update README.md for the current year's module

run-name: Update README for Year $(github.event.head_commit.timestamp + '%Y')
permissions:
contents: write

on:
push:
Expand All @@ -21,3 +22,16 @@ jobs:
run: ./update-year-readme.sh $(date +'%Y')
working-directory: .github/scripts
shell: bash

- name: Commit README.md
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add ../../
git commit -m "Update README.md file with recent statistics"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force_with_lease: true
branch: ${{ github.head_ref }}
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit f42ed03

Please sign in to comment.