-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
131 lines (118 loc) · 3.98 KB
/
action.yml
File metadata and controls
131 lines (118 loc) · 3.98 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
name: "Typst Out"
description: "Build Typst files using a custom Typst ref"
branding:
icon: "file-text"
color: "blue"
inputs:
typst_version:
description: "The version or ref of Typst to use for building"
required: false
default: "latest"
retention_days:
description: "The number of days to retain the PDFs as artifacts"
required: false
default: "7"
artifacts_name:
description: "The name of the artifacts to upload"
required: false
default: "typst_output"
output_extensions:
description: "The extensions of the output files"
required: false
default: "pdf"
template_file:
description: "The template file to use"
required: false
default: "template.typ"
runs:
using: "composite"
steps:
- name: Echo Typst ref
shell: bash
run: |
echo "Typst ref: ${{ inputs.typst_ref }}"
- name: Check Version
id: check_version
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
function get_rate_limit() {
rate_limit_remaining=$(gh api rate_limit --jq '.rate.remaining')
reset_time=$(gh api rate_limit --jq '.rate.reset')
echo "Rate limit remaining: $rate_limit_remaining"
}
function wait_for_rate_limit() {
while [[ $rate_limit_remaining -eq 0 ]]; do
echo "Rate limit exceeded. Waiting for reset..."
sleep $((reset_time - $(date +%s)))
get_rate_limit
done
}
function fetch_typst_version() {
retry_count=0
max_retries=3
while true; do
if [[ "${{ inputs.typst_version }}" == "latest" ]]; then
echo "Typst version: latest"
typst_ref=$(gh api https://api.github.com/repos/typst/typst/releases/latest --jq '.tag_name' || echo "fail")
else
echo "Typst version: ${{ inputs.typst_version }}"
typst_ref=${{ inputs.typst_version }}
fi
if [[ $typst_ref != "fail" ]]; then
break
else
echo "Failed to fetch Typst version. Retrying in 5 seconds..."
((retry_count++))
if [[ $retry_count -ge $max_retries ]]; then
echo "Max retries reached. Exiting with failure."
exit 1
fi
sleep 5
fi
done
}
get_rate_limit
wait_for_rate_limit
fetch_typst_version
echo "Using Typst ref: $typst_ref"
echo "typst_ref=$typst_ref" >> $GITHUB_OUTPUT
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
- name: Cache Typst
uses: actions/cache@v5
id: typst_cache
with:
path: ~/.cargo/bin/typst
key: typst-${{ steps.check_version.outputs.typst_ref }}-${{ runner.os }}
- name: Install Typst
if: steps.typst_cache.outputs.cache-hit != 'true'
shell: bash
run: |
# Install typst-cli from git using cargo
cargo install --git https://github.com/typst/typst.git --rev ${{ steps.check_version.outputs.typst_ref }} typst-cli
- name: Compile Typst files
shell: bash
run: |
templatefile="${{ inputs.template_file }}"
outputextension="${{ inputs.output_extensions }}"
echo "Compiling Typst files"
echo "Template file: $templatefile"
echo "Output extension: $outputextension"
find . -name "*.typ" -not -name "template.typ" | while read -r file; do
echo "Compiling $file to ${file%.typ}.${outputextension}"
typst compile "$file" "${file%.typ}.${outputextension}"
done
echo "Compiled Typst files"
echo "Output files:"
find . -name "*.$outputextension"
- name: Upload ouputs as artifacts
uses: actions/upload-artifact@v6
with:
name: ${{ inputs.artifacts_name }}
path: |
./**/*.pdf
retention-days: ${{ inputs.retention_days }}