Create main.yml #1
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 | |
git log --name-only --pretty=format:"%ad - %h" --date=short | grep -v '^$' | head -10 | awk '!seen[$0]++' | head -5 | while read -r line; do | |
filename=$(echo $line | awk '{print $3}') | |
filedate=$(echo $line | awk '{print $1}') | |
if [[ -n "$filename" ]]; then | |
echo "- [$filename](https://github.com/AKC23/Programming-problems-solutions/blob/master/$filename) (📅 $filedate)" >> latest_files.md | |
fi | |
done | |
- 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 |