Skip to content

Commit a5127f8

Browse files
committed
feat: Add release automation kit (Issue #122)
- Add generate_release_post.py script - Add GitHub Actions workflow template - Add documentation for usage
1 parent 518cf1f commit a5127f8

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

automation/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Release Automation Kit
2+
3+
This directory contains tools to automate the posting of release news to the `aboutcode.org` website.
4+
5+
## Components
6+
7+
1. **`generate_release_post.py`**: A Python script that generates a formatted ReStructuredText (RST) file for the news section.
8+
2. **`release-workflow-template.yml`**: A GitHub Actions workflow template that can be used in AboutCode projects (like ScanCode, VulnerableCode) to automatically trigger this process on release.
9+
10+
## Usage
11+
12+
### Local Usage
13+
14+
You can use the script locally to generate a news file:
15+
16+
```bash
17+
python3 generate_release_post.py \
18+
--project "ScanCode Toolkit" \
19+
--version "32.0.1" \
20+
--url "https://github.com/aboutcode-org/scancode-toolkit/releases/tag/v32.0.1" \
21+
--output-dir "output"
22+
```
23+
24+
This will create a file like `2023-10-27-scancode-toolkit-v32.0.1-released.rst` in the output directory.
25+
26+
### GitHub Actions Integration
27+
28+
To automate this for a project:
29+
30+
1. Copy `release-workflow-template.yml` to the project's `.github/workflows/` directory.
31+
2. Update the `PROJECT_NAME` environment variable in the workflow file.
32+
3. Configure the `create-pull-request` step to point to the correct `aboutcode.org` source repository (if different from the current one) and ensure a `BOT_TOKEN` with sufficient permissions is available in the repository secrets.
33+
34+
## Requirements
35+
36+
- Python 3.6+
37+
- No external dependencies for the script (uses standard library).
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Release Post Generator for AboutCode.org
4+
5+
This script generates a news post file for a new project release.
6+
It is designed to be used in GitHub Actions workflows.
7+
8+
Usage:
9+
python3 generate_release_post.py --project "Project Name" --version "1.0.0" --url "https://..." --date "2023-10-27" --output-dir "news"
10+
"""
11+
12+
import argparse
13+
import os
14+
import sys
15+
from datetime import datetime
16+
17+
TEMPLATE = """
18+
{title}
19+
{title_underline}
20+
21+
AboutCode is happy to announce the release of **{project} v{version}**!
22+
23+
Check out the full release notes and download it here:
24+
{url}
25+
26+
Visit the project homepage:
27+
{homepage}
28+
29+
-- The AboutCode Team
30+
"""
31+
32+
PROJECT_HOMEPAGES = {
33+
"ScanCode Toolkit": "https://github.com/aboutcode-org/scancode-toolkit",
34+
"ScanCode.io": "https://github.com/aboutcode-org/scancode.io",
35+
"VulnerableCode": "https://github.com/aboutcode-org/vulnerablecode",
36+
"DejaCode": "https://github.com/aboutcode-org/dejacode",
37+
"PURLDB": "https://github.com/aboutcode-org/purldb",
38+
}
39+
40+
def generate_post(project, version, url, date_str, output_dir):
41+
"""Generates the release post file."""
42+
43+
# Format the title
44+
title = f"{project} v{version} released"
45+
title_underline = "=" * len(title)
46+
47+
# Get homepage or default to github organization
48+
homepage = PROJECT_HOMEPAGES.get(project, "https://github.com/aboutcode-org")
49+
50+
content = TEMPLATE.format(
51+
title=title,
52+
title_underline=title_underline,
53+
project=project,
54+
version=version,
55+
url=url,
56+
homepage=homepage
57+
).strip()
58+
59+
# Create filename: YYYY-MM-DD-project-vVERSION-released.rst (Sphinx uses RST usually)
60+
# Using RST as AboutCode docs are RST-heavy
61+
safe_project_name = project.lower().replace(" ", "-").replace(".", "")
62+
filename = f"{date_str}-{safe_project_name}-v{version}-released.rst"
63+
64+
if output_dir:
65+
os.makedirs(output_dir, exist_ok=True)
66+
filepath = os.path.join(output_dir, filename)
67+
else:
68+
filepath = filename
69+
70+
with open(filepath, "w", encoding="utf-8") as f:
71+
f.write(content)
72+
f.write("\n")
73+
74+
print(f"Successfully generated release post: {filepath}")
75+
return filepath
76+
77+
if __name__ == "__main__":
78+
parser = argparse.ArgumentParser(description="Generate AboutCode release post")
79+
parser.add_argument("--project", required=True, help="Project name (e.g., ScanCode.io)")
80+
parser.add_argument("--version", required=True, help="Release version (e.g., 32.0.1)")
81+
parser.add_argument("--url", required=True, help="Release URL")
82+
parser.add_argument("--date", help="Date in YYYY-MM-DD format (default: today)")
83+
parser.add_argument("--output-dir", default=".", help="Directory to save the file")
84+
85+
args = parser.parse_args()
86+
87+
date_str = args.date if args.date else datetime.now().strftime("%Y-%m-%d")
88+
89+
try:
90+
generate_post(args.project, args.version, args.url, date_str, args.output_dir)
91+
except Exception as e:
92+
print(f"Error: {e}", file=sys.stderr)
93+
sys.exit(1)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Publish Release News
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
create-news-post:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Code
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: '3.x'
17+
18+
- name: Get Release Info
19+
id: release_info
20+
run: |
21+
echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
22+
echo "URL=${{ github.event.release.html_url }}" >> $GITHUB_ENV
23+
echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
24+
# Extract project name from repo name or set manually
25+
echo "PROJECT_NAME=ScanCode Toolkit" >> $GITHUB_ENV # TODO: Customize this per project
26+
27+
- name: Download Generator Script
28+
run: |
29+
# Downloads the generator script from the main AboutCode repo
30+
curl -O https://raw.githubusercontent.com/aboutcode-org/aboutcode/main/automation/generate_release_post.py
31+
32+
- name: Generate Post
33+
run: |
34+
python3 generate_release_post.py \
35+
--project "${{ env.PROJECT_NAME }}" \
36+
--version "${{ env.VERSION }}" \
37+
--url "${{ env.URL }}" \
38+
--date "${{ env.DATE }}" \
39+
--output-dir "news"
40+
41+
- name: Create Pull Request to Website Repo
42+
# Note: This step assumes you are pushing to the website repo.
43+
# AboutCode maintainers need to configure the target repository and token.
44+
# This uses peter-evans/create-pull-request as an example.
45+
uses: peter-evans/create-pull-request@v6
46+
with:
47+
token: ${{ secrets.BOT_TOKEN }} # Ensure this secret is set
48+
path: news
49+
commit-message: "docs: add release news for ${{ env.PROJECT_NAME }} ${{ env.VERSION }}"
50+
title: "News: ${{ env.PROJECT_NAME }} ${{ env.VERSION }} Released"
51+
body: "Automated release post for ${{ env.PROJECT_NAME }} ${{ env.VERSION }}"
52+
branch: "news/${{ env.PROJECT_NAME }}-${{ env.VERSION }}"
53+
base: main

0 commit comments

Comments
 (0)