Skip to content

Commit a4ce4d2

Browse files
authored
TCLOUD-4780: Created workflows for automatic previews (#3875)
* TCLOUD-4780: Created workflows for automatic previews * TCLOUD-4780: Set working directory only for the one step * TCLOUD-4780: Replace shell code that failed with nodejs * TCLOUD-4780: Setting permissions for id-token to write * TCLOUD-4780: Switch to using PR number instead of branch name * TCLOUD-4780: Removed branch restriction * TCLOUD-4780: Avoid creating the docs subdirectory * TCLOUD-4780: Re-add the docs folder segment for redirects Some older redirects go from the docs level (for example docs-4x) so the folder is needed to properly model the redirects. * TCLOUD-4780: Generating redirects * TCLOUD-4780: Make script parallel to speed up object creation * TCLOUD-4780: Increased parallel s3 operations to 20 * TCLOUD-4780: Create redirects in github action * TCLOUD-4780: Ensure the clean up of redirects * TCLOUD-4780: Use Lua replacment string "%1" instead of "$1" * TCLOUD-4780: Fixed missing semicolon * TCLOUD-4780: Use crypto to make the temporary file name unpredictable Note that this doesn't prevent the file being rewriten after it has been created but as we have to pass the file to other processes that can't be prevented. * TCLOUD-4780: Use preexisting file as redirect file template This avoids problems with creating temporary files. * TCLOUD-4780: Add additional metadata header to indicate 404s This solves a problem when a file created to indicate conditional redirects does not trigger a redirect but instead returns the dummy content. * TCLOUD-4780 Support atomic updates * TCLOUD-4780: Remove `--if-none-match` as it seems unsupported * TCLOUD-4780: Prefix the run number so it's more readable * TCLOUD-4780: Improve output prefix * TCLOUD-4780: Fix typo * TCLOUD-4780: Try redirect without URL encoding * TCLOUD-4780: Reduce logging * TCLOUD-4780: Fix a strange redirect * TCLOUD-4780: Move the generation of redirects to an action * TCLOUD-4780: Try using a tag to reference the action * TCLOUD-4780: Maybe enable debug logs * TCLOUD-4780: Fix calculation of prefix * TCLOUD-4780: Try referring to env vars just by their name * TCLOUD-4780: Try prefixing env vars with "env." * TCLOUD-4780: Change AWS region * TCLOUD-4780: Fix creation of pointer file * TCLOUD-4780: Try loading redirects from a URL * TCLOUD-4780: Revert to using local file path for redirects * TCLOUD-4780: Use v1.0 of the tinymce-docs-generate-redirects-action * TCLOUD-4780: Remove out of date comments * TCLOUD-4780: Update assumed role The service was renamed to tinymce-docs and so the role was updated to match. * TCLOUD-4780: Fix codeql's complaint about no Javascript
1 parent dea49aa commit a4ce4d2

File tree

5 files changed

+3484
-0
lines changed

5 files changed

+3484
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Preview Create/Update
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
10+
11+
# Need ID token write permission to use OIDC
12+
permissions:
13+
id-token: write
14+
15+
env:
16+
PR: pr-${{ github.event.number }}
17+
RUN: run-${{ github.run_number }}-${{ github.run_attempt }}
18+
19+
jobs:
20+
21+
build:
22+
name: Update Docs Preview
23+
24+
runs-on: ubuntu-latest
25+
26+
defaults:
27+
run:
28+
shell: bash
29+
30+
steps:
31+
- name: Checkout branch
32+
uses: actions/checkout@v5
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v5
36+
with:
37+
cache: 'yarn'
38+
node-version: 24
39+
40+
- name: Install dependencies
41+
run: yarn install
42+
43+
- name: Build Website
44+
run: yarn antora ./antora-playbook.yml
45+
46+
- name: Rename site folder to docs
47+
run: |
48+
mv ./build/site ./build/docs
49+
50+
- name: Rename sitemap.xml to antora-sitemap.xml
51+
run: |
52+
mv ./build/docs/sitemap.xml ./build/docs/antora-sitemap.xml
53+
54+
- name: configure aws credentials
55+
uses: aws-actions/[email protected]
56+
with:
57+
role-to-assume: arn:aws:iam::327995277200:role/staging-tinymce-docs-update
58+
role-session-name: tinymce-docs-update
59+
aws-region: us-east-1
60+
61+
- name: Upload website preview to S3
62+
run: |
63+
aws s3 sync ./build s3://tiny-cloud-antora-docs-preview/${PR}/${RUN}
64+
65+
- name: Create redirects on S3
66+
uses: tinymce/[email protected]
67+
with:
68+
build: ./build/
69+
redirects: ./redirects.json
70+
bucket: tiny-cloud-antora-docs-preview
71+
prefix: ${{ env.PR }}/${{ env.RUN }}
72+
parallel: 10
73+
74+
- name: Update pointer to current run output
75+
run: |
76+
aws s3api put-object --bucket tiny-cloud-antora-docs-preview --key ${PR}/index.html --body .github/workflows/resources/empty.html --content-type text/html --metadata pointer=${RUN}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Preview Delete
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
# Need ID token write permission to use OIDC
9+
permissions:
10+
id-token: write
11+
12+
env:
13+
PR: pr-${{ github.event.number }}
14+
15+
jobs:
16+
cleanup:
17+
name: Cleanup Docs Preview
18+
19+
runs-on: ubuntu-latest
20+
21+
defaults:
22+
run:
23+
shell: bash
24+
25+
steps:
26+
- name: Checkout branch
27+
uses: actions/checkout@v5
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v5
31+
with:
32+
cache: 'yarn'
33+
node-version: 24
34+
35+
- name: configure aws credentials
36+
uses: aws-actions/[email protected]
37+
with:
38+
role-to-assume: arn:aws:iam::327995277200:role/staging-docs-preview-update
39+
role-session-name: docs-preview-delete
40+
aws-region: us-east-2
41+
42+
- name: Remove website preview from S3
43+
run: |
44+
aws s3 rm s3://tiny-cloud-antora-docs-preview/${PR}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!doctype html><title>?</title>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Give CodeQL something to scan so it doesn't complain there is no Javascript...
2+
console.log('Hello world');

0 commit comments

Comments
 (0)