Skip to content

Commit f91370c

Browse files
committed
Update workflows to 1.2.0 (#119)
1 parent bb17a2c commit f91370c

File tree

4 files changed

+173
-54
lines changed

4 files changed

+173
-54
lines changed
Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,129 @@
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-
# By default, this workflow runs on completion of a workflow called "Verify PR"
3+
#
4+
# By default, this workflow runs on completion of a workflow called "Verify docs PR"
5+
#
46
# This workflow expects the triggering workflow to generate an artifact called "docs"
5-
67
# - update the reference to "docs" and "docs.zip" in this workflow if your triggering workflow generates an artifact with a different name
7-
name: "Deploy to surge"
8+
9+
# change to force workflow with no changelog
10+
11+
name: "Deploy docs preview"
812

913
on:
1014
workflow_run:
11-
workflows: ["Verify PR"]
15+
workflows: ["Verify docs PR"]
1216
types:
1317
- completed
1418

1519
jobs:
1620
publish-docs:
21+
# Uncomment this if statement to deploy only when the PR builds cleanly
1722
# if: github.event.workflow_run.conclusion == 'success'
1823

1924
runs-on: ubuntu-latest
2025

2126
steps:
2227
- name: "Download built documentation"
23-
uses: actions/[email protected]
28+
uses: actions/github-script@v7
29+
env:
30+
RUN_ID: ${{ github.event.workflow_run.id }}
31+
WORKSPACE: ${{ github.workspace }}
2432
with:
2533
script: |
2634
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
2735
owner: context.repo.owner,
2836
repo: context.repo.repo,
29-
run_id: ${{ github.event.workflow_run.id }},
37+
run_id: ${{ env.RUN_ID }},
3038
});
31-
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
39+
40+
var matchArtifactDocs = artifacts.data.artifacts.filter((artifact) => {
3241
return artifact.name == "docs"
3342
})[0];
34-
var download = await github.rest.actions.downloadArtifact({
43+
var downloadDocs = await github.rest.actions.downloadArtifact({
3544
owner: context.repo.owner,
3645
repo: context.repo.repo,
37-
artifact_id: matchArtifact.id,
46+
artifact_id: matchArtifactDocs.id,
3847
archive_format: 'zip',
3948
});
4049
var fs = require('fs');
41-
fs.writeFileSync('${{ github.workspace }}/docs.zip', Buffer.from(download.data));
42-
43-
- run: unzip docs.zip
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
4474

4575
- id: get-deploy-id
4676
run: |
4777
deployid=$(<deployid)
48-
echo "::set-output name=deploy-id::$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
4989
50-
- uses: actions/setup-node@v3
90+
- uses: actions/setup-node@v4
5191
with:
5292
node-version: lts/*
5393

5494
- 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 }}
55100
run: |
56101
npm install -g surge
57-
surge ./site ${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh --token ${{ secrets.SURGE_TOKEN }}
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 }}
58115

59-
- name: Comment on PR
60-
uses: marocchino/sticky-pull-request-comment@v2
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
61122
with:
62123
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
124+
header: docs-pr-changes
63125
message: |
64126
Looks like you've updated the documentation!
65127
66-
Check out your changes at https://${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh
128+
Check out your changes at https://${{ env.DEPLOY_URL }}
67129
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}

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

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

.github/workflows/docs-pr.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/docs-teardown.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ name: "Documentation Teardown"
44
on:
55
pull_request_target:
66
branches:
7-
- "4.4"
8-
- "5.0"
9-
- "5.x"
10-
- "dev"
7+
- 'main'
8+
- 'dev'
9+
- '5.x'
10+
- '4.4'
1111
types:
1212
- closed
1313

@@ -16,10 +16,36 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/setup-node@v3
19+
- uses: actions/setup-node@v4
2020
with:
2121
node-version: lts/*
22+
23+
- id: get-deploy-url
24+
env:
25+
ORG: ${{ github.event.repository.owner.login }}
26+
REPO: ${{ github.event.repository.name }}
27+
DEPLOYID: ${{ github.event.pull_request.number }}
28+
run: |
29+
deployurl=$ORG-$REPO-$DEPLOYID.surge.sh
30+
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
31+
2232
- name: Teardown documentation
33+
shell: bash
34+
env:
35+
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}"
36+
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
2337
run: |
2438
npm install -g surge
25-
surge teardown ${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ github.event.pull_request.number }}.surge.sh --token ${{ secrets.SURGE_TOKEN }}
39+
surge teardown $DEPLOY_URL --token "$SURGE_TOKEN"
40+
41+
- name: Comment on PR
42+
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0
43+
with:
44+
number: ${{ github.event.pull_request.number }}
45+
header: docs-pr-changes
46+
message: |
47+
Thanks for the documentation updates.
48+
49+
The preview documentation has now been torn down - reopening this PR will republish it.
50+
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
51+

0 commit comments

Comments
 (0)