forked from cotes2020/jekyll-theme-chirpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Update Last Modified Date and Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- blog | ||
workflow_dispatch: | ||
|
||
jobs: | ||
updateLastModified: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.3' | ||
|
||
- name: Install dependencies | ||
run: bundle install | ||
|
||
- name: Update last_modified_at field | ||
run: | | ||
posts_dir="_posts" | ||
for post_path in $(find "$posts_dir" -name "*.md"); do | ||
commit_count=$(git rev-list --count HEAD "$post_path") | ||
last_modified=$(git log -1 --pretty="%ad" --date=format:'%Y-%m-%d %H:%M %z' "$post_path" | xargs) | ||
content=$(cat "$post_path") | ||
if [[ "$content" =~ ^date:\ (.+) ]]; then | ||
if [[ "$content" =~ ^last_modified_at: ]]; then | ||
sed -i "s/^last_modified_at:.*/last_modified_at: $last_modified/" "$post_path" | ||
elif [[ $commit_count -gt 1 ]]; then | ||
sed -i "/^date: /a last_modified_at: $last_modified" "$post_path" | ||
fi | ||
fi | ||
done | ||
- name: Commit changes | ||
run: | | ||
git config --global user.name "GitHub Action" | ||
git config --global user.email "action@github.com" | ||
git add _posts/*.md | ||
git commit -m "Update last_modified_at field in posts" || echo "No changes to commit" | ||
deployToCloudflare: | ||
runs-on: ubuntu-latest | ||
needs: updateLastModified # Ensure this runs after the updateLastModified job | ||
|
||
steps: | ||
- name: Push changes | ||
run: git push origin blog | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Deploy to Cloudflare Pages | ||
uses: cloudflare/wrangler-action@2 | ||
with: | ||
apiToken: ${{ secrets.CF_API_TOKEN }} | ||
accountId: ${{ secrets.CF_ACCOUNT_ID }} | ||
projectName: "stevehoang" | ||
directory: "_site" |
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
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