Skip to content

Commit 247c2d0

Browse files
add pdf artifact upload step (#3410)
* add pdf artifact upload step * tried to fix artifact name * add pdfs to ignore * removed ignored pdfs * artifacts downloaded in deploy script * lint fixes * shellcheck adjust * adjusted descriptions in the script and readme * Update src/README.md * Update src/README.md * Update src/README.md Co-authored-by: Barry Pollard <barrypollard@google.com> --------- Co-authored-by: Barry Pollard <barrypollard@google.com>
1 parent 6583d08 commit 247c2d0

4 files changed

Lines changed: 50 additions & 11 deletions

File tree

.github/workflows/predeploy.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# A pre-deploy script that must be run in GitHub Actions to:
66
# - Update timestamps and hashes
77
# - Generate the ebooks
8+
# - Upload ebooks as artifacts
89
# - Submit a Pull Request with the changes
910
#
1011
# This should be run before every release
@@ -63,6 +64,14 @@ jobs:
6364
run: |
6465
cd src
6566
npm run ebooks
67+
- name: Upload PDF artifact
68+
if: ${{ github.event.inputs.ebooks == 'true' }}
69+
uses: actions/upload-artifact@v3
70+
with:
71+
name: pdfs
72+
path: ./src/static/pdfs/*.pdf
73+
if-no-files-found: warn # 'warn' or 'ignore' are also available, defaults to `warn`
74+
retention-days: 5 # defaults to 90
6675
- name: Update timestamps
6776
run: |
6877
cd src
@@ -73,9 +82,9 @@ jobs:
7382
with:
7483
title: Pre-deploy Updates
7584
branch-suffix: timestamp
76-
commit-message: Update Timestamps and Generate Ebooks
85+
commit-message: Update Timestamps
7786
body: |
78-
Updated Timestamps and Regenerated Ebooks through GitHub action
87+
Updated Timestamps through GitHub action
7988
- Auto-generated by [create-pull-request][1] GitHub Action
8089
8190
[1]: https://github.com/peter-evans/create-pull-request

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ env/
44
*.log
55
*.pyc
66
**/.DS_Store
7+
src/static/pdfs/
8+
.env

src/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ It is possible to run the Super-Linter locally if you have Docker installed.
177177
First up pull the Super-Linter Docker image (this takes some time to download but only need to do this once or when you want to upgrade the version of the super-linter):
178178

179179
```
180-
docker pull github/super-linter:latest
180+
docker pull github/super-linter/slim:latest
181181
```
182182

183183
Then to run the linting do this:
@@ -253,7 +253,7 @@ To actually generate the ebooks, start your local server, then run the following
253253
npm run ebooks
254254
```
255255

256-
There is a GitHub Action which can be run manually from the Actions tab to generate the Ebooks and open a Pull Request for them. This is the easiest way to generate them.
256+
There is a GitHub Action which can be run manually from the Actions tab to generate the Ebooks and store the resulting files in an artifact. This is the easiest way to generate them.
257257

258258
## Generating ebooks - including print-ready ebooks if you want a hardcopy
259259

@@ -291,7 +291,7 @@ This is the same as below since it uses all the default settings:
291291
prince "http://127.0.0.1:8080/en/2019/ebook?print&printer&page-size=A5&inside-margin=19.5mm&bleed=3mm&prince-trim=5mm&base-font-size=10px" -o static/pdfs/web_almanac_2019_en_print_A5.pdf
292292
```
293293

294-
Note this will create two extra pages at the begining which will need to be removed with a PDF editor (e.g. Adobe Acrobat) to start with a clean page starting on right hand side for printing. Please remove these before checking in versions into git.
294+
Note this will create two extra pages at the begining which will need to be removed with a PDF editor (e.g. Adobe Acrobat) to start with a clean page starting on right hand side for printing. Please remove these before deploying.
295295

296296
It is also possible to generate a cover using the `&cover` URL param. This consists of basically 2 pages - the first page is a double width-page with front and back cover as one page (with spine in between) and the second page is a blank inside page.
297297

@@ -332,6 +332,14 @@ You must first do some setup locally:
332332
gcloud init
333333
```
334334

335+
3. Set Github personal access token to GITHUB_TOKEN environment variable
336+
337+
Use an existing token or create a new token [in GitHub.com](https://github.com/settings/personal-access-tokens/new). In token configuration select *Repository access = Public Repositories (read-only)*.
338+
339+
```bash
340+
export GITHUB_TOKEN=...
341+
```
342+
335343
### Deploying staged versions of the site
336344

337345
It's sometimes useful to deploy a staged version of the site for others to see this.
@@ -360,8 +368,9 @@ The deploy script will do the following:
360368
- Ask you to confirm you've run the pre-deploy script via GitHub Actions
361369
- Switch to the production branch
362370
- Merge changes from main
363-
- Do a clean install
364-
- Run the tests
371+
- Do a clean install (remove generated chapters and e-books)
372+
- Download latest e-books from Github Action artifacts
373+
- Run and test the website
365374
- Ask you to complete any local tests and confirm good to deploy
366375
- Ask for a version number (suggesing the last verision tagged and incrementing the patch)
367376
- Tag the release (after asking you for the version number to use)

src/tools/scripts/deploy.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
22

33
# This script is used to deploy the Web Almanac to Google Cloud Platform (GCP).
4-
# Users must have push permissions on the production branch and also release
5-
# permissions for the Web Almanac on GCP
4+
# Users must have the following permissions:
5+
# - push permissions on the production branch,
6+
# - Github permissions to download the latest e-books from Github Action artifacts,
7+
# - release permissions for the Web Almanac on GCP
68

79
# exit when any command fails instead of trying to continue on
810
set -e
@@ -98,10 +100,27 @@ if [ "$(pgrep -f 'python main.py')" ]; then
98100
pkill -9 python main.py
99101
fi
100102

101-
#Remove generated chapters (in case new one from other branch in there)
103+
#Remove generated chapters and e-books (in case new one from other branch in there)
102104
# Or with "true" to prevent failure if files don't exist
103-
echo "Removing Generated Chapters"
105+
echo "Removing Generated Chapters and e-books"
104106
rm -f ./templates/*/*/chapters/* || true
107+
rm -f ./static/pdfs/* || true
108+
109+
# Download latest e-books from Github Action artifacts
110+
echo "Downloading latest e-books from Github Action artifacts"
111+
# Set your GitHub repository and workflow name
112+
REPO_OWNER=HTTPArchive
113+
REPO_NAME=almanac.httparchive.org
114+
WORKFLOW_ID=predeploy.yml
115+
116+
# Get the latest workflow run ID and download its artifact's ZIP file
117+
RUN_ID=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/workflows/${WORKFLOW_ID}/runs" | jq -r '.workflow_runs[0].id')
118+
ARTIFACT_ID=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runs/${RUN_ID}/artifacts" | jq -r '.artifacts[0].id')
119+
curl -L -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/artifacts/${ARTIFACT_ID}/zip" -o "${ARTIFACT_ID}.zip"
120+
121+
# Extract the contents of the ZIP file and clean up
122+
unzip -q "${ARTIFACT_ID}.zip" -d ./static/pdfs/
123+
rm "${ARTIFACT_ID}.zip"
105124

106125
echo "Run and test website"
107126
./tools/scripts/run_and_test_website.sh

0 commit comments

Comments
 (0)