Skip to content

Commit d11264c

Browse files
authored
Merge pull request #40 from Cannon07/upload_book_workflow
Upload book workflow
2 parents b21c946 + 69268a7 commit d11264c

File tree

5 files changed

+92
-13
lines changed

5 files changed

+92
-13
lines changed

.github/workflows/build_pdf_book.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build latest version of PDF Book
2+
3+
on:
4+
workflow_dispatch:
5+
repository_dispatch:
6+
types: [rebuild-book]
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build_pdf_book:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: install requirements
19+
run: |
20+
cd new-website
21+
cd utils
22+
pip install -r requirements.txt
23+
sudo apt-get install -y poppler-utils
24+
sudo apt-get install -y wkhtmltopdf
25+
26+
- name: fetch latest version of tutorials
27+
run: |
28+
sudo apt-get install jq
29+
cd new-website
30+
cd utils/tutorials
31+
python3 fetch_tutorials.py
32+
33+
- name: build pdf book
34+
env:
35+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
36+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
37+
run: |
38+
cd new-website
39+
cd utils/tutorials
40+
python3 build_pdf_book.py
41+
42+

.github/workflows/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
cd new-website
2525
cd utils
2626
pip install -r requirements.txt
27+
sudo apt-get install -y poppler-utils
28+
sudo apt-get install -y wkhtmltopdf
2729
2830
- name: Test tutorial fetching and export
2931
run: |
@@ -37,4 +39,10 @@ jobs:
3739
cd utils/tutorials
3840
python3 test_utils.py
3941
42+
- name: Test tutorials build pdf book functions
43+
run: |
44+
cd new-website
45+
cd utils/tutorials
46+
python3 test_build_pdf_book.py
47+
4048

new-website/README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ A detailed description of the working of the scripts is given below.
9393
- The script then merges these PDFs and creates the file `merged.pdf`.
9494
- The `merged.pdf` file is then uploaded to the S3 bucket.
9595
- Please note, pdfunite package is required to be installed for merging. `apt install poppler-utils`
96+
9697

9798

9899
## Deployment
@@ -107,12 +108,22 @@ A detailed description of the working of the scripts is given below.
107108

108109
## Workflow script
109110

110-
- The `deploy_gh_pages.yml` workflow script in `.github/workflows` is triggered on updates to the main branch.
111-
- The workflow runs a single job comprising of 3 steps
112-
- Fetch version data: This step fetches the latest deepchem release version from the github [api endpoint](https://api.github.com/repos/deepchem/deepchem/releases) and updates the terminal commands in `deepchem/data/home/terminal-commands.json`
113-
- Install and build: This step checks out the repository, installs the required dependencies using npm i, runs the linting process with npm run lint, and generates the static website with npm run export.
114-
- Deploy: This step deploys the website to the gh-pages branch using the [JamesIves/github-pages-deploy-action](https://github.com/JamesIves/github-pages-deploy-action). The website files are copied from the deepchem/out directory, and any files listed in the clean-exclude parameter are excluded from the cleaning process.
111+
- ### `deploy_gh_pages.yml`
112+
113+
- The `deploy_gh_pages.yml` workflow script in `.github/workflows` is triggered on updates to the main branch.
114+
- The workflow runs a single job comprising of 3 steps
115+
- Fetch version data: This step fetches the latest deepchem release version from the github [api endpoint](https://api.github.com/repos/deepchem/deepchem/releases) and updates the terminal commands in `deepchem/data/home/terminal-commands.json`
116+
- Install and build: This step checks out the repository, installs the required dependencies using npm i, runs the linting process with npm run lint, and generates the static website with npm run export.
117+
- Deploy: This step deploys the website to the gh-pages branch using the [JamesIves/github-pages-deploy-action](https://github.com/JamesIves/github-pages-deploy-action). The website files are copied from the deepchem/out directory, and any files listed in the clean-exclude parameter are excluded from the cleaning process.
118+
119+
- ### `build_pdf_book.yml`
120+
121+
- The `build_pdf_book.yml` workflow script in `.github/workflows` is triggered on updates to the `deepchem/examples/tutorials` directory in `deepchem` repository.
122+
- The workflow runs a single job comprising of 3 steps
123+
- Install requirements: This step installs the dependencies specified in the `requirements.txt` file in `new-website/utils`. It also installs poppler-utils and wkhtmltopdf packages.
124+
- Fetch latest version of tutorials: It installs the jq package and then runs the `fetch_tutorials.py` script.
125+
- Build pdf book: This step runs the `build_pdf_book.py` script.
115126

116127
## Workflow overview
117128

118-
![](./public/assets/workflow.png)
129+
![](./public/assets/workflow.png)

new-website/utils/tutorials/build_pdf_book.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,38 @@ def upload_file(file_name, bucket, object_name=None):
106106
True if file was uploaded, else False
107107
108108
"""
109+
s3_client = boto3.client('s3')
110+
try:
111+
response = s3_client.head_object(Bucket=bucket, Key=object_name)
112+
except ClientError as e:
113+
logging.error(e)
114+
else:
115+
last_modified_datetime = response['LastModified']
116+
format = '%Y-%m-%d_%H:%M:%S'
117+
formatted_time = last_modified_datetime.strftime(format)
118+
old_key = object_name
119+
new_key = f'{object_name[:-4]}_{formatted_time}.pdf'
120+
121+
s3_client.copy_object(
122+
Bucket=bucket,
123+
CopySource={'Bucket': bucket, 'Key': old_key},
124+
Key=new_key
125+
)
126+
127+
s3_client.delete_object(
128+
Bucket=bucket,
129+
Key=old_key
130+
)
109131

110-
# If S3 object_name was not specified, use file_name
111132
if object_name is None:
112133
object_name = os.path.basename(file_name)
113-
114-
# Upload the file
115-
s3_client = boto3.client('s3')
116134
try:
117135
response = s3_client.upload_file(file_name, bucket, object_name)
118136
except ClientError as e:
119137
logging.error(e)
120138
return False
121139
return True
122-
140+
123141

124142
def merge_pdf(info_path=INFO_PATH, pdf_path=PDF_PATH):
125143
"""
@@ -182,6 +200,6 @@ def compile_information_pages():
182200
html_to_pdf()
183201
merge_pdf()
184202
compile_information_pages()
185-
merge_pdf_pages(['storage/title.pdf', 'storage/acknowledgement.pdf', 'storage/contents.pdf', 'storage/merged.pdf'])
186-
upload_file('storage/full_pdf.pdf', 'deepchemtutorials', 'TutorialsBook.pdf')
203+
merge_pdf_pages(['cover.pdf', 'storage/title.pdf', 'storage/acknowledgement.pdf', 'storage/contents.pdf', 'storage/merged.pdf'])
204+
upload_file('storage/full_pdf.pdf', 'deepchemdata', 'book/TutorialsBook.pdf')
187205

new-website/utils/tutorials/cover.pdf

360 KB
Binary file not shown.

0 commit comments

Comments
 (0)