Skip to content

Commit

Permalink
🐎 ci: TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
Seeridia authored Jun 18, 2023
1 parent 40240f7 commit 5b8a1e4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
31 changes: 31 additions & 0 deletions .github/scripts/update-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function getChangedFiles() {
const { stdout } = await exec('git log --name-only --pretty=format: --max-count=3');
const files = stdout.split('\n');
const uniqueFiles = [...new Set(files)].filter(file => file.trim() !== '');
return uniqueFiles;
}

function updateReadme(files) {
const readmeContent = fs.readFileSync('./README.md', 'utf8');
const startIndex = readmeContent.indexOf('<!-- readme: recent-changes -start -->') + '<!-- readme: recent-changes -start -->'.length;
const endIndex = readmeContent.indexOf('<!-- readme: recent-changes -end -->');

let newContent = readmeContent.substring(0, startIndex) + '\n';
files.forEach((file, index) => {
newContent += `${index+1}. ${file}\n`;
});
newContent += readmeContent.substring(endIndex);

fs.writeFileSync('./README.md', newContent);
}

getChangedFiles()
.then(files => updateReadme(files))
.catch(error => {
console.error(error);
process.exit(1);
});
44 changes: 12 additions & 32 deletions .github/workflows/recent-changes.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
name: Recent changes
name: Update README

on:
push:
branches:
- main
- main # Or replace with your default branch

jobs:
update_readme:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Update README with recent changes
run: |
# Fetch the latest 3 commits
recent_changes=$(git log -3 --pretty=format:"%h %s" --name-only)
# Extract changed filenames from the recent_changes
changed_files=$(echo "$recent_changes" | grep -P '^(?=\S)(?!\d+\s)' | uniq)
# Format the changed files with numbering
formatted_changes=""
counter=1
while read -r line; do
formatted_changes+="$counter. $line\n"
counter=$((counter+1))
done <<< "$changed_files"
# Update the README.md file
sed -i '/<!-- readme: recent-changes -start -->/,/<!-- readme: recent-changes -end -->/c\<!-- readme: recent-changes -start -->\n'"$formatted_changes"'<!-- readme: recent-changes -end -->' README.md
- name: Commit and push changes
- uses: actions/checkout@v2
- name: Run update script
run: node .github/scripts/update-readme.js
- name: Commit and push if changed
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Update README with recent changes" || echo "No changes to commit"
git push
git diff
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git commit -am "Update README" -a || echo "No changes to commit"
git push

0 comments on commit 5b8a1e4

Please sign in to comment.