From 7d434a9e7eaf466eb3726ea21870afb76079cdee Mon Sep 17 00:00:00 2001 From: Darius Peters <38152878+dariusptrs@users.noreply.github.com> Date: Sat, 6 Jul 2024 22:44:57 +0200 Subject: [PATCH] update template --- .devcontainer/devcontainer.json | 12 +++ .github/ISSUE_TEMPLATE/config.yml | 5 ++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++ .github/ISSUE_TEMPLATE/feature_request.yaml | 45 +++++++++++ .github/ISSUE_TEMPLATE/inhaltlicher_fehler.md | 14 ++++ .../ISSUE_TEMPLATE/inhaltlicher_fehler.yaml | 25 +++++++ .github/pull_request_template.md | 14 ++++ .github/workflows/ci.yml | 60 +++++++++++++++ .github/workflows/update.yml | 38 ++++++++++ .gitignore | 6 +- .travis.yml | 32 -------- AuD.tex | 74 ++++++++++++++++-- scripts/__init__.py | 0 scripts/requirements.txt | 2 + scripts/tests/__init__.py | 0 scripts/tests/test_update_files.py | 75 +++++++++++++++++++ scripts/update_files.py | 42 +++++++++++ write-gitid.sh | 11 ++- 18 files changed, 435 insertions(+), 40 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yaml create mode 100644 .github/ISSUE_TEMPLATE/inhaltlicher_fehler.md create mode 100644 .github/ISSUE_TEMPLATE/inhaltlicher_fehler.yaml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/update.yml delete mode 100644 .travis.yml create mode 100644 scripts/__init__.py create mode 100644 scripts/requirements.txt create mode 100644 scripts/tests/__init__.py create mode 100644 scripts/tests/test_update_files.py create mode 100644 scripts/update_files.py diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..7d41fcb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "LaTeX4Ei Devcontainer", + "image": "makeappdev/uselatex:latest", + "extensions": [ + "eamodio.gitlens", + "James-Yu.latex-workshop", + "ms-azuretools.vscode-docker", + "ms-vscode-remote.vscode-remote-extensionpack", + "ms-vscode.cmake-tools", + "twxs.cmake" + ], +} diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..a3e749e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: 🔍 Search for existing issues first. + url: https://github.com/latex4ei/Allgemein/issues + about: Please search to see if an issue already exists, either in this repo or our common issue in https://github.com/latex4ei/Allgemein/issues diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..11fc491 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml new file mode 100644 index 0000000..d61d2fd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -0,0 +1,45 @@ +name: Feature request +description: Suggest an idea for this project +labels: [enhancement] +assignees: [] + +body: +- type: markdown + attributes: + value: | + **Is your feature request related to a problem? Please describe.** +- type: textarea + id: problem-description + attributes: + label: Problem Description + description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +- type: markdown + attributes: + value: | + **Describe the solution you'd like** +- type: textarea + id: solution-description + attributes: + label: Solution Description + description: A clear and concise description of what you want to happen. + +- type: markdown + attributes: + value: | + **Describe alternatives you've considered** +- type: textarea + id: alternatives-description + attributes: + label: Alternatives Description + description: A clear and concise description of any alternative solutions or features you've considered. + +- type: markdown + attributes: + value: | + **Additional context** +- type: textarea + id: additional-context + attributes: + label: Additional Context + description: Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/inhaltlicher_fehler.md b/.github/ISSUE_TEMPLATE/inhaltlicher_fehler.md new file mode 100644 index 0000000..1152b64 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/inhaltlicher_fehler.md @@ -0,0 +1,14 @@ +--- +name: Inhaltlicher Fehler +about: Hilf uns Fehler zu Verbessern +title: '' +labels: bug +assignees: '' + +--- + +**Fehlerbeschreibung** +Beschreibe hier den Fehler + +**Referenz** +Wenn möglich immer eine Referenz zum Skript o.ä. angeben oder als Screenshot mit einfügen. diff --git a/.github/ISSUE_TEMPLATE/inhaltlicher_fehler.yaml b/.github/ISSUE_TEMPLATE/inhaltlicher_fehler.yaml new file mode 100644 index 0000000..95b8d1e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/inhaltlicher_fehler.yaml @@ -0,0 +1,25 @@ +name: Inhaltlicher Fehler +description: Hilf uns Fehler zu Verbessern +labels: [bug] +assignees: [] + +body: +- type: markdown + attributes: + value: | + **Fehlerbeschreibung** +- type: textarea + id: error-description + attributes: + label: Fehlerbeschreibung + description: Beschreibe hier den Fehler + +- type: markdown + attributes: + value: | + **Referenz** +- type: textarea + id: reference + attributes: + label: Referenz + description: Wenn möglich immer eine Referenz zum Skript o.ä. angeben oder als Screenshot mit einfügen. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..d61ffcf --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,14 @@ +--- +name: Vorschlag Fehlerkorrektur +about: Du hast einen Fehler gefunden und willst ihn korrigieren +title: '' +labels: bug +assignees: '' + +--- + +**Fehlerbeschreibung** +Beschreibe hier den Fehler + +**Referenz** +Wenn möglich immer eine Referenz zum Skript o.ä. angeben oder als Screenshot mit einfügen. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ff9e20c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,60 @@ +name: CI + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12.2' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r scripts/requirements.txt + - name: Run pytest + run: pytest + + build: + runs-on: ubuntu-latest + container: makeappdev/uselatex:latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Configure Git safe directory with GITHUB_WORKSPACE + run: git config --global --add safe.directory $GITHUB_WORKSPACE + + - name: Build + run: | + cmake --version; pdflatex --version + mkdir -p build && cd build + cmake .. + make + + - name: Prepare Deployment + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' + run: | + mkdir -p export + echo "# This branch is for deployment only" >> export/README.md + cp build/*.pdf export + cp build/git.id export + + - name: Deploy + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + branch: gh-pages + folder: export + single-commit: true + silent: true diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..9fe823a --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,38 @@ +name: Update README and LaTeX Build File + +on: + workflow_dispatch: + +jobs: + update-and-create-pr: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12.2' + + - name: Run update script + run: python scripts/update_files.py + + - name: Configure Git + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Commit changes to a new branch + run: | + git checkout -b changes/${{ github.run_id }} + git add . + git commit -m "Apply automated updates" + git push -u origin changes/${{ github.run_id }} + + - name: Create Pull Request + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr create --base main --head changes/${{ github.run_id }} --title "Specify project URLs and CMake project" --body "Please review the changes applied by the automated script." diff --git a/.gitignore b/.gitignore index 2b3fe9e..827bcb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ build/ -AuD.pdf +/*.pdf ## Core latex/pdflatex auxiliary files: *.aux @@ -111,4 +111,6 @@ sympy-plots-for-*.tex/ # xindy *.xdy -StochastischeSignale.pdf +git.id +*.DS_Store +*.pyc diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7dd564a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -dist: xenial -sudo: required - -services: - - docker - -before_install: -- docker pull makeappdev/uselatex -- docker run -it -d --name uselatex makeappdev/uselatex bash -- docker ps -a -- docker exec uselatex bash -c "cmake --version; pdflatex --version" -- docker cp ./. uselatex:/ - -script: -- docker exec uselatex bash -c "mkdir -p build && cd build && cmake ..; make" -- mkdir -p export -- mkdir -p tmp -- echo "# This branch is for deployment only" >> export/README.md -- docker cp uselatex:build/. tmp -- cp tmp/*.pdf export -- cp tmp/git.id export - -deploy: - provider: pages - skip-cleanup: true - github-token: $GITHUB_TOKEN # Set in travis-ci.org dashboard, marked secure - local-dir: export - on: - branch: master - -notifications: - email: false diff --git a/AuD.tex b/AuD.tex index 0ce0d2c..bde53ae 100644 --- a/AuD.tex +++ b/AuD.tex @@ -5,6 +5,70 @@ \usepackage{multirow} \usepackage{latexnew} + %UPDATE WITHOUT CLASS CHANGE +% ---------------------------------------------------------------------- + +% LastPage +\usepackage{lastpage} + +% Allow hyperlinks + \RequirePackage[pagebackref=true,pdfpagelabels]{hyperref} + +% Colors + \RequirePackage{latex4ei/latex4ei_colors} + \colorlet{col_link}{tum_blue_dark} + \hypersetup{ + colorlinks=true, + linkcolor=col_link, + urlcolor=col_link, + citecolor=col_link, +} + +% set pdfoptions + \AtBeginDocument{ + \hypersetup{ + pdftitle={Analysis 1}, + pdfauthor={Lukas Kompatscher}, + pdfcreator={LaTeX4EI template (www.latex4ei.de)}, + pdfkeywords={latex4ei} + } + } + +% Date with git commit number + \newcommand{\themydate}{\today} % Default URL placeholder + \newcommand{\mydate}[1]{\renewcommand{\themydate}{#1}} + +% Header and Footer + \RequirePackage{fancyhdr} + + \pagestyle{fancy} + \fancyhf{} + + \AtBeginDocument{ + \IfFileExists{git.id}{\input{git.id}}{} + \ifdefined\GitNiceDate\mydate{\GitNiceDate\ (git \GitRevision)}\fi + \ifdefined\GitIssuesURL + \ifdefined\setissueslinkurl + \setissueslinkurl{\GitIssuesURL} % Set the actual URL + \fi + \fi + } + +% Define Email + \providecommand{\email}[1]{\href{mailto:#1}{\nolinkurl{#1}}} + +% + \fancyfoot[C]{von Lukas Kompatscher\ -- Mail: \email{lukas.kompatscher@tum.de}} + \fancyfoot[R]{Stand: \themydate \qquad \thepage/\pageref{LastPage}} + \fancyfoot[L]{Homepage: \url{www.latex4ei.de} -- Fehler bitte \emph{sofort} \href{\issueslinkurl}{melden}.} + + \renewcommand{\headrulewidth}{0.0pt} %obere Linie ausblenden + \renewcommand{\footrulewidth}{0.1pt} %obere Linie ausblenden + + \newcommand{\issueslinkurl}{https://github.com/latex4ei/Allgemein/issues} % Default URL placeholder + \newcommand{\setissueslinkurl}[1]{\renewcommand{\issueslinkurl}{#1}} +% ---------------------------------------------------------------------- + \renewcommand{\t}{\texttt} \newcommand{\f}{{\bfseries}} @@ -101,7 +165,7 @@ \subsubsection{Greedy} Schrittweise Erweiterung der Lösung ausgehend von Startlösung unter Berücksichtigung des bestmöglichsten Schrittes\\ \textbf{Beispiele:} Berechnung Wechselgeld, Glasfasernetz \subsubsection{Brute Force} -Erzeuge alle in Frage kommenden Kandidaten und suche besten aus\\ +Erzeuge alle in Frage kommenden Kandidaten und suche besten aus \subsubsection{Backtracing} Systematische Suchtechnik, um Lösungsraum vollständig abzuarbeiten\\ \textbf{Beispiele:} Labyrinth (mit frühem Abbrechen von falschen Lösungspfaden) @@ -492,7 +556,7 @@ \section{Graphen} \textbf{Ungerichteter Graph:} Richtung der Kante spielt keine Rolle\\ \textbf{Gerichteter Graph:} Richtung der Kante spielt eine Rolle, Schleifen möglich $(u, u)$ mit $u \in V$\\ -\textbf{DAG:} Directed acyclic graph.\\ +\textbf{DAG:} Directed acyclic graph. \subsection{Eigenschaften} $v$ \textbf{adjazent} zu $u$: $(u,v) \in E$ bzw. $\{u, v\} \in E$ für $u, v \in V$\\ @@ -501,7 +565,7 @@ \subsection{Eigenschaften} Pfad: Folge von miteinander verbundenen Knoten\\ einfacher Pfad: alle Knoten sind paarweise verschieden\\ Zyklus: Pfad mit gleichem Anfangs- sowie Endknoten\\ -Kreis: einfacher Pfad mit gleichem Anfangs- sowie Endknoten\\ +Kreis: einfacher Pfad mit gleichem Anfangs- sowie Endknoten \subsubsection{Gerichteter Graph} Anzahl der eintretenden Kanten in $v$ heißt Eingangsgrad: $indeg(v)$\\ @@ -611,7 +675,7 @@ \subsubsection{Ungerichteter Graph} 10. \quad for \{u,w\} $\in$ V $\times$ V\\ 11. \quad \quad if (d[u,w] $>$ d[u,v] + d[v,w])\\ 12. \quad \quad \quad d(u,w) = d(u,v) + d(v,w);\\ - 13. \quad \quad \quad pred(u,w) = pred(v,w);\\ + 13. \quad \quad \quad pred(u,w) = pred(v,w); }} \subsection{Bäume} @@ -665,7 +729,7 @@ \subsubsection{AVL-Baum} 11\ \quad else\\ 12\ \qquad v->left = LeftRotate(v->left)\\ 13\ \qquad v = RightRotate(v) // Doppelrotation\\ -14\ return v\\ +14\ return v } \subsubsection{Traversierung} diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..fe79a98 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,2 @@ +pyfakefs==5.3.5 +pytest==8.1.1 diff --git a/scripts/tests/__init__.py b/scripts/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/tests/test_update_files.py b/scripts/tests/test_update_files.py new file mode 100644 index 0000000..efbc556 --- /dev/null +++ b/scripts/tests/test_update_files.py @@ -0,0 +1,75 @@ +import pytest +from scripts.update_files import check_tex_file_exists, update_readme_content, update_cmake_content +from pathlib import Path +import os + +@pytest.fixture +def fake_base_path(fs): + """Fixture to create a base path and mock environment variable.""" + base_path = Path("/test/project") + fs.create_dir(base_path) + os.environ['GITHUB_REPOSITORY'] = 'user/correct_title' + return base_path + +def test_check_tex_file_exists__file_does_not_exist__should_raise(fake_base_path, fs): + repo_name = "correct_title" + fs.create_file(fake_base_path / f"{repo_name}.tex") + check_tex_file_exists(repo_name, fake_base_path) + + with pytest.raises(FileNotFoundError): + check_tex_file_exists("nonexistent_repo", Path(fake_base_path)) + +def test_update_readme_content(fake_base_path, fs): + initial_readme_content = """ + # WrongTitle + Some content in the README file. + [![Actions Status](https://github.com/latex4ei/WrongCheatsheetTemplate/workflows/CI/badge.svg)](https://github.com/latex4ei/WrongCheatsheetTemplate) + ## Section + More details here. + """.strip() + fs.create_file(fake_base_path / "README.md", contents=initial_readme_content) + repo_name = "correct_title" + github_repository = 'user/correct_title' + + updated_content = update_readme_content(initial_readme_content, repo_name, github_repository) + + expected_content = """ + # correct_title + Some content in the README file. + [![Actions Status](https://github.com/user/correct_title/workflows/CI/badge.svg)](https://github.com/user/correct_title) + ## Section + More details here. + """.strip() + assert updated_content == expected_content, "README.md content was not updated correctly." + +def test_update_cmake_content(fake_base_path, fs): + initial_cmake_content = """ + cmake_minimum_required(VERSION 3.12) + project(WrongProjectName NONE) + # Add the main LaTeX document + add_latex_document( + CheatsheetTemplate.tex + AnotherDoc.tex + FORCE_PDF + IMAGE_DIRS img + DEPENDS writegitid + ) + """.strip() + fs.create_file(fake_base_path / "CMakeLists.txt", contents=initial_cmake_content) + repo_name = "correct_title" + + updated_content = update_cmake_content(initial_cmake_content, repo_name) + + expected_content = """ + cmake_minimum_required(VERSION 3.12) + project(correct_title NONE) + # Add the main LaTeX document + add_latex_document( + correct_title.tex + AnotherDoc.tex + FORCE_PDF + IMAGE_DIRS img + DEPENDS writegitid + ) + """.strip() + assert updated_content == expected_content, "CMakeLists.txt content was not updated correctly." diff --git a/scripts/update_files.py b/scripts/update_files.py new file mode 100644 index 0000000..ab0c3e1 --- /dev/null +++ b/scripts/update_files.py @@ -0,0 +1,42 @@ +from pathlib import Path +import re +import os +import sys + +def check_tex_file_exists(repo_name: str, base_path: Path): + """Check if a .tex file with the same name as the repository exists.""" + tex_file_path = base_path / f"{repo_name}.tex" + if not tex_file_path.exists(): + msg = f"No .tex file found with the name {tex_file_path.name}. File name must match repo name." + raise FileNotFoundError(msg) + +def update_readme_content(content: str, repo_name: str, github_repository: str) -> str: + """Updates the README.md content.""" + content = re.sub(r'^# .+', f'# {repo_name}', content, count=1, flags=re.MULTILINE) + actions_status_line = f'[![Actions Status](https://github.com/{github_repository}/workflows/CI/badge.svg)](https://github.com/{github_repository})' + return re.sub(r'\[!\[Actions Status\].*', actions_status_line, content) + +def update_cmake_content(content: str, repo_name: str) -> str: + """Updates the CMakeLists.txt content.""" + content = re.sub(r'project\(([^ ]*)', f'project({repo_name}', content, count=1) + return re.sub(r'^( *)[^\s#].*?\.tex', r'\1' + f'{repo_name}.tex', content, flags=re.MULTILINE, count=1) + +def main(github_repository: str): + repo_name = Path(github_repository).name + base_path = Path(__file__).parent.parent + + check_tex_file_exists(repo_name, base_path) + + readme_path = base_path / 'README.md' + cmake_path = base_path / 'CMakeLists.txt' + + readme_content = readme_path.read_text() + updated_readme_content = update_readme_content(readme_content, repo_name, github_repository) + readme_path.write_text(updated_readme_content) + + cmake_content = cmake_path.read_text() + updated_cmake_content = update_cmake_content(cmake_content, repo_name) + cmake_path.write_text(updated_cmake_content) + +if __name__ == "__main__": + main(os.getenv('GITHUB_REPOSITORY')) diff --git a/write-gitid.sh b/write-gitid.sh index 85d217d..b441cae 100755 --- a/write-gitid.sh +++ b/write-gitid.sh @@ -11,4 +11,13 @@ fi GITREV=$(git rev-list HEAD --count) echo "\\def\\GitRevision{$GITREV}"> git.id -git show -s --format=%ci | xargs -I var_d $DATEBIN -d "var_d" +\\def\\GitNiceDate{%-d.\ %B\ %Y\ um\ %H:%M\ Uhr} >> git.id +git show -s --format=%ci | xargs -I var_d $DATEBIN -d "var_d" +\\def\\GitNiceDate{%-d.\ %B\ %Y} >> git.id + +# Get the repository's remote URL +REPO_URL=$(git remote get-url origin) + +# Convert SSH URL to HTTPS URL and append /issues for the issues page +# This also ensures it works for URLs ending with .git and without +ISSUES_URL=$(echo $REPO_URL | sed -e 's/^git@github\.com:/https:\/\/github\.com\//' -e 's/\.git$//' -e 's/$/\/issues/') + +echo "\\def\\GitIssuesURL{$ISSUES_URL}" >> git.id