Skip to content

Update README and LaTeX Build File #3

Update README and LaTeX Build File

Update README and LaTeX Build File #3

Workflow file for this run

name: Update README and LaTeX Build File with Python
on:
workflow_dispatch:
jobs:
update-files:
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.x'
- name: Update files with Python
run: |
python -c "\
import os, re
# Extract repository name
repo_name = os.getenv('GITHUB_REPOSITORY').split('/')[-1]
# Update README.md
with open('README.md', 'r+') as file:
lines = file.readlines()
lines[0] = f'# {repo_name}\\n'
for i, line in enumerate(lines):
if 'Actions Status' in line:
lines[i] = f'[![Actions Status](https://github.com/{os.getenv('GITHUB_REPOSITORY')}/workflows/CI/badge.svg)](https://github.com/{os.getenv('GITHUB_REPOSITORY')})\\n'
file.seek(0)
file.writelines(lines)
file.truncate()
# Update CMakeLists.txt with project name
with open('CMakeLists.txt', 'r+') as file:
content = file.read()
content = re.sub(r'project\(([^ ]*)', f'project({repo_name}', content, count=1)
# Assuming the LaTeX file is the first .tex file mentioned in CMakeLists.txt
content = re.sub(r'([^ ]*\.tex)', f'{repo_name}.tex', content, count=1)
file.seek(0)
file.write(content)
file.truncate()\
"
- name: Setup Git
run: |
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
- name: Commit and push if changed
run: |
git add README.md CMakeLists.txt
git diff --staged --quiet || git commit -m "Update README and LaTeX build configuration with correct repository name"
git push