Update README with Latest Files #26
This file contains hidden or 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: Update README with Latest Files | |
on: | |
push: | |
schedule: | |
- cron: "0 * * * *" # Runs every hour to update the README | |
jobs: | |
update-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Get Last 5 Modified Files | |
run: | | |
echo "## 📂 Last 5 Uploaded Files" > latest_files.md | |
echo "" >> latest_files.md | |
# Get last 5 recently committed files | |
git log --pretty=format:"%ad %h" --date=short --name-only --diff-filter=A,M | grep -vE '^$' | head -30 | awk '!seen[$0]++' | head -5 | while read -r filedate hash filename; do | |
if [[ -n "$filename" && -f "$filename" ]]; then | |
encoded_filename=$(echo "$filename" | sed 's/ /%20/g') # Encode spaces for GitHub URLs | |
echo "- [$filename](https://github.com/AKC23/Programming-problems-solutions/blob/master/$encoded_filename) (📅 $filedate)" >> latest_files.md | |
fi | |
done | |
cat latest_files.md # Debugging output | |
- name: Update README | |
run: | | |
sed -i '/## 📂 Last 5 Uploaded Files/,$d' README.md | |
cat latest_files.md >> README.md | |
- name: Commit Changes | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git add README.md | |
git commit -m "Updated README with latest files" || exit 0 | |
git push |