-
Notifications
You must be signed in to change notification settings - Fork 1
125 lines (113 loc) · 4.71 KB
/
build.yml
File metadata and controls
125 lines (113 loc) · 4.71 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
name: Build
on:
push:
branches:
- main
#pull_request:
# branches:
# - main
env:
GO_VERSION: 1.24.3
MUFFET_VERSION: v2.11.0
PAGEFIND_VERSION: 1.3.0
jobs:
create-archive:
name: Create archive
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetches entire commit history for git lastmod
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build site
run: ./build.sh
- name: Generate caddy_redirects.conf
run: |
./generate-caddy-redirects.sh
sudo cp caddy_redirects.conf src/public/
- name: Validate Caddy config (local)
run: |
echo -e "https://seatable.com {\nimport /tmp/caddy_redirects.conf\n}" > Caddyfile
docker run --rm -v ./Caddyfile:/tmp/Caddyfile -v ./src/public/caddy_redirects.conf:/tmp/caddy_redirects.conf lucaslorentz/caddy-docker-proxy:2.9.1-alpine validate --config /tmp/Caddyfile
- name: Create tar.gz archive
run: tar -czvf archive.tar.gz public
working-directory: src
- name: Upload tar.gz artifact
uses: actions/upload-artifact@v4
with:
name: site
path: src/archive.tar.gz
check-links:
name: Check links
runs-on: ubuntu-22.04
steps:
- name: Determine if skip
id: check
run: |
SKIP=false
if [[ "${{ vars.SKIP_MUFFET }}" == "true" || "${{ github.ref_name }}" == "skip-muffet-branch" ]]; then
SKIP=true
fi
echo "skipped=$SKIP" >> $GITHUB_OUTPUT
echo "Skip check-links: $SKIP"
- name: Checkout repository
if: steps.check.outputs.skipped != 'true'
uses: actions/checkout@v4
- uses: actions/setup-go@v2
if: steps.check.outputs.skipped != 'true'
with:
go-version: ${{ env.GO_VERSION }}
- name: Start development server
if: steps.check.outputs.skipped != 'true'
run: docker compose up -d
- name: Add $GOPATH/bin to $PATH
if: steps.check.outputs.skipped != 'true'
run: |
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Install muffet
if: steps.check.outputs.skipped != 'true'
run: go install github.com/raviqqe/muffet/v2@${MUFFET_VERSION}
- name: 'Wait until the container is healthy'
if: steps.check.outputs.skipped != 'true'
uses: raschmitt/wait-for-healthy-container/@master
with:
container-name: hugo
timeout: 240
- name: Check links
if: steps.check.outputs.skipped != 'true'
run: muffet -t60 -c30 -f -i 'http://127*' -i 'http://localhost' -e '/js/script.js' -e '/api/event' -e 'http://127.0.0.1:1313/pagefind/pagefind-ui.css' -e 'http://127.0.0.1:1313/pagefind/pagefind-ui.js' http://127.0.0.1:1313
deploy:
name: Deploy
needs:
- create-archive
- check-links
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: site
- name: Extract archive
run: tar xf archive.tar.gz
- name: Add SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: placeholder
- name: Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy with rsync
# There's no target path after the last colon since rrsync is used on the server
run: 'rsync -avz --delete . ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:'
working-directory: public
- name: Validate Caddy config (remote)
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} validate-caddy-config
- name: Reload Caddy config
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} reload-caddy-config