Skip to content

Commit

Permalink
Workflow to sync changelog with Seqera docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vladsavelyev committed Nov 27, 2024
1 parent 2874187 commit b7d003f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/seqera_docs_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import re
from pathlib import Path
import subprocess
from typing import TypedDict


class ChangelogData(TypedDict):
version: str
date: str
contents: str


def latest_version_data(changelog_content: str) -> ChangelogData:
lines = []
for line in changelog_content.splitlines()[1:]:
if line.strip() == "":
break
lines.append(line)

print(lines[0])
match = re.match(r"^(.+) - (.+)$", lines[0])
version, date = match.groups()
print(f"version: {version}, date: {date}")
contents = "\n".join(lines[1:])

return {"version": version, "date": date, "contents": contents}


# Read CHANGELOG.md
changelog_path = Path("changelog.txt")
if not changelog_path.exists():
raise FileNotFoundError("changelog.txt not found")

# Create seqeralabs-docs directory if it doesn't exist
docs_dir = Path("seqeralabs-docs")
# Clone seqeralabs-docs repo if it doesn't exist
if not docs_dir.exists():
print("Cloning seqeralabs-docs repository...")
repo_url = "https://github.com/seqeralabs/docs.git"
try:
subprocess.run(["git", "clone", repo_url, str(docs_dir)], check=True)
except subprocess.CalledProcessError as e:
raise RuntimeError(f"Failed to clone repository: {e}")

# Extract latest version
with open(changelog_path) as f:
changelog_data: ChangelogData = latest_version_data(f.read())

# Create output directory
output_dir = docs_dir / "changelog" / "wave"
output_dir.mkdir(parents=True, exist_ok=True)

# Create output file
mdx_content: str = f"""---
title: Wave v{changelog_data['version']}
date: {changelog_data['date']}
tags: [wave]
---
{changelog_data['contents']}
"""
with open(output_path := output_dir / f"v{changelog_data['version']}.mdx", "w") as f:
f.write(mdx_content)

# Print version for GitHub Actions
print(f"::set-output name=version::{changelog_data['version']}")
41 changes: 41 additions & 0 deletions .github/workflows/seqera_docs_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Push changelog to Seqera Docs
on:
release:
types: [published]
workflow_dispatch:

jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Clone seqeralabs/docs
run: |
git clone https://github.com/seqeralabs/docs.git seqeralabs-docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Convert changelog
id: convert
run: python ${GITHUB_WORKSPACE}/.github/workflows/seqera_docs_changelog.py

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.SEQERALABS_DOCS_PAT }}
path: seqeralabs-docs
commit-message: "Changelog: Wave ${{ steps.convert.outputs.version }}"
title: "Changelog: Wave ${{ steps.convert.outputs.version }}"
body: |
This PR adds the changelog for Wave ${{ steps.convert.outputs.version }} to the Seqera documentation.
This is an automated PR created from the Wave repository.
branch: changelog-wave-${{ steps.convert.outputs.version }}
base: master
delete-branch: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ deployment-url.txt
tsp-output/
node_modules/
package-lock.json

# Seqera Docs clone
seqeralabs-docs

0 comments on commit b7d003f

Please sign in to comment.