-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (164 loc) · 6.22 KB
/
latex.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
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
170
171
172
173
174
175
176
177
name: Compile Latex and Release PDF
on:
push:
tags:
- 'v*'
branches:
- '*'
jobs:
workflow-setup:
name: Workflow Setup
runs-on: ubuntu-24.04
outputs:
runner: ${{ steps.texlive_runner.outputs.runner }}
prefix: ${{ steps.doc_prefix.outputs.prefix }}
prefixwithref: ${{ steps.doc_prefix.outputs.prefixwithref }}
pdf: ${{ steps.doc_prefix.outputs.pdf }}
tex: ${{ steps.doc_prefix.outputs.tex }}
steps:
- name: Get TeXLive Runner
id: texlive_runner
run: |
if ! [ -z "$GH_TOKEN" ]; then
runners=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/${{ github.repository_owner }}/actions/runners)
texlive=$(echo $runners | jq --arg label "self-texlive" '[.runners[] | any(.labels[]; .name == $label) and .status == "online"] | any')
if [ "$texlive" = "false" ]; then
echo "runner=ubuntu-latest" >> "$GITHUB_OUTPUT"
else
echo "runner=self-texlive" >> "$GITHUB_OUTPUT"
fi
else
echo "runner=ubuntu-latest" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.TOKEN_RUNNER }}
- name: Get Document Prefix
id: doc_prefix
run: |
prefix=$(echo "${{ github.repository }}" | cut -d'/' -f2)
echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
prefixwithref=$(echo "$prefix")-${{ github.ref_name }}
echo "prefixwithref=$prefixwithref" >> "$GITHUB_OUTPUT"
echo "pdf=$prefixwithref.pdf" >> "$GITHUB_OUTPUT"
echo "tex=$prefix.tex" >> "$GITHUB_OUTPUT"
-
name: Show Outputs
run: |
echo "runner=${{ steps.texlive_runner.outputs.runner }}"
echo "prefix=${{ steps.doc_prefix.outputs.prefix }}"
echo "prefixwithref=${{ steps.doc_prefix.outputs.prefixwithref }}"
echo "pdf=${{ steps.doc_prefix.outputs.pdf }}"
echo "tex=${{ steps.doc_prefix.outputs.tex }}"
build_latex:
needs: workflow-setup
runs-on: ${{ needs.workflow-setup.outputs.runner }}
name: Build LaTeX Artifact
env:
VERSION: ${{ github.ref_name }}
steps:
- name: Set up Git repository
uses: actions/checkout@v4
with:
clean: true
- name: Install hooks
run: |
bash ./a.cli setup
- name: Compile LaTeX document
uses: xu-cheng/latex-action@v3
if: ${{ needs.workflow-setup.outputs.runner == 'ubuntu-latest' }}
with:
root_file: ${{ needs.workflow-setup.outputs.tex }}
latexmk_shell_escape: true
post_compile: "latexmk -c; rm -rf _minted*"
- name: Compile LaTeX document
if: ${{ needs.workflow-setup.outputs.runner == 'self-texlive' }}
run: |
latexmk -shell-escape -pdf -file-line-error -halt-on-error -interaction=nonstopmode ${{ needs.workflow-setup.outputs.tex }}
- name: Rename PDF
run: mv ${{ needs.workflow-setup.outputs.prefix }}.pdf ${{ needs.workflow-setup.outputs.pdf }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ needs.workflow-setup.outputs.prefixwithref }}
path: |
./*.tex
./*.bib
./*.gin
./*.bbl
./${{ needs.workflow-setup.outputs.pdf }}
./README.adoc
./hooks*
./img*
./dat*
./*.png
./a.cli
./*.sty
./exclude.txt
./sections*
./litterature*
./graphics*
!./.git*
!./.github*
!./.vscode*
!./.idea*
!./.DS_Store*
!./.gitignore*
check:
needs: [build_latex,workflow-setup]
runs-on: ${{ needs.workflow-setup.outputs.runner }}
name: Check LaTeX Artifact
steps:
-
name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.workflow-setup.outputs.prefixwithref }}
path: ${{ github.workspace }}/artifact
-
name: List Artifact
run: ls -R ${{ github.workspace }}
-
name: Check compilation of LaTeX document from artifact
if: ${{ needs.workflow-setup.outputs.runner == 'ubuntu-latest' }}
uses: xu-cheng/latex-action@v3
with:
root_file: ${{ needs.workflow-setup.outputs.tex }}
latexmk_shell_escape: true
post_compile: "latexmk -c; rm -rf _minted*"
working_directory: ${{ github.workspace }}/artifact
-
name: Check compilation of LaTeX document from artifact
if: ${{ needs.workflow-setup.outputs.runner == 'self-texlive' }}
run: |
latexmk -shell-escape -pdf -file-line-error -halt-on-error -interaction=nonstopmode ${{ needs.workflow-setup.outputs.tex }}
working-directory: ${{ github.workspace }}/artifact
release:
needs: [workflow-setup,build_latex, check]
runs-on: ${{ needs.workflow-setup.outputs.runner }}
name: Create Release
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.workflow-setup.outputs.prefixwithref }}
path: ${{ github.workspace }}/artifact
- name: Archive Article
run: |
temp_dir=$(mktemp -d)
tar -czvf "${temp_dir}/${{ needs.workflow-setup.outputs.prefixwithref }}.tar.gz" -C artifact ./
mv "${temp_dir}/${{ needs.workflow-setup.outputs.prefixwithref }}.tar.gz" ./
rm -rf "$temp_dir"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') || contains(github.ref, 'preview') }}
name: Release ${{ github.ref_name }}
generate_release_notes: true
tag_name: ${{ github.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
files: |
artifact/${{ needs.workflow-setup.outputs.prefixwithref }}.pdf
${{ needs.workflow-setup.outputs.prefixwithref }}.tar.gz