From c45de049954cb0ae956dd85956b7d5d69ca9a60c Mon Sep 17 00:00:00 2001 From: Theo-Hafsaoui Date: Sat, 7 Sep 2024 15:25:09 +0200 Subject: [PATCH] Add Dockerfile and CD with CI improvement --- .github/workflows/lint.yml | 3 ++ .github/workflows/pdf.yml | 41 +++++++++++++++++++ Dockerfile | 25 +++++++++++ Makefile | 3 ++ go.mod | 5 +-- go.sum | 4 -- .../parser/assets/latex/output/texput.log | 21 ++++++++++ internal/parser/template_sections.go | 2 +- 8 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/pdf.yml create mode 100644 Dockerfile create mode 100644 internal/parser/assets/latex/output/texput.log diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2b37bd2..28bcd7c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,3 +24,6 @@ jobs: - name: Run linter run: make lint + - name: Check dependency + run: go mod tidy && git diff --exit-code + diff --git a/.github/workflows/pdf.yml b/.github/workflows/pdf.yml new file mode 100644 index 0000000..33a8f56 --- /dev/null +++ b/.github/workflows/pdf.yml @@ -0,0 +1,41 @@ +name: Compile LaTeX Document + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build Docker image + run: docker build . -t anemon + + - name: Run Docker container + run: docker run --rm -v ${{ github.workspace }}/assets/latex/output:/output anemon + + - name: Upload compiled PDF + uses: actions/upload-artifact@v4 + with: + name: compiled-pdf + path: | + ls assets/latex/output/*.pdf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2de8b06 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.23 as build + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . +RUN make build +RUN ./anemon generate + +FROM debian:latest +COPY --from=build /app/assets/latex/output/ /internal_output +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + texlive \ + texlive-latex-extra \ + texlive-fonts-extra \ + texlive-xetex \ + texlive-font-utils \ + fonts-font-awesome \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +CMD mkdir -p /tmp_output && cd /internal_output && for i in *.tex; do pdflatex $i -output-directory=/tmp_output || true; done && ls && ls /tmp_output && cp /tmp_output/*.pdf /output/ diff --git a/Makefile b/Makefile index 2a6dfa8..3dd0a92 100644 --- a/Makefile +++ b/Makefile @@ -8,5 +8,8 @@ build: lint: golangci-lint run ./... +tidy: + go mod tidy + test: go test ./... diff --git a/go.mod b/go.mod index 1b93505..7510094 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,9 @@ module anemon go 1.22.0 +require github.com/spf13/cobra v1.8.1 + require ( - github.com/google/go-cmp v0.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/cobra v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/text v0.18.0 // indirect ) diff --git a/go.sum b/go.sum index 01e000a..912390a 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,4 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -8,7 +6,5 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= -golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/parser/assets/latex/output/texput.log b/internal/parser/assets/latex/output/texput.log new file mode 100644 index 0000000..17b1af1 --- /dev/null +++ b/internal/parser/assets/latex/output/texput.log @@ -0,0 +1,21 @@ +This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Debian) (preloaded format=pdflatex 2024.9.7) 7 SEP 2024 14:06 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +** + +! Emergency stop. +<*> + +End of file on the terminal! + + +Here is how much of TeX's memory you used: + 3 strings out of 478051 + 104 string characters out of 5840944 + 1849330 words of memory out of 5000000 + 20235 multiletter control sequences out of 15000+600000 + 512287 words of font info for 32 fonts, out of 8000000 for 9000 + 14 hyphenation exceptions out of 8191 + 0i,0n,0p,1b,6s stack positions out of 10000i,1000n,20000p,200000b,200000s +! ==> Fatal error occurred, no output PDF file produced! diff --git a/internal/parser/template_sections.go b/internal/parser/template_sections.go index 6dbf06c..4889325 100644 --- a/internal/parser/template_sections.go +++ b/internal/parser/template_sections.go @@ -29,6 +29,6 @@ const edu_template = ` const NB_P_EDU = 4 const sk_template = ` -\textbf{1}{: 2} \\ +\item \textbf{1}{: 2} \\ ` const NB_P_SK = 2