Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR Preview GitHub Action [skip ci] #155

Merged
merged 49 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0a1fad6
Drafted the 'on' trigger for the action
benji-glitsos-ga Mar 12, 2024
259e01a
Copied code from the deploy production YAML and also formatted deploy…
benji-glitsos-ga Mar 12, 2024
808f8d6
Renamed the YAML file
benji-glitsos-ga Mar 12, 2024
1e95a6e
Added 'Comment on PR' step
benji-glitsos-ga Mar 12, 2024
e073888
Refactored slightly
benji-glitsos-ga Mar 12, 2024
50771e7
Drafted the 'Deploy site' step
benji-glitsos-ga Mar 12, 2024
902c91d
Edited the comment content
benji-glitsos-ga Mar 12, 2024
9ef1656
Improving build script
benji-glitsos-ga Mar 12, 2024
46be219
Renamed file
benji-glitsos-ga Mar 12, 2024
446e460
Minor rewording
benji-glitsos-ga Mar 12, 2024
5e71b62
Removed Netlify config file
benji-glitsos-ga Mar 12, 2024
ca3e1ab
Added a 'preview is building' comment. Now the commenting uses 2 steps
benji-glitsos-ga Mar 12, 2024
c1945d3
Formatted comments using tables
benji-glitsos-ga Mar 12, 2024
c604993
Removed redundant env variable from workflow
benji-glitsos-ga Mar 12, 2024
b8593b6
Minor wording in workflow
benji-glitsos-ga Mar 12, 2024
8490181
Renamed 'install-production' script since it is now also used in the …
benji-glitsos-ga Mar 13, 2024
6f548e8
Simplified code by using env variable
benji-glitsos-ga Mar 13, 2024
5e346f2
Copied OIDC step from production workflow
benji-glitsos-ga Mar 13, 2024
e7c05e3
Deleted 'if' condition on PR Preview OIDC step
benji-glitsos-ga Mar 13, 2024
bf9a550
Created deploy preview script
benji-glitsos-ga Mar 13, 2024
5f70420
Fixed one error in code
benji-glitsos-ga Mar 13, 2024
cd728d9
Removed 'if' condition in workflow
benji-glitsos-ga Mar 13, 2024
0aa4693
Trial setup of PR Previews
omad Mar 13, 2024
f44cc8a
Allow getting OIDC creds
omad Mar 13, 2024
d073abe
Run PR Action on Synchronize as well
omad Mar 13, 2024
ae032f5
Fix PR comment posting from Actions
omad Mar 13, 2024
f72319b
Fix GitHub Comment templating
omad Mar 13, 2024
19900d2
Fix GH Workflow file
omad Mar 13, 2024
bc802d3
Update PR Preview build domain
omad Mar 13, 2024
bec1daf
Tweak comments and cache build deps
omad Mar 13, 2024
c9cc771
Fix Typo
omad Mar 13, 2024
48be718
Replaced emojis with shortcodes
benji-glitsos-ga Mar 13, 2024
25eec56
Converted Markdown tables to HTML to remove empty header row
benji-glitsos-ga Mar 13, 2024
315e0ba
Minor punctuation
benji-glitsos-ga Mar 13, 2024
7e43b2d
Wording of comment
benji-glitsos-ga Mar 13, 2024
6fb8e6f
Removed 'demo' build mode and its accompanying logic
benji-glitsos-ga Mar 14, 2024
01e93df
Editing the env variables and preview banner
benji-glitsos-ga Mar 14, 2024
ff79ca4
Renamed 'deploy_banner' python module
benji-glitsos-ga Mar 14, 2024
589e2b7
Wording on banner
benji-glitsos-ga Mar 14, 2024
ff7f670
Changed the emojis to be less colourful
benji-glitsos-ga Mar 14, 2024
64ee9b7
Minor refactor to pull request number env variable
benji-glitsos-ga Mar 14, 2024
ea788aa
Renaming some Github Action steps
benji-glitsos-ga Mar 14, 2024
383d707
Added the Pull Request Number to the comment titles
benji-glitsos-ga Mar 14, 2024
fcf5ab3
Disabled the automatic pull request hashtag link in Github markdown
benji-glitsos-ga Mar 14, 2024
070574c
Minor wording
benji-glitsos-ga Mar 14, 2024
d5cae4d
Tidying use of step IDs
benji-glitsos-ga Mar 14, 2024
c31f6c1
Made emojis more colourful and used different emojis
benji-glitsos-ga Mar 14, 2024
760a6b1
Minor punctuation
benji-glitsos-ga Mar 14, 2024
d2b0e76
Removed issue numbers from comment titles because they were too visua…
benji-glitsos-ga Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BUILD_MODE=local # local / demo / production
BUILD_MODE=local # local / pr-preview / production

LOCAL_ENABLE_REDIRECTS=Yes
LOCAL_ENABLE_TAGS=Yes
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/deploy-pr-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Deploy to PR Preview

on:
pull_request:
branches:
- main

env:
PR_PREVIEW_PULL_REQUEST_NUMBER: ${{github.event.pull_request.number}}
PR_PREVIEW_SUBDOMAIN: pr-${{github.event.pull_request.number}}-preview
PR_PREVIEW_DEPLOY_LOG_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
PR_PREVIEW_BUCKET: s3://khpreview.dea.ga.gov.au

permissions:
id-token: write # For requesting the JWT used by OIDC Authentication
issues: write
pull-requests: write

jobs:
publish:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11"]
node-version: [18.x]

steps:
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: PR Preview

- name: "Comment: PR Preview is deploying"
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{github.event.pull_request.number}}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
## :hourglass: PR Preview is deploying ...

<table>
<tr>
<td><strong>Deploy log:</strong></td>
<td><a href="${{ env.PR_PREVIEW_DEPLOY_LOG_URL }}">View the log</a></td>
</tr>
</table>

- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Pull latest from submodules
run: git submodule foreach git pull origin stable
# This doesn't update the submodule to the latest commit on the origin; therefore, you should manually do this on a semi-regular basis.

- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # Use pip to cache the installed dependencies

- name: Install dependencies
run: ./install-dependencies.sh

- name: Build site
env:
BUILD_MODE: pr-preview
run: ./build-pr-preview.sh

- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::538673716275:role/github-actions-dea-knowledge-hub-prs
aws-region: ap-southeast-2

- name: Deploy preview site
run: |
aws s3 sync --delete output "$PR_PREVIEW_BUCKET/$PR_PREVIEW_SUBDOMAIN"

- name: "Update Comment: PR Preview is ready"
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{github.event.pull_request.number}}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
## :star2: PR Preview is ready!

<table>
<tr>
<td><strong>Preview site:</strong></td>
<td><a href="https://${{ env.PR_PREVIEW_SUBDOMAIN }}.khpreview.dea.ga.gov.au/">${{ env.PR_PREVIEW_SUBDOMAIN }}.khpreview.dea.ga.gov.au</a></td>
</tr>
<tr>
<td><strong>Deploy log:</strong></td>
<td><a href="${{ env.PR_PREVIEW_DEPLOY_LOG_URL }}">View the log</a></td>
</tr>
</table>

7 changes: 4 additions & 3 deletions .github/workflows/deploy-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ permissions:

jobs:
publish:
name: Publish
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11"]
node-version: [18.x]

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -33,8 +34,8 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install requirements
run: ./install-production.sh
- name: Install dependencies
run: ./install-dependencies.sh

- name: Build site
env:
Expand Down
6 changes: 1 addition & 5 deletions build-demo.sh → build-pr-preview.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash

python -m pip install -r ./docs/requirements.txt

npm install -g sass

apt-get install -y pandoc
set -eox pipefail

mkdir -p ./output

Expand Down
22 changes: 0 additions & 22 deletions docs/_modules/deploy_banner.py

This file was deleted.

11 changes: 11 additions & 0 deletions docs/_modules/pr_preview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

def banner():
pull_request_number = os.environ.get("PR_PREVIEW_PULL_REQUEST_NUMBER")
deploy_log_url = os.environ.get("PR_PREVIEW_DEPLOY_LOG_URL")

knowledge_hub_url = "https://knowledge.dea.ga.gov.au/"
github_url = "https://github.com/GeoscienceAustralia/dea-knowledge-hub"

return f'You are viewing <strong>PR Preview #{pull_request_number}</strong>, not the official <a href="{knowledge_hub_url}">DEA Knowledge Hub</a>. View the <a href="{github_url}/pull/{pull_request_number}">Pull request</a> or <a href="{deploy_log_url}">Deploy log</a>.'

2 changes: 1 addition & 1 deletion docs/_modules/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def current_year():
def optional_exclude_pattern(environment_variable, exclude_pattern):
if (
os.environ.get(environment_variable) == "No"
and not os.environ.get("BUILD_MODE") in ["demo", "production"]
and not os.environ.get("BUILD_MODE") in ["pr-preview", "production"]
):
return [exclude_pattern]
else:
Expand Down
14 changes: 7 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
sys.path.insert(0, os.path.abspath('.'))
from _modules import utilities
from _modules import mock_imports
from _modules import deploy_banner
from _modules import pr_preview

environment = {
"build_mode": os.environ.get("BUILD_MODE"),
"git_branch": os.environ.get("BRANCH"),
"local_enable_redirects": os.environ.get("LOCAL_ENABLE_REDIRECTS"),
"local_enable_tags": os.environ.get("LOCAL_ENABLE_TAGS"),
"pr_preview_subdomain": os.environ.get("PR_PREVIEW_SUBDOMAIN"),
}

project = "DEA Knowledge Hub"
Expand Down Expand Up @@ -49,7 +50,7 @@
language = "en"

if environment["build_mode"] == "production": html_baseurl = "https://knowledge.dea.ga.gov.au/"
elif environment["build_mode"] == "demo": html_baseurl = f"https://{environment['git_branch']}--dea-docs.netlify.app/"
elif environment["build_mode"] == "pr-preview": html_baseurl = f"https://{environment['pr_preview_subdomain']}.khpreview.dea.ga.gov.au/"
else: html_baseurl = ""

html_permalinks = False
Expand Down Expand Up @@ -87,7 +88,7 @@
external_toc_path = "table_of_contents.yaml"

if (
environment["build_mode"] in ["demo", "production"]
environment["build_mode"] in ["pr-preview", "production"]
or environment["local_enable_redirects"] == "Yes"
): rediraffe_redirects = utilities.source_redirects("_redirects/*.txt")

Expand All @@ -112,7 +113,7 @@
notfound_urls_prefix = ""

tags_create_tags = (
environment["build_mode"] in ["demo", "production"]
environment["build_mode"] in ["pr-preview", "production"]
or environment["local_enable_tags"] == "Yes"
)

Expand Down Expand Up @@ -141,8 +142,8 @@
},
}

if environment["build_mode"] == "demo":
html_theme_options["announcement"] = deploy_banner.banner()
if environment["build_mode"] == "pr-preview":
html_theme_options["announcement"] = pr_preview.banner()

html_context = {
"default_mode": "light",
Expand All @@ -155,4 +156,3 @@
suppress_warnings = [
# "etoc.toctree"
]

File renamed without changes.
34 changes: 0 additions & 34 deletions netlify.toml

This file was deleted.