Skip to content

Commit 39f2bd1

Browse files
Merge pull request #40 from neo4j/docs-workflows
Docs workflows
2 parents 192bbf7 + fc3eb4d commit 39f2bd1

8 files changed

Lines changed: 1861 additions & 3844 deletions

File tree

‎.github/workflows/docs-deploy-surge.yml‎

Lines changed: 109 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,56 @@
11
# Use this starter workflow to deploy HTML generated by Antora to surge.sh
22
# Docs are published at <org>-<repo>-<deployid>.surge.sh
3-
#
3+
#
44
# By default, this workflow runs on completion of a workflow called "Verify docs PR"
5-
#
5+
#
66
# This workflow expects the triggering workflow to generate an artifact called "docs"
77
# - update the reference to "docs" and "docs.zip" in this workflow if your triggering workflow generates an artifact with a different name
88

99
# change to force workflow with no changelog
1010

1111
name: "Deploy docs preview"
1212

13+
permissions:
14+
actions: read
15+
contents: read
16+
pull-requests: write
17+
1318
on:
1419
workflow_run:
1520
workflows: ["Verify docs PR"]
1621
types:
1722
- completed
1823

1924
jobs:
20-
publish-docs:
21-
# Uncomment this if statement to deploy only when the PR builds cleanly
22-
# if: github.event.workflow_run.conclusion == 'success'
25+
# [Optional] Restrict automatic dpeloyment to PRs from the upstream repo
26+
# For fork PRs, requires manual approval via the "preview" environment.
27+
# For PRs from the main repository this job is skipped and deploy-docs runs immediately.
28+
# Setup: create a "preview" environment in Settings → Environments with required reviewers.
29+
# approve-fork:
30+
# if: github.event.workflow_run.head_repository.full_name != github.repository
31+
# environment: preview
32+
# runs-on: ubuntu-latest
33+
# steps:
34+
# - name: Fork PR approved for deployment
35+
# run: echo "Approved"
36+
37+
deploy-docs:
38+
# needs: [approve-fork]
39+
# Run when approve-fork succeeded (fork, approved) or was skipped (non-fork).
40+
# Uncomment the conclusion check to deploy only when the PR builds cleanly:
41+
# && github.event.workflow_run.conclusion == 'success'
42+
# if: |
43+
# always() &&
44+
# (needs.approve-fork.result == 'success' || needs.approve-fork.result == 'skipped')
2345

2446
runs-on: ubuntu-latest
2547

2648
steps:
2749
- name: "Download built documentation"
28-
uses: actions/github-script@v7
50+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
2951
env:
3052
RUN_ID: ${{ github.event.workflow_run.id }}
31-
WORKSPACE: ${{ github.workspace }}
53+
ARTIFACT_DIR: ${{ runner.temp }}/artifacts
3254
with:
3355
script: |
3456
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
@@ -47,7 +69,8 @@ jobs:
4769
archive_format: 'zip',
4870
});
4971
var fs = require('fs');
50-
fs.writeFileSync('${{ env.WORKSPACE }}/docs.zip', Buffer.from(downloadDocs.data));
72+
fs.mkdirSync(process.env.ARTIFACT_DIR + '/docs', { recursive: true });
73+
fs.writeFileSync(process.env.ARTIFACT_DIR + '/docs/docs.zip', Buffer.from(downloadDocs.data));
5174
5275
var matchArtifactChangelog = artifacts.data.artifacts.filter((artifact) => {
5376
return artifact.name == "changelog"
@@ -58,67 +81,123 @@ jobs:
5881
artifact_id: matchArtifactChangelog.id,
5982
archive_format: 'zip',
6083
});
61-
fs.writeFileSync('${{ env.WORKSPACE }}/changelog.zip', Buffer.from(downloadChangelog.data));
84+
fs.mkdirSync(process.env.ARTIFACT_DIR + '/changelog', { recursive: true });
85+
fs.writeFileSync(process.env.ARTIFACT_DIR + '/changelog/changelog.zip', Buffer.from(downloadChangelog.data));
86+
87+
- id: suspicious-path-check
88+
name: Suspicious paths check
89+
env:
90+
ARTIFACT_DIR: ${{ runner.temp }}/artifacts/docs
91+
run: |
92+
cd "$ARTIFACT_DIR"
93+
if unzip -l docs.zip | grep -q "\.\./"; then
94+
exit 1
95+
fi
96+
97+
- id: hidden-files-check
98+
name: Hidden files check
99+
env:
100+
ARTIFACT_DIR: ${{ runner.temp }}/artifacts/docs
101+
run: |
102+
cd "$ARTIFACT_DIR"
103+
HIDDEN_FILES=$(find . -type f -name ".*" | wc -l)
104+
if [ "$HIDDEN_FILES" -ne 0 ]; then
105+
echo "Security Alert: Unexpected hidden files detected!"
106+
exit 1
107+
fi
62108
63109
- id: unzip-docs
64-
run: unzip docs.zip
110+
name: Unzip docs artifact
111+
env:
112+
ARTIFACT_DIR: ${{ runner.temp }}/artifacts/docs
113+
run: |
114+
cd "$ARTIFACT_DIR"
115+
unzip docs.zip
65116
66-
- id: get-top-dir
117+
- id: find-changelog
118+
name: Get changelog
67119
run: |
68-
root=$(ls -d */index.html | sed -r 's/(.*)\/index\.html/\1/')
69-
echo "top-dir=$root" >> $GITHUB_OUTPUT
120+
if [ -f "${{ runner.temp }}/artifacts/changelog/changelog.zip" ]; then
121+
echo "has-changelog=true" >> $GITHUB_OUTPUT
122+
else
123+
echo "has-changelog=false" >> $GITHUB_OUTPUT
124+
fi
70125
71126
- id: unzip-changelog
72-
if: ${{ hashFiles('changelog.zip') != '' }}
73-
run: unzip changelog.zip
74-
127+
name: Unzip changelog artifact
128+
if: ${{ steps.find-changelog.outputs.has-changelog == 'true' }}
129+
env:
130+
ARTIFACT_DIR: ${{ runner.temp }}/artifacts/changelog
131+
run: |
132+
cd "$ARTIFACT_DIR"
133+
unzip changelog.zip
134+
75135
- id: get-deploy-id
136+
name: Get deploy ID
137+
env:
138+
ARTIFACT_DIR: ${{ runner.temp }}/artifacts/docs
76139
run: |
77-
deployid=$(<deployid)
140+
deployid=$(<"$ARTIFACT_DIR/deployid")
78141
case "$deployid" in ''|*[!0-9]*) echo "Provided PR number is not an integer"; exit 1 ;; esac
79142
echo "deploy-id=$deployid" >> "$GITHUB_OUTPUT"
80143
81144
- id: get-deploy-url
145+
name: Get deploy URL
82146
env:
83147
ORG: ${{ github.event.repository.owner.login }}
84148
REPO: ${{ github.event.repository.name }}
85149
DEPLOYID: ${{ steps.get-deploy-id.outputs.deploy-id }}
86150
run: |
87151
deployurl=$ORG-$REPO-$DEPLOYID.surge.sh
88152
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
89-
90-
- uses: actions/setup-node@v4
153+
154+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
91155
with:
92156
node-version: lts/*
93-
94-
- name: Deploy docs to surge
157+
158+
- id: prepare-deploy-dir
159+
name: Prepare deploy directory
160+
shell: bash
161+
env:
162+
DOCS_SRC_DIR: ${{ runner.temp }}/artifacts/docs
163+
DOCS_DEPLOY_DIR: ${{ runner.temp }}/deploy-docs
164+
run: |
165+
mkdir -p "$DOCS_DEPLOY_DIR"
166+
# Copy only the built docs into a clean directory for deployment
167+
cp -R "$DOCS_SRC_DIR"/. "$DOCS_DEPLOY_DIR"/
168+
169+
- id: surge-deploy
170+
name: Deploy docs to surge
95171
shell: bash
96172
env:
97173
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
98174
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}"
99-
SITE_DIR: ${{ steps.get-top-dir.outputs.top-dir }}
175+
DEPLOY_DIR: ${{ runner.temp }}/deploy-docs
100176
run: |
101177
npm install -g surge
102-
surge ./$SITE_DIR $DEPLOY_URL --token "$SURGE_TOKEN"
178+
cd "$DEPLOY_DIR"
179+
surge . "$DEPLOY_URL" --token "$SURGE_TOKEN"
103180
104181
# If the PR artifacts include a changelog file, add it to the PR as a comment
105182
# The changelog contains links to new and changed files in the deployed docs
106-
- name: Comment on PR (changelog)
107-
if: ${{ hashFiles('changelog') != '' }}
108-
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0
183+
- id: comment-changelog
184+
name: Prepare changelog comment
185+
if: ${{ steps.find-changelog.outputs.has-changelog == 'true' }}
186+
uses: marocchino/sticky-pull-request-comment@70d2764d1a7d5d9560b100cbea0077fc8f633987 #v3
109187
with:
110188
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
111189
recreate: true
112190
header: docs-pr-changes
113-
path: changelog
191+
path: ${{ runner.temp }}/artifacts/changelog/changelog
114192
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
115193

116194
# If there's no changelog, add a generic comment to the PR
117-
- name: Comment on PR (no changelog)
118-
if: ${{ hashFiles('changelog') == '' }}
195+
- id: comment-no-changelog
196+
name: Comment on PR (no changelog)
197+
if: ${{ steps.find-changelog.outputs.has-changelog == 'false' }}
119198
env:
120199
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
121-
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0
200+
uses: marocchino/sticky-pull-request-comment@70d2764d1a7d5d9560b100cbea0077fc8f633987 #v3
122201
with:
123202
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
124203
header: docs-pr-changes
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
name: "Generate HTML"
3+
4+
permissions:
5+
contents: read
6+
7+
# edit the list of branches according to your repository
8+
# the list of branches should contain all the branches in your Antora publish playbooks
9+
on:
10+
push:
11+
branches:
12+
- 'main'
13+
workflow_dispatch:
14+
15+
# change `dev` and `main` according to your repository's branch names
16+
# `dev` is the branch you use to build and publish to staging
17+
# `main` is the branch you use to build and publish to neo4j.com/docs
18+
# in some cases, PROD_BRANCH and DEV_BRANCH may be the same branch
19+
env:
20+
PROD_BRANCH: 'main'
21+
DEV_BRANCH: 'main'
22+
23+
jobs:
24+
25+
prepare-ref-env:
26+
name: Set build branch and environments
27+
runs-on: ubuntu-latest
28+
outputs:
29+
build-ref: ${{ steps.set-ref-env.outputs.build-ref }}
30+
environments: ${{ steps.set-ref-env.outputs.environments }}
31+
steps:
32+
- name: Set Build Ref
33+
id: set-ref-env
34+
run: |
35+
dev_branch="${{ env.DEV_BRANCH }}"
36+
prod_branch="${{ env.PROD_BRANCH }}"
37+
38+
if [[ -z "${prod_branch}" ]]; then
39+
build_from="${dev_branch}"
40+
environments='["dev"]'
41+
elif [[ "${GITHUB_REF}" == "refs/heads/${dev_branch}" ]]; then
42+
build_from="${dev_branch}"
43+
environments='["dev"]'
44+
else
45+
build_from="${prod_branch}"
46+
environments='["prod"]'
47+
fi
48+
49+
if [[ -n "${prod_branch}" && "${dev_branch}" == "${prod_branch}" ]]; then
50+
environments='["dev","prod"]'
51+
fi
52+
53+
echo "build-ref=${build_from}" >> $GITHUB_OUTPUT
54+
echo "environments=${environments}" >> $GITHUB_OUTPUT
55+
56+
docs-build:
57+
name: Generate HTML
58+
needs: prepare-ref-env
59+
uses: neo4j/docs-tools/.github/workflows/reusable-docs-build.yml@v2
60+
with:
61+
package-script: 'verify:publish'
62+
build-ref: ${{needs.prepare-ref-env.outputs.build-ref}}
63+
fetch-depth: 0
64+
65+
docs-verify:
66+
name: Verify HTML
67+
needs: docs-build
68+
uses: neo4j/docs-tools/.github/workflows/reusable-docs-verify.yml@v2
69+
with:
70+
failOnWarnings: true
71+
72+
publish-html:
73+
name: Publish HTML
74+
needs: [docs-verify, prepare-ref-env]
75+
runs-on: ubuntu-latest
76+
77+
strategy:
78+
matrix:
79+
environments: ${{ fromJson(needs.prepare-ref-env.outputs.environments) }}
80+
81+
steps:
82+
- name: Publish to ${{ matrix.environments }}
83+
uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 #v4
84+
with:
85+
token: ${{ secrets.DOCS_DISPATCH_TOKEN }}
86+
repository: neo4j/docs-publish
87+
event-type: publish-html
88+
client-payload: |-
89+
{
90+
"org": "${{ github.repository_owner }}",
91+
"repo": "${{ github.event.repository.name }}",
92+
"run_id": "${{ github.run_id }}",
93+
"publish_env": "${{ matrix.environments }}"
94+
}

‎.github/workflows/docs-pr-checks.yml‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
21
name: "Verify docs PR"
32

3+
permissions:
4+
contents: read
5+
pull-requests: read
6+
47
on:
58
pull_request:
69
branches:
7-
- main
10+
- main
11+
812

913
jobs:
1014

1115
# Generate HTML
1216
docs-build-pr:
13-
uses: neo4j/docs-tools/.github/workflows/reusable-docs-build.yml@v1.2.0
17+
uses: neo4j/docs-tools/.github/workflows/reusable-docs-build.yml@v2
1418
with:
1519
deploy-id: ${{ github.event.number }}
1620
retain-artifacts: 14
@@ -20,7 +24,7 @@ jobs:
2024
# By default, the job fails if there are errors, passes if there are warnings only.
2125
docs-verify-pr:
2226
needs: docs-build-pr
23-
uses: neo4j/docs-tools/.github/workflows/reusable-docs-verify.yml@v1.2.0
27+
uses: neo4j/docs-tools/.github/workflows/reusable-docs-verify.yml@v2
2428
with:
2529
failOnWarnings: true
2630

@@ -37,22 +41,22 @@ jobs:
3741
steps:
3842
- name: Get file changes
3943
id: get-file-changes
40-
uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1
44+
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47
4145
with:
4246
separator: ','
4347
files_yaml: |
4448
pages:
45-
- modules/**/pages/**/*.adoc
49+
- '**/modules/**/pages/**/*.adoc'
4650
asciidoc:
47-
- modules/**/*.adoc
51+
- '**/modules/**/*.adoc'
4852
4953
# Generate a PR comment if the docs are using the pageList extension
5054
# The extension maps asciidoc source files to their HTML output paths
5155
# The comment will contain links to new and changed pages in the deployed HTML docs
5256
docs-updates-comment-pr:
5357
if: needs.docs-build-pr.outputs.pages-listed == 'success'
5458
needs: [docs-build-pr, docs-changes-pr]
55-
uses: neo4j/docs-tools/.github/workflows/reusable-docs-pr-changes.yml@v1.2.0
59+
uses: neo4j/docs-tools/.github/workflows/reusable-docs-pr-changes.yml@v2
5660
with:
5761
pages-modified: ${{ needs.docs-changes-pr.outputs.pages-modified }}
5862
pages-added: ${{ needs.docs-changes-pr.outputs.pages-added }}

0 commit comments

Comments
 (0)