Skip to content

Commit

Permalink
Feature/oppgrader latex og fix avstander (#1149)
Browse files Browse the repository at this point in the history
Omfattende rework av latex mal til siste design i NAV, samt en del side-bryting bugfixes og forbedringer. Major bump av LaTeX og biblioteker til siste versjon. Forenkler mal-element hierarkiet som rendres (kun paragraph skille mellom text literals, ikke andre elementer). Paralelliserer integrasjonstester og visuelle tester på større github node.
  • Loading branch information
hconhegg authored Jan 16, 2025
1 parent c9d5445 commit eb27d92
Show file tree
Hide file tree
Showing 95 changed files with 1,255 additions and 912 deletions.
31 changes: 10 additions & 21 deletions .github/workflows/pdfbygger-brevbaker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ jobs:
steps:
- uses: "actions/checkout@v4"
- uses: "gradle/actions/wrapper-validation@v4"
- uses: "actions/cache@v4"
with:
"path": "~/.gradle/caches"
"key": "${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}"
"restore-keys": "${{ runner.os }}-gradle-"
- uses: "actions/setup-java@v4"
with:
"distribution": "temurin"
"java-version": "17"
"cache": "gradle"

- name: "compile and run tests"
run: |
./gradlew :brevbaker-api-model-common:publishToMavenLocal
Expand Down Expand Up @@ -79,15 +76,11 @@ jobs:
steps:
- uses: "actions/checkout@v4"
- uses: "gradle/actions/wrapper-validation@v4"
- uses: "actions/cache@v4"
with:
"path": "~/.gradle/caches"
"key": "${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}"
"restore-keys": "${{ runner.os }}-gradle-"
- uses: "actions/setup-java@v4"
with:
"distribution": "temurin"
"java-version": "17"
"cache": "gradle"
- name: "compile and run tests"
run: "./gradlew :pdf-bygger:build"
- name: "Build and publish container image to GAR"
Expand Down Expand Up @@ -137,23 +130,19 @@ jobs:
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
runs-on: ubuntu-latest
runs-on: ubuntu-latest-16-cores
permissions:
statuses: write
checks: write
pull-requests: write
packages: write
steps:
- uses: "actions/checkout@v4"
- uses: "actions/cache@v4"
with:
"path": "~/.gradle/caches"
"key": "${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}"
"restore-keys": "${{ runner.os }}-gradle-"
- uses: "actions/setup-java@v4"
with:
"distribution": "temurin"
"java-version": "17"
"cache": "gradle"
- name: "run integration tests"
run: |
./gradlew :brevbaker-api-model-common:publishToMavenLocal
Expand All @@ -170,17 +159,17 @@ jobs:
report_paths: '**/build/test-results/integrationTest/TEST-*.xml'
- name: Convert visual-test pdfs
uses: routsi/[email protected]
if: ${{ needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main' }}
if: ${{ (needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main') && github.event_name != 'workflow_dispatch' }}
with:
command: mogrify -path pensjon-brevbaker/build/test_visual -format png -background white -alpha remove -alpha off -density 300 -quality 85 pensjon-brevbaker/build/test_visual/pdf/*.pdf
command: mogrify -path pensjon-brevbaker/build/test_visual -format png -background white -alpha remove -alpha off -density 230 -quality 85 pensjon-brevbaker/build/test_visual/pdf/*.pdf
- uses: actions/setup-node@v4
if: ${{ needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main' }}
if: ${{ (needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main') && github.event_name != 'workflow_dispatch' }}
with:
node-version: '20'
- run: npm install --save-dev @percy/cli
if: ${{ needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main' }}
if: ${{ (needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main') && github.event_name != 'workflow_dispatch' }}
- name: Publish visual-tests to percy
if: ${{ needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main' }}
if: ${{ (needs.changes.outputs.latex == 'true' || github.ref == 'refs/heads/main') && github.event_name != 'workflow_dispatch' }}
run: |
npx percy upload pensjon-brevbaker/build/test_visual/ > percy.log
cat percy.log
Expand Down
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,47 @@ En strategi for overgangen kan se slik ut:
```
3. Ta i bruk den nye versjonen i avsender systemet.

# Oppdatere LaTeX mal/avhengigheter

## Iterere på endringer

For å fort kunne oppdatere latex filene i pdf-byggeren under kjøring, anbefales det å kjøre følgende kommando som before launch for LatexVisualITest.

```bash
docker exec -u 0 -it pensjonsbrev_pdf-bygger_1 rm -rf /app/pensjonsbrev_latex && docker cp ./pdf-bygger/containerFiles/latex pensjonsbrev_pdf-bygger_1:/app/pensjonsbrev_latex/
```

Da vil du kunne se på pensjon-brevbaker/build/test_visual/pdf resultatet av endringen fort.

## Se forskjell mellom endringer og gammel versjon
For å se at du kun har endret det du skal, så kan du kjøre følgende script etterpå:
```bash
folder=./pensjon-brevbaker/build/test_visual
original_files=$folder/image_old
compare_to_folder=$folder/pdf
mogrify_folder=$folder/image_new
output_folder=$folder/out
mkdir -p $output_folder
mkdir -p $mogrify_folder
magick mogrify -path $mogrify_folder -format png -background white -alpha remove -alpha off -density 200 -quality 85 $compare_to_folder/*.pdf
for absolutefilename in $original_files/*.png; do
filename=$(basename "$absolutefilename")
echo -e "\n-------------------------------"
echo comparing $filename
magick compare -metric MAE -density 150 -compose multiply $original_files/$filename $mogrify_folder/$filename $output_folder/$filename
echo -e "\n-------------------------------"
done
```

Først en gang for å lage bilder i image_new, så kan du kopiere bildene til image_old for å få ett sammenligningsgrunnlag.
Deretter kan du kjøre scriptet på nytt og få vite hvor ulike de er, samt en diff mellom bildene i out mappen.

Du vil også kunne se disse endringene i percey ved å lage en pull-request.

## Oppdatere latex biblioteker
Ved først bygge pensjon-pdf-bygger/latex.Dockerfile, så sette "from" i pensjon-pdf-bygger/Dockerfile, kan du iterere over det å oppdatere latex imaget/pakker.
Når du er ferdig med det, så kan du kjøre github action workflowen "update-latex-image" på branchen, så vil den publisere ett nytt dato-stemplet image som kan tas i bruk i pensjon-pdf-bygger/Dockerfile.

# Kode generert av GitHub Copilot

Dette repoet inneholder forekomster av kode generert av GitHub Copilot.
Expand All @@ -154,7 +195,7 @@ Dette repoet inneholder forekomster av kode generert av GitHub Copilot.
ERROR: Cannot connect to kubernetes cluster dev-gcp: getting credentials
Have you remembered to connect naisdevice? (see https://doc.nais.io/basics/access/)
```
- Hvis du har tidligere fulgt setupen, kan du prøve å verifiser at du er autensitert i gcloud, og potensielt oppdatere credentials ved å kjøre `gcloud auth login --update-adc`, så kan du prøve igjen
- Hvis du har tidligere fulgt setupen, kan du prøve å verifiser at du er autensitert i gcloud, og potensielt oppdatere credentials ved å kjøre `gcloud auth login --update-adc`, så kan du prøve igjen.
#### Får ikke kjørt jq etter å ha lastet den ned
- Prøv `brew install jq`
- Prøv `brew install jq`.
3 changes: 2 additions & 1 deletion pdf-bygger/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ ENV DEBIAN_FRONTEND="noninteractive" TZ="Europe/London"
ENV PATH="${PATH}:/app/tex/bin/x86_64-linux/"
ENV TEXINPUTS=".:/app/pensjonsbrev_latex//:"
COPY containerFiles/fonts /usr/share/fonts
RUN fc-cache /usr/share/fonts # Build font cache for faster latex compile time. About 400 ms faster per letter
COPY containerFiles/latex /app/pensjonsbrev_latex
RUN apt update && apt -y install tzdata perl-tk && rm -rf /var/lib/apt/lists/*
#To update TeXLive/XeLaTeX version, run the github workflow and replace the --from argument to newest release
COPY --from=ghcr.io/navikt/pensjonsbrev/pensjon-latex:2022-09-15-12_53 /app /app
COPY --from=ghcr.io/navikt/pensjonsbrev/pensjon-latex:2024-12-30-14_56 /app /app

USER apprunner
COPY build/libs/pdf-bygger.jar /app/app.jar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Copyright 2010, 2012, 2014 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name Source.
Copyright 2010-2020 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
https://openfontlicense.org


-----------------------------------------------------------
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 19 additions & 3 deletions pdf-bygger/containerFiles/latex/attachment.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
% setup a counter to uniquely identify attachments (used for labeling the last page of attachments)
\newcounter{attachments}

\newcommand{\saksinfovedlegg}{
\begin{saksinfotable}{}
\feltvedlegggjeldernavnprefix & \feltnavnbruker \\
\feltfoedselsnummerprefix & \feltfoedselsnummerbruker \\
\feltsaksnummerprefix & \feltsaksnummer \hfill \letterdate\\
\end{saksinfotable}
}

% produces a label for the current attachment
\newcommand{\startvedlegg}[2]{
% make sure that the attachment starts on an even page (for printing)
Expand All @@ -17,9 +25,17 @@
\stepcounter{attachments}
% increase the attachment counter to identify this attachment
\logo
\vspace*{55pt}
#2
\titleText{#1}
\ifthenelse{\equal{#2}{includesakinfo}}{
\addvspace{37pt}
\sakspart{\saksinfovedlegg}
\addvspace{6pt}
\titleText{#1}
\addvspace{25pt}
}{
\addvspace{28pt}
\titleText{#1}
\addvspace{25pt}
}
}

\newcommand{\sluttvedlegg}{
Expand Down
52 changes: 42 additions & 10 deletions pdf-bygger/containerFiles/latex/closing.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,64 @@
% Closing/last page of letter
%----------------------------------------

\newcommand{\closingsinglesignature}{
\vspace{4pt}
\feltsaksbehandlernavn
\\ \feltclosingsaksbehandlersuffix
\par
\vspace*{18pt}
\feltnavenhet
}

\newcommand{\closingdoublesignature}{
\vspace{5pt}
\doublesignature{\feltattestantnavn}{\feltsaksbehandlernavn}
\par
\vspace*{11pt}
\feltnavenhet
}

\newcommand{\closingautosignature}[1]{
\feltnavenhet
\par
\vspace*{18pt}
#1
}

\newcommand{\closingautosignaturevedtaksbrev}{
\closingautosignature{\feltclosingautomatisktextvedtaksbrev}
}

\newcommand{\closingautosignatureinfobrev}{
\closingautosignature{\feltclosingautomatisktextinfobrev}
}

% Closing page text
\newcommand{\closing}{
\nopagebreak
\addvspace{28pt minus 16pt}
\begin{minipage}{\textwidth}
\standardtext
\sloppy % no word-breaking
\raggedright % no word spacing
\raggedbottom % no line stretching to fit page
\frenchspacing % no double space after ended sentence
\vspace*{42pt}
\feltclosinggreeting
\par
\vspace*{4pt}
\feltclosinggreeting \\
\closingbehandlet
\feltclosingvedlegg
\label{\currentSectionName} %set label for the last page before attachments
\end{minipage}
\feltclosingvedlegg
\label{\currentSectionName} %set label for the last page before attachments
}

% attachmentList
\newenvironment{attachmentList}
{\par
\vspace{30pt}
\addvspace{42pt minus 20pt}
% enclose in brackets to prevent font from bleeding out to the rest of the letter.
% Should be the same as the secondary letter title, but without extra spacing after.
{\primaryFont\fontsize{\titletwotextsize}{0pt} \selectfont \textbf{\feltclosingvedleggprefix}}
\titletwo
\feltclosingvedleggprefix
\standardtext
\vspace{-12pt}
\begin{itemize}}
{\end{itemize}}

Expand All @@ -45,7 +78,6 @@

\newcommand{\doublesignature}[2]{
\setlength{\tabcolsep}{12pt}
\primaryFont \fontsize{\standardtextsize}{19.5pt} \selectfont
\begin{signaturestable}{colspec={X[l]X[l]}, column{1} = {rightsep = 10mm},column{2} = {leftsep = 10mm}}
#1 & #2 \\
\feltclosingsaksbehandlersuffix & \feltclosingsaksbehandlersuffix \\
Expand Down
89 changes: 0 additions & 89 deletions pdf-bygger/containerFiles/latex/content.tex

This file was deleted.

23 changes: 23 additions & 0 deletions pdf-bygger/containerFiles/latex/content/content.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% elements used to render the letter and attachment outline/content

% used to track whether the title1/title2 should add extra space above. Needs to be declared before other content
\newcommand{\previouselement}{title}

%starts with true because of main title
\newcommand{\setpreviouselement}[1]{
\renewcommand{\previouselement}{#1}
}

% Several elements use the \addvspace command. When two elements next to each other uses this kind of space, the highest value is chosen.
% For example:
% some paragraph text
% \addvspace{16pt}
% \addvspace{32pt}
% some title text
% in this case only 32 pt of vertical space is added between the elements.

\input{titles}
\input{paragraph}
\input{itemList}
\input{forms}
\input{table}
Loading

0 comments on commit eb27d92

Please sign in to comment.