Skip to content

chore(ci): regenerate all versioned examples #13

chore(ci): regenerate all versioned examples

chore(ci): regenerate all versioned examples #13

name: Update Examples & Versions
on:
push:
branches:
- main
tags:
- 'v*'
permissions:
contents: write
jobs:
update-examples:
runs-on: ubuntu-latest
steps:
- name: Checkout DiscordTranscript
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Process Examples Generation
run: |
mkdir -p examples/versions
# 1. Générer le rendu de preview actuel
python examples/generate_sample.py
# 2. Régénérer toutes les archives de version à partir de leur tag Git avec le script d'exemple actuel
python -c "
import subprocess, os, sys, json
tags_output = subprocess.check_output(['git', 'tag', '-l'], text=True).strip().splitlines()
tags = [t for t in tags_output if t.startswith('v') and '-' not in t]
with open('examples/generate_sample.py', 'r', encoding='utf-8') as f:
sample_script = f.read()
results = {}
for tag in tags:
print(f'Régénération de la version {tag}...')
subprocess.run(['git', 'checkout', tag, '-f'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run([sys.executable, '-m', 'pip', 'install', '-e', '.', '--no-deps'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
script_content = sample_script.replace(', language=\"fr\"', '')
sample_path = 'examples/generate_sample.py' if os.path.exists('examples/generate_sample.py') else 'generate_sample.py'
with open(sample_path, 'w', encoding='utf-8') as f:
f.write(script_content)
proc = subprocess.run([sys.executable, sample_path], capture_output=True, text=True)
if os.path.exists('examples/test_render.html'):
with open('examples/test_render.html', 'r', encoding='utf-8') as f:
results[tag] = f.read()
elif os.path.exists('test_render.html'):
with open('test_render.html', 'r', encoding='utf-8') as f:
results[tag] = f.read()
os.remove('test_render.html')
subprocess.run(['git', 'checkout', 'main', '-f'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run([sys.executable, '-m', 'pip', 'install', '-e', '.', '--no-deps'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
vdir = 'examples/versions'
os.makedirs(vdir, exist_ok=True)
for tag, content in results.items():
dest = f'{vdir}/{tag}.html'
with open(dest, 'w', encoding='utf-8') as f:
f.write(content)
data = [
{
'id': 'preview',
'name': 'Preview Build',
'url': 'https://raw.githubusercontent.com/Xougui/DiscordTranscript/main/examples/test_render.html'
}
]
files = sorted([f for f in os.listdir(vdir) if f.endswith('.html')], reverse=True)
for idx, filename in enumerate(files):
ver_id = filename[:-5]
raw_url = f'https://raw.githubusercontent.com/Xougui/DiscordTranscript/main/examples/versions/{filename}'
data.append({
'id': ver_id,
'name': f'Version Stable {ver_id}',
'url': raw_url,
'isDefault': idx == 0
})
with open(os.path.join(vdir, 'versions.json'), 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
"
- name: Commit & Push changes to DiscordTranscript
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout main || git checkout -b main
git add examples/test_render.html examples/versions/
if ! git diff --staged --quiet; then
git commit -m "auto: update preview (test_render.html) and version archives [skip ci]"
git push origin main
fi