Add CHANGELOG to container.
This commit is contained in:
44
.github/workflows/build.yml
vendored
44
.github/workflows/build.yml
vendored
@@ -55,7 +55,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
php: [ 8.4 ]
|
||||
php: [8.4]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -144,6 +144,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Ensure all commit history is available
|
||||
|
||||
- uses: bahmutov/npm-install@v1
|
||||
with:
|
||||
@@ -163,6 +165,36 @@ jobs:
|
||||
with_date: "true"
|
||||
with_branch: "true"
|
||||
|
||||
- name: Version tag
|
||||
uses: arabcoders/action-python-autotagger@master
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
repo_name: arabcoders/watchstate
|
||||
path: config/config.php
|
||||
regex: "'version'\\s\\=\\>\\s\\'(.+?)\\'\\,"
|
||||
|
||||
- name: Determine current branch
|
||||
id: branch
|
||||
run: |
|
||||
echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> $GITHUB_ENV
|
||||
|
||||
- name: Fetch all tags
|
||||
run: git fetch --tags
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.x"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install gitpython
|
||||
|
||||
- name: Generate Changelog
|
||||
run: |
|
||||
python container/make_changelog.py . --changelog_path ./CHANGELOG.md --branch_name $BRANCH_NAME
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
@@ -208,14 +240,6 @@ jobs:
|
||||
cache-from: type=gha, scope=${{ github.workflow }}
|
||||
cache-to: type=gha, scope=${{ github.workflow }}
|
||||
|
||||
- name: Version tag
|
||||
uses: arabcoders/action-python-autotagger@master
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
repo_name: arabcoders/watchstate
|
||||
path: config/config.php
|
||||
regex: "'version'\\s\\=\\>\\s\\'(.+?)\\'\\,"
|
||||
|
||||
dockerhub-sync-readme:
|
||||
runs-on: ubuntu-latest
|
||||
if: (github.event_name == 'push' && endsWith(github.ref, github.event.repository.default_branch)) || (github.event_name == 'workflow_dispatch' && github.event.inputs.update_readme == 'true')
|
||||
@@ -242,7 +266,7 @@ jobs:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # so we can see all tags + full history
|
||||
fetch-depth: 0 # so we can see all tags + full history
|
||||
|
||||
- name: Determine current branch
|
||||
id: branch
|
||||
|
||||
3
CHANGELOG.md
Normal file
3
CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# CHANGELOG
|
||||
|
||||
This file will be populated automatically via github action for containers.
|
||||
69
container/make_changelog.py
Normal file
69
container/make_changelog.py
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import git
|
||||
import argparse
|
||||
from datetime import datetime, timezone
|
||||
|
||||
def get_tags(repo, branch_name):
|
||||
"""Returns sorted tags by date, filtered by branch name."""
|
||||
tags = [tag for tag in repo.tags if tag.name.startswith(branch_name)]
|
||||
tags = sorted(tags, key=lambda t: t.commit.committed_datetime, reverse=True)
|
||||
return tags
|
||||
|
||||
def get_commits_between(repo, start_commit, end_commit):
|
||||
"""Get commit messages between two commits (excluding merges)."""
|
||||
commits = list(repo.iter_commits(f"{start_commit}..{end_commit}", no_merges=True))
|
||||
return commits
|
||||
|
||||
def format_tag(tag, branch_name):
|
||||
"""Formats the tag as 'branch-latest-tag-date-hash'."""
|
||||
commit_date = datetime.fromtimestamp(tag.commit.committed_date, timezone.utc).strftime("%Y%m%d")
|
||||
commit_hash = tag.commit.hexsha[:7] # Short commit hash
|
||||
return f"{branch_name}-{commit_date}-{commit_hash}"
|
||||
|
||||
def generate_changelog(repo_path, changelog_path, branch_name):
|
||||
repo = git.Repo(repo_path)
|
||||
tags = get_tags(repo, branch_name)
|
||||
changelog_entries = []
|
||||
|
||||
if not tags:
|
||||
start_commit = repo.commit(repo.git.rev_list("--max-parents=0", "HEAD"))
|
||||
commits = get_commits_between(repo, start_commit.hexsha, "HEAD")
|
||||
date_str = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
changelog_entries.append(f"# {date_str} - Initial Release\n\n")
|
||||
|
||||
for commit in commits:
|
||||
changelog_entries.append(f"* {commit.summary}\n")
|
||||
else:
|
||||
for i in range(len(tags) - 1):
|
||||
tag = tags[i] # Newest tag
|
||||
next_tag = tags[i + 1] # Older tag
|
||||
|
||||
tag_commit = tag.commit.hexsha
|
||||
next_tag_commit = next_tag.commit.hexsha
|
||||
|
||||
commits = get_commits_between(repo, next_tag_commit, tag_commit)
|
||||
|
||||
if not commits:
|
||||
continue
|
||||
|
||||
date_str = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
formatted_tag = format_tag(tag, branch_name)
|
||||
changelog_entries.append(f"# {date_str} - {formatted_tag}\n\n")
|
||||
|
||||
for commit in commits:
|
||||
changelog_entries.append(f"* {commit.summary}\n")
|
||||
|
||||
changelog_entries.append("\n")
|
||||
|
||||
with open(changelog_path, "w", encoding="utf-8") as f:
|
||||
f.writelines(changelog_entries)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Generate a changelog from git history.")
|
||||
parser.add_argument("--repo_path", "-p", type=str, help="Path to the git repository", default=".")
|
||||
parser.add_argument("--changelog_path", "-f", type=str, default="./CHANGELOG.md", help="Path to the output CHANGELOG.md file (default: ./CHANGELOG.md)")
|
||||
parser.add_argument("--branch_name", "-b", type=str, default="master", help="Branch name to filter tags (default: master)")
|
||||
args = parser.parse_args()
|
||||
|
||||
generate_changelog(args.repo_path, args.changelog_path, args.branch_name)
|
||||
@@ -329,6 +329,8 @@
|
||||
<NuxtLink @click="loadFile = '/FAQ.md'" v-text="'FAQ'"/>
|
||||
-
|
||||
<NuxtLink @click="loadFile = '/NEWS.md'" v-text="'News'"/>
|
||||
-
|
||||
<NuxtLink @click="loadFile = '/CHANGELOG.md'" v-text="'ChangeLog'"/>
|
||||
</div>
|
||||
<div class="column is-6 is-4-mobile has-text-right">
|
||||
{{ api_version }} - <a href="https://github.com/arabcoders/watchstate" target="_blank">WatchState</a>
|
||||
|
||||
@@ -38,6 +38,7 @@ final class ServeStatic implements LoggerAwareInterface
|
||||
'/README.md' => __DIR__ . '/../../README.md',
|
||||
'/NEWS.md' => __DIR__ . '/../../NEWS.md',
|
||||
'/FAQ.md' => __DIR__ . '/../../FAQ.md',
|
||||
'/CHANGELOG.md' => __DIR__ . '/../../CHANGELOG.md',
|
||||
];
|
||||
|
||||
private const array MD_IMAGES = [
|
||||
|
||||
Reference in New Issue
Block a user