-
Notifications
You must be signed in to change notification settings - Fork 82
144 lines (123 loc) · 5.12 KB
/
deploy-workshop.yml
File metadata and controls
144 lines (123 loc) · 5.12 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Deploy Workshop to GitHub Pages
permissions: write-all
on:
workflow_dispatch:
inputs:
release_type:
description: 'Type of version bump'
required: true
type: choice
options:
- minor
- major
default: minor
jobs:
deploy:
name: Build and deploy workshop
runs-on: ubuntu-24.04
steps:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.145.0'
extended: true
- name: Setup yq
uses: chrisdickinson/setup-yq@latest
with:
yq-version: '4.45.1'
yq-url: 'https://github.com/mikefarah/yq/releases/download/v{version}/yq_{platform}_{arch}'
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Cache go dependencies
uses: actions/cache@v4
with:
path: /tmp/hugo_cache
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugomod-
- name: Bump version and create tag
id: bumpversion
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git pull --rebase
TAG=$(bumpversion --list "${{ inputs.release_type }}" | awk -F= '/new_version=/ { print $2 }')
echo "tag_name=${TAG}" >> $GITHUB_OUTPUT
BASE_URL="$(yq .baseURL hugo.yaml)"
echo "base_url=${BASE_URL}" >> $GITHUB_OUTPUT
# Update README with new release link
awk "/Latest versions of the workshop are:/ { print; print \"- [v${TAG}](https://splunk.github.io/observability-workshop/)\";next }1" README.md |
awk "NR==1,/Latest versions of the workshop are:/{c=3} c&&c-- " > README.new.md
mv README.new.md README.md
git fetch --tags origin
git add README.md
git commit --amend -m "Releasing v${TAG}"
git tag -a "v${TAG}" -m "Version ${TAG}"
git push --follow-tags origin main || { echo 'Push failed. git pull --rebase from upstream and attempt another release.'; exit 1; }
- name: Build Hugo site
run: |
hugo --minify --destination "public" --baseURL "${{ steps.bumpversion.outputs.base_url }}observability-workshop" --noChmod --cacheDir /tmp/hugo_cache
- name: Create redirect handler for old URLs
run: |
cat > public/404.html << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
<script>
// Handle redirects from old versioned URLs to new root URLs
(function() {
var path = window.location.pathname;
// Match /observability-workshop/latest/ or /observability-workshop/v{version}/ patterns
var versionPattern = /^\/observability-workshop\/(latest|v[\d.]+)\/(.*)/;
var match = path.match(versionPattern);
if (match) {
// Extract the path after the version (e.g., "en/index.html")
var newPath = match[2];
// Preserve query string and hash if present
var newUrl = window.location.origin + '/observability-workshop/' + newPath + window.location.search + window.location.hash;
// Redirect to new URL
window.location.replace(newUrl);
} else {
// If no version pattern matched, show a friendly 404 message
document.write('<h1>404 - Page Not Found</h1>');
document.write('<p>The page you are looking for does not exist.</p>');
document.write('<p>Visit the <a href="/observability-workshop/">Splunk Observability Workshop homepage</a>.</p>');
}
})();
</script>
<noscript>
<meta http-equiv="refresh" content="0; url=/observability-workshop/">
</noscript>
</head>
<body>
<p>Redirecting... If you are not redirected, <a href="/observability-workshop/">click here</a>.</p>
</body>
</html>
EOF
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
publish_branch: gh-pages
force_orphan: false
user_name: ${{ github.actor }}
user_email: ${{ github.actor }}@users.noreply.github.com
commit_message: "Deploy v${{ steps.bumpversion.outputs.tag_name }}"
- name: Publish GitHub release
uses: softprops/action-gh-release@v1
with:
name: v${{ steps.bumpversion.outputs.tag_name }}
tag_name: v${{ steps.bumpversion.outputs.tag_name }}