chore: update frontmatter date (auto-update) #1654
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: Update Frontmatter | |
on: | |
push: | |
branches: | |
- 'main' | |
paths: | |
- 'content/docs/**/*.md' | |
- '!content/docs/README.md' # Exclude the README.md file | |
- '!content/docs/shared-content/**/*.md' # Exclude the shared-content folder | |
jobs: | |
update-date: | |
runs-on: ubuntu-latest | |
if: ${{ !contains(github.event.head_commit.message, 'auto-update') }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 2 | |
token: ${{ secrets.ACCESS_TOKEN }} | |
# ACCESS_TOKEN is a personal access token with repo scope | |
# it needs to be updated in the repo secrets when it expires - Nov 10, 2024 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 18 | |
- name: Get list of modified files | |
id: get-modified-files | |
run: | | |
modified_files=$(git diff --name-only HEAD^ HEAD | grep '^content/docs/.*\.md$' | xargs) | |
echo "Modified files: $modified_files" | |
if [ -z "$modified_files" ]; then | |
echo "No modified Markdown files to update." | |
exit 0 | |
fi | |
echo "modified_files=$modified_files" >> $GITHUB_OUTPUT | |
- name: Install packages | |
run: npm ci | |
- name: Run update script | |
run: node src/scripts/update-frontmatter.js ${{ steps.get-modified-files.outputs.modified_files }} | |
- name: Commit changes | |
run: | | |
git config user.name "GitHub Action" | |
git config user.email "[email protected]" | |
export HUSKY=0 | |
git add -A | |
# Check for meaningful changes before committing | |
if [ -n "$(git status --porcelain)" ]; then | |
# Commit only modified markdown files, not all changes | |
git commit -m "chore: update frontmatter date (auto-update)" ${{ steps.get-modified-files.outputs.modified_files }} | |
echo "Changes committed" | |
else | |
echo "No significant changes to commit" | |
exit 0 | |
fi | |
- name: Pull latest changes | |
run: git pull --rebase | |
- name: Push changes | |
run: git push origin HEAD:main | |
env: | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} |