Skip to content

Commit 7d43555

Browse files
authored
Add github actions (#137) (#140)
Cherry-picked from #137
1 parent 9e4f2d0 commit 7d43555

File tree

3 files changed

+239
-0
lines changed

3 files changed

+239
-0
lines changed
+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Use this starter workflow to deploy HTML generated by Antora to surge.sh
2+
# Docs are published at <org>-<repo>-<deployid>.surge.sh
3+
#
4+
# By default, this workflow runs on completion of a workflow called "Verify docs PR"
5+
#
6+
# This workflow expects the triggering workflow to generate an artifact called "docs"
7+
# - update the reference to "docs" and "docs.zip" in this workflow if your triggering workflow generates an artifact with a different name
8+
9+
# change to force workflow with no changelog
10+
11+
name: "Deploy docs preview"
12+
13+
on:
14+
workflow_run:
15+
workflows: ["Verify docs PR"]
16+
types:
17+
- completed
18+
19+
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'
23+
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: "Download built documentation"
28+
uses: actions/github-script@v7
29+
env:
30+
RUN_ID: ${{ github.event.workflow_run.id }}
31+
WORKSPACE: ${{ github.workspace }}
32+
with:
33+
script: |
34+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
run_id: ${{ env.RUN_ID }},
38+
});
39+
40+
var matchArtifactDocs = artifacts.data.artifacts.filter((artifact) => {
41+
return artifact.name == "docs"
42+
})[0];
43+
var downloadDocs = await github.rest.actions.downloadArtifact({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
artifact_id: matchArtifactDocs.id,
47+
archive_format: 'zip',
48+
});
49+
var fs = require('fs');
50+
fs.writeFileSync('${{ env.WORKSPACE }}/docs.zip', Buffer.from(downloadDocs.data));
51+
52+
var matchArtifactChangelog = artifacts.data.artifacts.filter((artifact) => {
53+
return artifact.name == "changelog"
54+
})[0];
55+
var downloadChangelog = await github.rest.actions.downloadArtifact({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
artifact_id: matchArtifactChangelog.id,
59+
archive_format: 'zip',
60+
});
61+
fs.writeFileSync('${{ env.WORKSPACE }}/changelog.zip', Buffer.from(downloadChangelog.data));
62+
63+
- id: unzip-docs
64+
run: unzip docs.zip
65+
66+
- id: get-top-dir
67+
run: |
68+
root=$(ls -d */index.html | sed -r 's/(.*)\/index\.html/\1/')
69+
echo "top-dir=$root" >> $GITHUB_OUTPUT
70+
71+
- id: unzip-changelog
72+
if: ${{ hashFiles('changelog.zip') != '' }}
73+
run: unzip changelog.zip
74+
75+
- id: get-deploy-id
76+
run: |
77+
deployid=$(<deployid)
78+
case "$deployid" in ''|*[!0-9]*) echo "Provided PR number is not an integer"; exit 1 ;; esac
79+
echo "deploy-id=$deployid" >> "$GITHUB_OUTPUT"
80+
81+
- id: get-deploy-url
82+
env:
83+
ORG: ${{ github.event.repository.owner.login }}
84+
REPO: ${{ github.event.repository.name }}
85+
DEPLOYID: ${{ steps.get-deploy-id.outputs.deploy-id }}
86+
run: |
87+
deployurl=$ORG-$REPO-$DEPLOYID.surge.sh
88+
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
89+
90+
- uses: actions/setup-node@v4
91+
with:
92+
node-version: lts/*
93+
94+
- name: Deploy docs to surge
95+
shell: bash
96+
env:
97+
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
98+
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}"
99+
SITE_DIR: ${{ steps.get-top-dir.outputs.top-dir }}
100+
run: |
101+
npm install -g surge
102+
surge ./$SITE_DIR $DEPLOY_URL --token "$SURGE_TOKEN"
103+
104+
# If the PR artifacts include a changelog file, add it to the PR as a comment
105+
# 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
109+
with:
110+
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
111+
recreate: true
112+
header: docs-pr-changes
113+
path: changelog
114+
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
115+
116+
# If there's no changelog, add a generic comment to the PR
117+
- name: Comment on PR (no changelog)
118+
if: ${{ hashFiles('changelog') == '' }}
119+
env:
120+
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
121+
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0
122+
with:
123+
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
124+
header: docs-pr-changes
125+
message: |
126+
Looks like you've updated the documentation!
127+
128+
Check out your changes at https://${{ env.DEPLOY_URL }}
129+
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}

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

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
name: "Verify docs PR"
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- "dev"
8+
- "5.x"
9+
- "4.[0-9]"
10+
11+
jobs:
12+
13+
# Generate HTML
14+
docs-build-pr:
15+
uses: neo4j/docs-tools/.github/workflows/[email protected]
16+
with:
17+
deploy-id: ${{ github.event.number }}
18+
retain-artifacts: 14
19+
20+
# Parse the json log output from the HTML build, and output warnings and errors as annotations
21+
# Optionally, fail the build if there are warnings or errors
22+
# By default, the job fails if there are errors, passes if there are warnings only.
23+
docs-verify-pr:
24+
needs: docs-build-pr
25+
uses: neo4j/docs-tools/.github/workflows/[email protected]
26+
with:
27+
failOnWarnings: true
28+
29+
# Get lists of changes in the PR
30+
# - all updated asciidoc files
31+
# - all updated asciidoc pages
32+
# - all new asciidoc pages
33+
docs-changes-pr:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
asciidoc-files: ${{ steps.get-file-changes.outputs.asciidoc_all_changed_files }}
37+
pages-modified: ${{ steps.get-file-changes.outputs.pages_modified_files }}
38+
pages-added: ${{ steps.get-file-changes.outputs.pages_added_files }}
39+
steps:
40+
- name: Get file changes
41+
id: get-file-changes
42+
uses: tj-actions/changed-files@cbda684547adc8c052d50711417fa61b428a9f88 # v41.1.2
43+
with:
44+
separator: ','
45+
files_yaml: |
46+
pages:
47+
- modules/**/pages/**/*.adoc
48+
asciidoc:
49+
- modules/**/*.adoc
50+
51+
# Generate a PR comment if the docs are using the pageList extension
52+
# The extension maps asciidoc source files to their HTML output paths
53+
# The comment will contain links to new and changed pages in the deployed HTML docs
54+
docs-updates-comment-pr:
55+
if: needs.docs-build-pr.outputs.pages-listed == 'success'
56+
needs: [docs-build-pr, docs-changes-pr]
57+
uses: neo4j/docs-tools/.github/workflows/[email protected]
58+
with:
59+
pages-modified: ${{ needs.docs-changes-pr.outputs.pages-modified }}
60+
pages-added: ${{ needs.docs-changes-pr.outputs.pages-added }}

.github/workflows/docs-teardown.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# copy this workflow into your repo
2+
name: "Documentation Teardown"
3+
4+
on:
5+
pull_request_target:
6+
branches:
7+
- "dev"
8+
- "5.x"
9+
- "4.[0-9]"
10+
types:
11+
- closed
12+
13+
jobs:
14+
teardown-docs:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: lts/*
21+
22+
- id: get-deploy-url
23+
env:
24+
ORG: ${{ github.event.repository.owner.login }}
25+
REPO: ${{ github.event.repository.name }}
26+
DEPLOYID: ${{ github.event.pull_request.number }}
27+
run: |
28+
deployurl=$ORG-$REPO-$DEPLOYID.surge.sh
29+
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
30+
31+
- name: Teardown documentation
32+
shell: bash
33+
env:
34+
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}"
35+
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
36+
run: |
37+
npm install -g surge
38+
surge teardown $DEPLOY_URL --token "$SURGE_TOKEN"
39+
40+
- name: Comment on PR
41+
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0
42+
with:
43+
number: ${{ github.event.pull_request.number }}
44+
header: docs-pr-changes
45+
message: |
46+
Thanks for the documentation updates.
47+
48+
The preview documentation has now been torn down - reopening this PR will republish it.
49+
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
50+

0 commit comments

Comments
 (0)