-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (125 loc) · 4.74 KB
/
convert-to-pdf.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Build PDF
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened, labeled, unlabeled]
paths:
- 'docs/REPORT.md'
- 'docs/REPORT.stub'
- 'docs/images/**'
- 'protocols/**.md'
- '.github/workflows/convert-to-pdf.yml'
jobs:
merge-markdown-files: # First job: Merge markdown files
name: Merge Markdown Files
runs-on: ubuntu-latest
steps:
- name: Print Branch Names (for debugging purposes)
run: |
echo "The baseref is $GITHUB_BASE_REF"
echo "The headref is $GITHUB_HEAD_REF"
- uses: actions/setup-python@v5
with:
python-version: 'pypy3.9' # Set to latest possible
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
- name: Checkout PR Head Branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0 # Fetch all history for .Git based projects
- name: Generate Report
run: python ./scripts/create_report.py # For 'on' try without './' if it doesn't work
- name: Set up Git and Commit Changes
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add docs/REPORT.md
git commit -m "Update REPORT.md with latest protocols" || echo "No changes to REPORT.md."
git push origin ${{ github.head_ref }}
generate-diagrams:
name: Generate Diagrams
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 'pypy3.9' # Adjust Python version as necessary
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install matplotlib
- name: Checkout PR Head Branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0 # Fetch all history for .Git based projects
- name: Checkout to Git Feature Branch
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git fetch origin ${{ github.head_ref }}
git checkout ${{ github.head_ref }}
- name: Remove Outdated Diagrams
run: |
if [ -d "./images" ]; then
git rm -r ./images/protocols_datarate.png
git rm -r ./images/protocols_frequency.png
git rm -r ./images/protocols_range.png
git commit -m "Remove existing pdfs folder"
git push origin ${{ github.head_ref }}
else
echo "images folder does not exist, skipping removal."
fi
- name: Generate Diagrams
run: |
if [ ! -d "./images" ]; then
mkdir images
else
echo "images folder already exists, skipping creation."
fi
python ./scripts/create_diagram.py
- name: Set up Git and Commit Changes
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add images/
git commit -m "Created diagrams and saved to images-folder" || echo "No diagrams to create"
git push origin ${{ github.head_ref }}
convert-to-pdf: # Second job: Convert REPORT.md to PDF
name: Convert to PDF
needs: [merge-markdown-files, generate-diagrams]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true # Ensures the action can push back to the repository
fetch-depth: 0 # Fetch all history for .Git based projects
- name: Checkout to Git Feature Branch
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git fetch origin ${{ github.head_ref }}
git checkout ${{ github.head_ref }}
- name: Remove Outdated PDFs
run: |
if [ -d "./pdfs" ]; then
git rm -r ./pdfs
git commit -m "Remove existing pdfs folder"
git push origin ${{ github.head_ref }}
else
echo "pdfs folder does not exist, skipping removal."
fi
- uses: baileyjm02/[email protected]
with:
input_dir: docs
output_dir: pdfs
images_dir: images
image_import: ./images
build_html: false # Set true to also add HTML files to the output directory
- name: Commit and Push PDF to Main
run: |
git add pdfs/
git commit -m "Automated PDF Creation" -a || echo "No changes to commit."
git push origin ${{ github.head_ref }}