generated from ba-latex/Vorlage-Latex
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (87 loc) · 3.63 KB
/
document-build.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
name: Document builder
on:
push:
pull_request:
workflow_dispatch:
jobs:
build-pdf:
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: actions/checkout@v2
- name: Determine container version
run: echo DOCKER_IMAGE=$(cat .vscode/settings.json | python3 -c "import json, sys; print(json.load(sys.stdin)['vorlage-latex.buildcontainer'])") >> $GITHUB_ENV
- name: Pull container image
run: docker pull $DOCKER_IMAGE
- name: Build PDF
run: docker run --rm -v "$GITHUB_WORKSPACE/Latex:/latex" -u $(id -u ${USER}):$(id -g ${USER}) -e DISABLE_DIFFPDF=1 -e DISABLE_SYNCTEX=1 $DOCKER_IMAGE
- name: Archive PDF
uses: actions/upload-artifact@v2
with:
name: main.pdf
path: Latex/main.pdf
diff:
# only runs if pdf build was successful
needs: build-pdf
if: |
github.event_name == 'push' ||
github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- name: Checkout commit before push
if: |
github.event_name == 'push'
&& github.event.before != '0000000000000000000000000000000000000000'
id: checkout-push
uses: actions/checkout@v2
with:
ref: ${{ github.event.before }}
- name: Checkout pull request base
if: ${{ github.event_name == 'pull_request' }}
id: checkout-pull-request
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Stop execution on SetUp fail
if: |
steps.checkout-push.conclusion == 'skipped' &&
steps.checkout-pull-request.conclusion == 'skipped'
run: |
echo "stop=true" >> $GITHUB_ENV
echo "::warning::No checkout action ran, aborting diff. Either this workflow was triggered by a wrong event or there are no previous commits on the current branch."
- name: Determine container version
if: ${{ env.stop != 'true' }}
run: echo DOCKER_IMAGE=$(cat .vscode/settings.json | python3 -c "import json, sys; print(json.load(sys.stdin)['vorlage-latex.buildcontainer'])") >> $GITHUB_ENV
- name: Pull container image
if: ${{ env.stop != 'true' }}
run: docker pull $DOCKER_IMAGE
- name: Build PDF
if: ${{ env.stop != 'true' }}
id: build-prev
# NOTE there currently is no better way to mark a job as "allow failure" so we have to use this little hack.
# the job will still appear as successful even if the diff build fails which might be slightly misleading
run: |
if ! docker run --rm -v "$GITHUB_WORKSPACE/Latex:/latex" -u $(id -u ${USER}):$(id -g ${USER}) -e DISABLE_DIFFPDF=1 -e DISABLE_SYNCTEX=1 $DOCKER_IMAGE; then
echo "stop=true" >> $GITHUB_ENV
echo "::warning::previous build failed, not generating diff"
fi
- name: Download new main.pdf
if: ${{ env.stop != 'true' }}
uses: actions/download-artifact@v2
with:
name: main.pdf
- name: Generate diff
if: ${{ env.stop != 'true' }}
id: diff
run: |
if docker run --rm -v "$GITHUB_WORKSPACE:/data" --init -u $(id -u ${USER}):$(id -g ${USER}) $DOCKER_IMAGE xvfb-run diff-pdf -v -m -s --output-diff="/data/main-diff.pdf" "/data/Latex/main.pdf" "/data/main.pdf"; then
echo "stop=true" >> $GITHUB_ENV
echo "::warning::diff-pdf: no change detected"
fi
- name: Archive diff PDF
if: ${{ env.stop != 'true' }}
uses: actions/upload-artifact@v2
with:
name: main-diff.pdf
path: main-diff.pdf