-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (155 loc) · 5.64 KB
/
Copy pathhugo.yml
File metadata and controls
174 lines (155 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Sample workflow for building and deploying a Hugo site to GitHub Pages
name: Deploy Hugo site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Run daily at 10 AM UTC for bookmark updates and scheduled post publishing
schedule:
- cron: '0 10 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Default to bash
defaults:
run:
shell: bash
jobs:
# Update bookmarks job
update-bookmarks:
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.check-changes.outputs.changes }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests python-dotenv
- name: Run bookmarks.py
env:
LINKDING_API_KEY: ${{ secrets.LINKDING_API_KEY }}
LINKDING_API_ENDPOINT: ${{ secrets.LINKDING_API_ENDPOINT }}
P_ACCESS_TOKEN_ID: ${{ secrets.P_ACCESS_TOKEN_ID }}
P_ACCESS_TOKEN: ${{ secrets.P_ACCESS_TOKEN }}
run: |
python bookmarks.py
- name: Check for changes
id: check-changes
run: |
git add ./content/bookmarks
if git diff --cached --quiet; then
echo "changes=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "changes=true" >> $GITHUB_OUTPUT
echo "Changes detected"
fi
- name: Commit and push changes
if: steps.check-changes.outputs.changes == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "updated bookmarks"
git push
# Check for scheduled posts ready to publish
check-scheduled-posts:
runs-on: ubuntu-latest
outputs:
has_posts: ${{ steps.check-posts.outputs.has_posts }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check for posts ready to publish
id: check-posts
run: |
NOW=$(date -u +%s)
HAS_POSTS=false
# Find all blog posts and collect their dates first (avoids broken pipe)
DATE_LINES=$(find content/blog -name "index.md" -exec grep -H "^date:" {} \; 2>/dev/null || true)
# Check each date line
while IFS= read -r line; do
if [ -z "$line" ]; then
continue
fi
POST_DATE=$(echo "$line" | awk -F'date: "' '{if (NF>1) print $2}' | tr -d '"')
if [ -n "$POST_DATE" ]; then
POST_TIME=$(date -d "$POST_DATE" +%s 2>/dev/null || echo "0")
if [ "$POST_TIME" -gt 0 ] && [ "$POST_TIME" -le "$NOW" ]; then
HAS_POSTS=true
break
fi
fi
done <<< "$DATE_LINES"
echo "has_posts=$HAS_POSTS" >> $GITHUB_OUTPUT
if [ "$HAS_POSTS" = "true" ]; then
echo "Scheduled posts ready to publish"
else
echo "No scheduled posts ready to publish"
fi
# Build job
build:
runs-on: ubuntu-latest
needs: [update-bookmarks, check-scheduled-posts]
if: needs.update-bookmarks.outputs.changes == 'true' || needs.check-scheduled-posts.outputs.has_posts == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
env:
HUGO_VERSION: 0.128.0
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Dart Sass
run: sudo snap install dart-sass
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
ref: main
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Install Node.js dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
- name: Build with Hugo
env:
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
HUGO_ENVIRONMENT: production
run: |
hugo mod get -u
hugo \
--minify \
--baseURL "${{ steps.pages.outputs.base_url }}/"
- name: List build output
run: ls -l ./public
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
name: github-pages
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: [update-bookmarks, check-scheduled-posts, build]
if: needs.update-bookmarks.outputs.changes == 'true' || needs.check-scheduled-posts.outputs.has_posts == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4