Skip to content

Commit

Permalink
automate build
Browse files Browse the repository at this point in the history
  • Loading branch information
Rdeisenroth committed Aug 12, 2023
1 parent 81017bc commit fc06af2
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"name": "latex",
"image": "ghcr.io/rdeisenroth/rubos-tuda-template:latest",
"customizations": {
"vscode": {
"extensions": [
"james-yu.latex-workshop",
// Git
"eamodio.gitlens",
// Other helpers
"shardulm94.trailing-spaces",
"stkb.rewrap", // rewrap comments after n characters on one line
// Other
"vscode-icons-team.vscode-icons",
"draivin.hsnips"
],
"settings": {
// General settings
"files.eol": "\n",
// Latex settings
"latex-workshop.linting.chktex.enabled": true,
"latex-workshop.linting.chktex.exec.path": "chktex",
"latex-workshop.latex.clean.subfolder.enabled": true,
"latex-workshop.latex.autoClean.run": "onBuilt",
"editor.formatOnSave": true,
"files.associations": {
"*.tex": "latex",
"*.sty": "latex-expl3",
"*.cls": "latex-expl3",
"*.def": "latex",
"*.aux": "latex",
"*.toc": "latex",
"*.pygstyle": "latex",
"*.pygtex": "latex"
},
"latex-workshop.latexindent.path": "latexindent",
"latex-workshop.latexindent.args": [
"-c",
"%DIR%/",
"%TMPFILE%",
"-y=defaultIndent: '%INDENT%'"
],
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"--shell-escape",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-lualatex",
//"-pdflatex",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {
//"DARK_MODE": "1"
}
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"--shell-escape",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "lualatex",
"command": "lualatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-luatex",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
}
}
}
}
70 changes: 70 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# LaTeX document build workflow

name: build

# Controls when the workflow will run
on:
# Triggers the workflow on push events for all branches
push:
branches:
- main
- master
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
# The type of runner that the job will run on
runs-on: [self-hosted]
# The docker image to use for the container
container:
image: ghcr.io/rdeisenroth/rubos-tuda-template:latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# 1. Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Set up Git repository
uses: actions/checkout@v3

# Link texmf folder to the current texmf home
- name: Link texmf folder to the current texmf home
run: |
ln -s /root/texmf $(kpsewhich -var-value=TEXMFHOME)
texhash --verbose
# 2. Build the document
- name: "Build the document"
run: |
CI_RUN=1 make -j $(nproc)
mv build/*.pdf .
# 3. Upload artifacts to GitHub
- name: Upload artifacts to GitHub
#if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
with:
name: PDF
path: "*.pdf"
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`

# 4. Get Date
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d-%H-%M-%S.%N')"

# 5. create a release
- name: Create a release
if: ${{ github.ref == 'refs/heads/master' && !env.ACT && github.repository == 'Rdeisenroth/AuD-Zusammenfassung' }}
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: snapshot-${{ steps.date.outputs.date }}
name: snapshot-release-${{ steps.date.outputs.date }}
files: "*.pdf"
fail_on_unmatched_files: true
draft: false
prerelease: false
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

OUT_DIR := build/
TOPTARGETS := clean all

define compile_latex_with_jobname_and_env
cd $(4) && $(3) latexmk --shell-escape -synctex=1 -interaction=nonstopmode -file-line-error -lualatex -jobname=$(2) "$(1)"
endef

define build_latex_with_jobname_and_env
$(eval DIR := $(dir $(1)))
$(eval FILE := $(notdir $(1)))
@echo -e "\e[1;32mCompiling \"$(FILE)\" in \"$(DIR)\" with jobname \"$(2)\"$<\e[0m"
@$(call compile_latex_with_jobname_and_env,$(FILE),$(2),$(3),$(DIR))
@echo -e "\e[1;32mSuccessfully compiled \"$(FILE)\" in \"$(DIR)\" with jobname \"$(2)\"$<\e[0m"
@mkdir -p $(OUT_DIR)
@mv $(DIR)/$(2).pdf $(OUT_DIR)/
endef

FILES := $(wildcard *.tex)

all:
$(MAKE) clean
$(MAKE) compile

$(FILES:.tex=.tex.regular):
$(eval FILE := $(patsubst %.tex.regular,%.tex,$@))
$(call build_latex_with_jobname_and_env,$(FILE),$(patsubst %.tex,%,$(FILE)),)

$(FILES:.tex=.tex.darkmode):
$(eval FILE := $(patsubst %.tex.darkmode,%.tex,$@))
$(call build_latex_with_jobname_and_env,$(FILE),$(patsubst %.tex,%-darkmode,$(FILE)),DARK_MODE=1)

compile: $(FILES:.tex=.tex.regular) $(FILES:.tex=.tex.darkmode)
@echo -e "\e[1;42mAll Done. PDFs can be found in \"$(OUT_DIR)\"\e[0m"

clean:
@echo -e "\e[1;34mCleaning up leftover build files...$<\e[0m"
@latexmk -C -f
@rm -f options.cfg
@rm -f *.pdf
@rm -f *.aux
@rm -f *.fdb_latexmk
@rm -f *.fls
@rm -f *.len
@rm -f *.listing
@rm -f *.log
@rm -f *.out
@rm -f *.synctex.gz
@rm -f *.toc
@rm -f *.nav
@rm -f *.snm
@rm -f *.vrb
@rm -f *.idx
@rm -f *.ilg
@rm -f *.ind
@rm -f *.bbl
@rm -f *.blg
@rm -f *.bak[0-9]*
@rm -rf _minted-*
@rm -rf svg-inkscape
@echo -e "\e[1;44mDone cleaning up leftover build files.$<\e[0m"

cleanBuild:
@echo -e "\e[1;34mCleaning up build directory...$<\e[0m"
@rm -rf build
@echo -e "\e[1;44mDone cleaning up build directory.$<\e[0m"

cleanAll: clean cleanBuild

.PHONY: $(TOPTARGETS) $(FILES)

0 comments on commit fc06af2

Please sign in to comment.