-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (60 loc) · 2.17 KB
/
Copy pathbuild_and_deploy.yml
File metadata and controls
69 lines (60 loc) · 2.17 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
name: Deploy Hugo to Self-hosted Runner
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
jobs:
build-and-deploy:
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Install Hugo
run: |
HUGO_VERSION=0.160.0 # Update if needed
wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
tar -xvzf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
sudo mv hugo /usr/local/bin/hugo
rm -f hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz # Cleanup tarball
hugo version
- name: Set Base URL
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "HUGO_BASEURL=https://kgi.services.base4nfdi.de/" >> $GITHUB_ENV
elif [ "${{ github.ref }}" == "refs/heads/dev" ]; then
echo "HUGO_BASEURL=https://wp.dev.kgi.services.base4nfdi.de/" >> $GITHUB_ENV
else
echo "Skipping deployment for unrecognized branch"
exit 0
fi
- name: Build Hugo site with correct baseURL
run: hugo --minify --baseURL "$HUGO_BASEURL"
- name: Determine target directory
id: deploy-path
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "TARGET_DIR=/var/www/kgi.services.base4nfdi.de" >> $GITHUB_ENV
elif [ "${{ github.ref }}" == "refs/heads/dev" ]; then
echo "TARGET_DIR=/var/www/wp.dev.kgi.services.base4nfdi.de" >> $GITHUB_ENV
else
echo "Skipping deployment for unrecognized branch"
exit 0
fi
- name: Deploy to target directory
if: github.event_name == 'push'
run: |
sudo rm -rf $TARGET_DIR/*
sudo cp -r public/* $TARGET_DIR/
sudo chown -R www-data:www-data $TARGET_DIR
sudo chmod -R 755 $TARGET_DIR
- name: Clean Up Workspace
if: always()
run: |
echo "Cleaning up workspace..."
rm -rf $GITHUB_WORKSPACE/*
echo "Cleanup complete."