-
Notifications
You must be signed in to change notification settings - Fork 1
98 lines (82 loc) · 2.75 KB
/
deploy-docs.yml
File metadata and controls
98 lines (82 loc) · 2.75 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
name: Deploy NetLogo Documentation
on:
push:
branches:
- main
workflow_dispatch:
inputs:
deploy_target:
description: "Deployment target"
required: false
default: "prebuild"
type: choice
options:
- "gh-pages/live-site"
- staging
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
pages: write
id-token: write
steps:
- name: Checkout Source Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Environment Variables
id: setup_vars
run: echo "DIST_DIR=dist" >> $GITHUB_ENV
- name: Build Distribution Files
run: |
mkdir -p ${{ env.DIST_DIR }}
EXCLUDE=("latest" "${{ env.DIST_DIR }}" "$(basename "$0")" ".git" ".github" ".gitignore" "README.md")
for item in *; do
if [[ ! " ${EXCLUDE[@]} " =~ " $item " ]]; then
cp -R "$item" "${{ env.DIST_DIR }}/"
fi
done
if [ -L "latest" ]; then
LATEST_TARGET=$(readlink latest)
if [ -d "$LATEST_TARGET" ]; then
cp -R "$LATEST_TARGET"/* "${{ env.DIST_DIR }}/"
else
echo "::error::'latest' symlink target '$LATEST_TARGET' does not exist."
exit 1
fi
elif [ -d "latest" ]; then
cp -R "latest"/* "${{ env.DIST_DIR }}/"
else
echo "::warning::'latest' directory or symlink not found."
fi
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Checkout Target Branch
uses: actions/checkout@v4
with:
ref: "gh-pages/live-site"
path: prebuild-branch
- name: Deploy to gh-pages/live-site Branch
id: deploy
run: |
cd prebuild-branch
# Efficiently remove old files and copy new ones
git rm -rf . && git clean -fxd
cp -R ../${{ env.DIST_DIR }}/* .
touch .nojekyll
git add -A
if git diff --staged --quiet; then
echo "No changes to deploy."
echo "status=no-changes" >> $GITHUB_OUTPUT
else
echo "Changes detected, committing and pushing."
git commit -m "docs: Deploy documentation from main branch
Source commit: ${{ github.sha }}
Branch: ${{ github.ref_name }}
Distribution size: $(du -sh ../${{ env.DIST_DIR }} | cut -f1)"
git push origin gh-pages/live-site
echo "status=deployed" >> $GITHUB_OUTPUT
fi