Skip to content

Commit 6c260c1

Browse files
committed
Use SHA for untrusted actions (#852)
1 parent b56e31f commit 6c260c1

File tree

4 files changed

+124
-48
lines changed

4 files changed

+124
-48
lines changed
Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
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+
name: "Deploy docs preview"
810

911
on:
1012
workflow_run:
11-
workflows: ["Verify PR"]
13+
workflows: ["Verify Docs PR"]
1214
types:
1315
- completed
1416

1517
jobs:
1618
publish-docs:
19+
# Uncomment this if statement to deploy only when the PR builds cleanly
1720
# if: github.event.workflow_run.conclusion == 'success'
1821

1922
runs-on: ubuntu-latest
2023

2124
steps:
2225
- name: "Download built documentation"
23-
uses: actions/[email protected]
26+
uses: actions/[email protected]
27+
env:
28+
RUN_ID: ${{ github.event.workflow_run.id }}
29+
WORKSPACE: ${{ github.workspace }}
2430
with:
2531
script: |
2632
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
2733
owner: context.repo.owner,
2834
repo: context.repo.repo,
29-
run_id: ${{ github.event.workflow_run.id }},
35+
run_id: ${{ env.RUN_ID }},
3036
});
3137
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
3238
return artifact.name == "docs"
@@ -38,7 +44,7 @@ jobs:
3844
archive_format: 'zip',
3945
});
4046
var fs = require('fs');
41-
fs.writeFileSync('${{ github.workspace }}/docs.zip', Buffer.from(download.data));
47+
fs.writeFileSync('${{ env.WORKSPACE }}/docs.zip', Buffer.from(download.data));
4248
4349
- run: unzip docs.zip
4450

@@ -47,6 +53,15 @@ jobs:
4753
deployid=$(<deployid)
4854
case "$deployid" in ''|*[!0-9]*) echo "Provided PR number is not an integer"; exit 1 ;; esac
4955
echo "deploy-id=$deployid" >> "$GITHUB_OUTPUT"
56+
57+
- id: get-deploy-url
58+
env:
59+
ORG: ${{ github.event.repository.owner.login }}
60+
REPO: ${{ github.event.repository.name }}
61+
DEPLOYID: ${{ steps.get-deploy-id.outputs.deploy-id }}
62+
run: |
63+
deployurl=$ORG-$REPO-$DEPLOYID.surge.sh
64+
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
5065
5166
- uses: actions/setup-node@v3
5267
with:
@@ -55,17 +70,35 @@ jobs:
5570
- name: Deploy docs to surge
5671
shell: bash
5772
env:
73+
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
5874
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}"
5975
run: |
6076
npm install -g surge
61-
surge ./site ${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh --token "$SURGE_TOKEN"
77+
surge ./site $DEPLOY_URL --token "$SURGE_TOKEN"
6278
63-
- name: Comment on PR
64-
uses: marocchino/sticky-pull-request-comment@v2
79+
# If the PR artifacts include a changelog file, add it to the PR as a comment
80+
# The changelog contains links to new and changed files in the deployed docs
81+
- name: Comment on PR (changelog)
82+
if: ${{ hashFiles('changelog') != '' }}
83+
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd #v2.8.0
84+
with:
85+
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
86+
recreate: true
87+
header: docs-pr-changes
88+
path: changelog
89+
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
90+
91+
# If there's no changelog, add a generic comment to the PR
92+
- name: Comment on PR (no changelog)
93+
if: ${{ hashFiles('changelog') == '' }}
94+
env:
95+
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
96+
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd #v2.8.0
6597
with:
6698
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
99+
header: docs-pr-changes
67100
message: |
68-
This PR includes documentation updates.
101+
Looks like you've updated the documentation!
69102
70-
You can view the updated docs at https://${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ steps.get-deploy-id.outputs.deploy-id }}.surge.sh
103+
Check out your changes at https://${{ env.DEPLOY_URL }}
71104
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
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+
- "dev"
8+
- "5.x"
9+
- "4.[0-9]"
10+
- "3.5"
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: 18 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-
- "3.5"
8-
- "4.[0-9]"
9-
- "5.x"
107
- "dev"
8+
- "5.x"
9+
- "4.[0-9]"
10+
- "3.5"
1111
types:
1212
- closed
1313

@@ -19,20 +19,32 @@ jobs:
1919
- uses: actions/setup-node@v3
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
2333
shell: bash
2434
env:
2535
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}"
36+
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
2637
run: |
2738
npm install -g surge
28-
surge teardown ${{ github.event.repository.owner.login}}-${{ github.event.repository.name}}-${{ github.event.pull_request.number }}.surge.sh --token "$SURGE_TOKEN"
39+
surge teardown $DEPLOY_URL --token "$SURGE_TOKEN"
40+
2941
- name: Comment on PR
30-
uses: marocchino/sticky-pull-request-comment@v2
42+
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd # v2.8.0
3143
with:
3244
number: ${{ github.event.pull_request.number }}
45+
header: docs-pr-changes
3346
message: |
3447
Thanks for the documentation updates.
3548
3649
The preview documentation has now been torn down - reopening this PR will republish it.
3750
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}
38-

0 commit comments

Comments
 (0)