-
Notifications
You must be signed in to change notification settings - Fork 8
81 lines (67 loc) · 2.03 KB
/
deploy.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: deploy-static-pages
on:
workflow_dispatch:
push:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout source Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Install Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
- name: Build Hugo Site
run: |
hugo --minify
if [ ! -d "public" ] || [ -z "$(ls -A public)" ]; then
echo "Error: Hugo did not generate any files."
exit 1
fi
- name: Get Commit Message
id: commit_message
run: |
COMMIT_MSG=$(jq -r '.commits[-1].message' "$GITHUB_EVENT_PATH" | sed ':a;N;$!ba;s/\n/ /g')
echo "commit_message<<EOF" >> $GITHUB_ENV
echo "$COMMIT_MSG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Backup Generated Files and Copy Other Relevant Files
run: |
mkdir -p $HOME/temp
cp -r public/* $HOME/temp/
cp README.md $HOME/temp/
cp lychee.toml $HOME/temp/
- name: List Files
run: |
echo "Listing files in backup directory:"
ls -l $HOME/temp/
- name: Deploy to main Branch
env:
ACTIONS_DEPLOY_TOKEN: ${{ secrets.ACTIONS_DEPLOY_TOKEN }}
COMMIT_MESSAGE: ${{ env.commit_message }}
run: |
# Switch to main branch
git checkout main
# Clean up branch
git clean -df
# Restore files from backup
rsync -av $HOME/temp/* . --exclude=$HOME/temp/.git
rm -rf $HOME/temp
# Configure Git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Commit and push changes
git add .
git commit -m "Deploying: $COMMIT_MESSAGE"
git push origin main
- name: Lychee Link Checker
uses: lycheeverse/lychee-action@v1
with:
args: -c lychee.toml -n .