-
Notifications
You must be signed in to change notification settings - Fork 532
169 lines (144 loc) · 6.99 KB
/
Copy pathcombined-docs-md-ci.yml
File metadata and controls
169 lines (144 loc) · 6.99 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Generate PDF Documentation
on:
pull_request:
branches:
- "main"
- "pdf-documentation"
workflow_dispatch:
inputs:
folder_path:
description: "Path to the documentation folder"
required: true
default: "./docs"
sidebar_path:
description: "Path to the sidebar.js file"
required: true
default: "./sidebars.js"
combined_md_file_path:
description: "Path to the combined docs markdown file"
required: true
default: "./combined_docs.md"
permissions:
id-token: write
contents: read
jobs:
generate_docs:
runs-on: ubuntu-latest
outputs:
pdf_url: ${{ steps.s3_upload.outputs.s3_url }} # Output the S3 bucket URL where the generated PDF is stored
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: "20" # Specify the Node.js version you need
- name: Install Python
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip
- name: Install LaTeX, Pandoc, and Required Packages
run: |
sudo apt-get install -y pandoc
sudo apt-get install texlive-latex-base
sudo apt-get install texlive-luatex
sudo apt-get install lmodern
sudo apt-get install texlive-fonts-recommended
sudo apt-get install texlive-fonts-extra
sudo apt-get install texlive-latex-extra
- name: Install Ghostscript
run: |
sudo apt-get install -y ghostscript
- name: Verify Ghostscript Installation
run: |
gs --version
which gs
echo "Ghostscript installation verified"
- name: Set environment variables
env:
FOLDER_PATH: ${{ github.event.inputs.folder_path || './docs' }} # For manual runs or PR body
SIDEBAR_PATH: ${{ github.event.inputs.sidebar_path || './sidebars.js' }} # For manual runs or PR body
COMBINED_DOC_PATH: ${{ github.event.inputs.combined_md_file_path || './combined_docs.md' }} # For manual runs or PR body
BRANCH_NAME: ${{ github.head_ref || github.ref }}
run: |
echo "FOLDER_PATH=${FOLDER_PATH}" >> $GITHUB_ENV
echo "SIDEBAR_PATH=${SIDEBAR_PATH}" >> $GITHUB_ENV
echo "COMBINED_DOC_PATH=${COMBINED_DOC_PATH}" >> $GITHUB_ENV
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
# Fallback: Set the repository name as the documentation name if no title is found
- name: Set repository name as documentation name fallback
run:
| # Extracts the repository name (everything after the slash in org/repo)
echo "REPO_NAME=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)" >> $GITHUB_ENV
# Extract documentation title and determine the version number dynamically
- name: Extract title and version
run: |
DOC_TITLE=$(node -p "require('./documentation/makersaurus.config.js').title || ''")
if [[ "${{ env.FOLDER_PATH }}" == "./docs" ]]; then
VERSION=$(node -p "require('./documentation/makersaurus.config.js').versions?.current?.label || '0.0.0'")
else
VERSION=$(basename "${{ env.FOLDER_PATH }}" | sed 's/version-//')
fi
SAFE_TITLE=$(echo "$DOC_TITLE" | tr ' ' '_' | tr -dc 'A-Za-z0-9._-')
echo "DOC_TITLE=${DOC_TITLE}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "SAFE_TITLE=${SAFE_TITLE}" >> $GITHUB_ENV
# Download the script from another repository (replace with correct repo and script path)
- name: Download script and make it executable
run: |
curl -H "Authorization: bearer ${{ secrets.GH_ACTIONS_RUNNERS_H2O_OPS_TOKEN }}" -L -o ./documentation/generate_combined_md.py "https://raw.githubusercontent.com/h2oai/makersaurus/refs/heads/main/documentation/generate_combined_md.py"
curl -H "Authorization: bearer ${{ secrets.GH_ACTIONS_RUNNERS_H2O_OPS_TOKEN }}" -L -o ./documentation/generate_pdf_doc.py "https://raw.githubusercontent.com/h2oai/makersaurus/refs/heads/main/documentation/generate_pdf_doc.py"
curl -H "Authorization: bearer ${{ secrets.GH_ACTIONS_RUNNERS_H2O_OPS_TOKEN }}" -L -o ./documentation/parse_sidebar.js "https://raw.githubusercontent.com/h2oai/makersaurus/refs/heads/main/documentation/parse_sidebar.js"
chmod +x ./documentation/generate_combined_md.py
chmod +x ./documentation/generate_pdf_doc.py
chmod +x ./documentation/parse_sidebar.js
# Generate either a combined markdown file or a PDF depending on the branch
- name: Generate combined markdown or PDF
run: |
cd documentation
if [[ "${{ env.BRANCH_NAME }}" =~ ^refs/heads/pdf-documentation ]]; then
python3 generate_pdf_doc.py "${{ env.FOLDER_PATH }}" "${{ env.SIDEBAR_PATH }}" "${{ env.COMBINED_DOC_PATH }}"
else
python3 generate_combined_md.py "${{ env.FOLDER_PATH }}" "${{ env.SIDEBAR_PATH }}"
fi
# Rename the generated output files to include the documentation title and version
- name: Rename output files
run: |
cd documentation
if [[ -f documentation.pdf ]]; then
mv documentation.pdf "${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf"
fi
if [[ -f combined_docs.md ]]; then
mv combined_docs.md "${{ env.SAFE_TITLE }}_${{ env.VERSION }}.md"
fi
- name: Upload generated documentation
uses: actions/upload-artifact@v4
with:
name: documentation_artifacts
path: |
documentation/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.md
documentation/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::905418351423:role/Github-OIDC-Role-h2o-llmstudio
role-session-name: h2o-llm-studio
aws-region: us-east-1
- name: Publish documentation to S3
id: s3_upload
run: |
if [[ "${{ env.BRANCH_NAME }}" =~ ^refs/heads/pdf-documentation ]]; then
aws s3 cp "documentation/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf" s3://pdf-documentation/h2o-llm-studio/
S3_BUCKET="pdf-documentation"
S3_KEY="h2o-llm-studio/${{ env.SAFE_TITLE }}_${{ env.VERSION }}.pdf"
S3_URL="https://${S3_BUCKET}.s3.amazonaws.com/${S3_KEY}"
echo "s3_url=${S3_URL}" >> $GITHUB_OUTPUT
echo "PDF uploaded successfully to: ${S3_URL}"
else
echo "Skipping S3 upload - not on pdf-documentation branch"
fi
- name: Display PDF URL
if: steps.s3_upload.outputs.s3_url != ''
run: |
echo "PDF is available at: ${{ steps.s3_upload.outputs.s3_url }}"
echo "pdf_url=${{ steps.s3_upload.outputs.s3_url }}" >> $GITHUB_ENV