Fetch Profile Image and Update README #5
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: Fetch Profile Image and Update README | |
on: | |
schedule: | |
- cron: "*/30 * * * *" # Runs every 30 minutes | |
workflow_dispatch: | |
jobs: | |
update-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Download profile image | |
run: | | |
curl -o profileimage.png https://projecteuler.net/profile/pepperonii.png | |
- name: Get current time | |
id: timestamp | |
run: | | |
echo "CURRENT_TIME=$(date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV | |
- name: Update README with profile image and timestamp | |
run: | | |
if [ -f "profileimage.png" ]; then | |
# Update README with the profile image path | |
sed -i 's|https://projecteuler.net/profile/pepperonii.png|./profileimage.png|' README.md | |
# Replace or add a "Last updated" timestamp at the end of the README | |
if grep -q "Last updated: " README.md; then | |
sed -i "s|_Last updated: .*_|_Last updated: ${CURRENT_TIME}_|" README.md | |
else | |
echo "_Last updated: ${CURRENT_TIME}_" >> README.md | |
fi | |
fi | |
env: | |
CURRENT_TIME: ${{ env.CURRENT_TIME }} | |
- name: Commit updated README | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add README.md profileimage.png | |
git commit -m "gh actions fetched profile image" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |