-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (71 loc) · 2.95 KB
/
update-hugo.yml
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
name: Update Hugo version
on:
schedule:
- cron: "0 0 * * 1" # Runs every Monday at midnight
workflow_dispatch:
jobs:
check-and-update-hugo:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Otherwise, the token used is the GITHUB_TOKEN, instead of your personal
# access token
persist-credentials: false
# Otherwise, there would be errors pushing refs to the destination repository
fetch-depth: 0
- name: Get current Hugo version
id: get_current_hugo_version
run: |
current_version=$(grep 'HUGO_VERSION:' .github/workflows/ci.yml | awk '{print $2}')
echo "Current Hugo version is ${current_version}"
echo "CURRENT_HUGO_VERSION=${current_version}" >> "${GITHUB_ENV}"
- name: Fetch latest Hugo version
id: fetch_latest_hugo_version
run: |
latest_version=$(curl --silent "https://api.github.com/repos/gohugoio/hugo/releases/latest" \
| jq -r .tag_name | sed 's/v//')
echo "Latest Hugo version is ${latest_version}"
echo "LATEST_HUGO_VERSION=${latest_version}" >> "${GITHUB_ENV}"
- name: Check if update is needed
id: check_update
run: |
if [[ "${LATEST_HUGO_VERSION}" == "${CURRENT_HUGO_VERSION}" ]]; then
echo "Hugo is up to date. No update needed."
echo "hugo_update_needed=false" >> "${GITHUB_ENV}"
exit 0
else
echo "Hugo needs updating from ${CURRENT_HUGO_VERSION} to ${LATEST_HUGO_VERSION}."
echo "hugo_update_needed=true" >> "${GITHUB_ENV}"
fi
- name: Update Hugo version in ci.yml
if: env.hugo_update_needed == 'true'
run: |
sed -i "s/HUGO_VERSION: ${CURRENT_HUGO_VERSION}/HUGO_VERSION: ${LATEST_HUGO_VERSION}/g" \
.github/workflows/ci.yml
- name: Install updated Hugo version
if: env.hugo_update_needed == 'true'
run: |
wget -O hugo.deb \
"https://github.com/gohugoio/hugo/releases/download/v${{ env.LATEST_HUGO_VERSION }}/hugo_${{ env.LATEST_HUGO_VERSION }}_linux-amd64.deb"
sudo dpkg -i hugo.deb
- name: Build site with updated Hugo
if: env.hugo_update_needed == 'true'
run: |
git submodule update --init --recursive
npm ci || true
hugo --gc --minify
continue-on-error: false
- name: Commit version update
if: success() && env.hugo_update_needed == 'true'
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git commit -am "Update Hugo version to ${LATEST_HUGO_VERSION}"
- name: Push changes
if: success() && env.hugo_update_needed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT_TOKEN }}
branch: ${{ github.ref }}