Repository navigation
138 lines (131 loc) · 5.11 KB
/
Copy pathdeploy-lab.yml
File metadata and controls
138 lines (131 loc) · 5.11 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
name: Deploy Labspace labs
# Reusable workflow that validates a repo's labs, assembles a static site by
# overlaying them onto the prebuilt runtime image's payload, generates the
# labs.json catalog, and publishes to GitHub Pages. A lab author's repo calls it
# in one step:
#
# jobs:
# deploy:
# uses: dockersamples/simspace/.github/workflows/deploy-lab.yml@main
# with:
# runtime-tag: "1" # pin to a released version
# permissions:
# contents: read
# pages: write
# id-token: write
#
# Labs are loaded at runtime, so no app rebuild is needed — the site is just the
# runtime image's static files with the author's labs/ swapped in and a freshly
# generated labs.json. One lab is entered directly; several show a landing page.
on:
workflow_call:
inputs:
labs-dir:
description: "Path to the labs directory (contains labs/<id>/labspace.yaml)."
type: string
default: "labs"
runtime-image:
description: "Runtime image the site is based on."
type: string
default: "dockersamples/simspace"
authoring-image:
description: "Authoring image used to validate labs + generate the catalog."
type: string
default: "dockersamples/simspace-authoring"
runtime-tag:
description: "Image tag for BOTH images. Pin to a version for stable labs."
type: string
default: "latest"
pulse-endpoint:
description: "Base URL of the pulse presence/analytics backend. Set to
enable tracking for all labs (opt out per lab with `tracking: false`);
leave empty to disable tracking entirely."
type: string
default: ""
title:
description: "Deployment-wide site title, shown on the landing page and
browser tab in place of the \"Labspace\" default (e.g. \"Acme
Labs\"). Leave empty to keep the default."
type: string
default: ""
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Validate labs
# Validates every lab under labs/ and fails if none are found (e.g. a
# single-lab repo not yet moved to labs/<id>/).
run: |
docker run --rm \
-v "${{ github.workspace }}/${{ inputs.labs-dir }}:/labs:ro" \
"${{ inputs.authoring-image }}:${{ inputs.runtime-tag }}" \
npm run validate-lab -- /labs
build:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Assemble static site (runtime payload + these labs + catalog)
run: |
set -euo pipefail
image="${{ inputs.runtime-image }}:${{ inputs.runtime-tag }}"
docker pull "$image"
cid="$(docker create "$image")"
mkdir -p site
docker cp "$cid":/usr/share/nginx/html/. site/
docker rm "$cid"
# Replace the runtime image's sample labs + catalog with this repo's.
rm -rf site/labs site/labs.json
mkdir -p site/labs
cp -R "${{ inputs.labs-dir }}/." site/labs/
# Generate labs.json for these labs (from each labspace.yaml).
docker run --rm \
-v "${{ github.workspace }}:/work" \
"${{ inputs.authoring-image }}:${{ inputs.runtime-tag }}" \
npm run generate-catalog -- "/work/${{ inputs.labs-dir }}" /work/site/labs.json
- name: Configure deployment settings (config.json)
# The runtime image ships a dev config.json (localhost tracking, no
# title). Replace it with this deployment's settings, or remove it
# entirely when neither is set.
env:
PULSE_ENDPOINT: ${{ inputs.pulse-endpoint }}
SITE_TITLE: ${{ inputs.title }}
run: |
set -euo pipefail
json='{}'
if [ -n "${PULSE_ENDPOINT}" ]; then
json=$(jq -n --argjson base "$json" --arg endpoint "$PULSE_ENDPOINT" \
'$base + {tracking: {endpoint: $endpoint, presence: true, identity: "optional-name"}}')
echo "Tracking enabled → ${PULSE_ENDPOINT}"
else
echo "No pulse-endpoint set; tracking disabled."
fi
if [ -n "${SITE_TITLE}" ]; then
json=$(jq -n --argjson base "$json" --arg title "$SITE_TITLE" '$base + {title: $title}')
echo "Site title set → ${SITE_TITLE}"
fi
if [ "$json" != '{}' ]; then
echo "$json" > site/config.json
else
rm -f site/config.json
fi
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: site
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0