Skip to content

Commit

Permalink
ci: add updated ci release
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Jul 19, 2024
1 parent 31aa5e4 commit 1494445
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 20 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Release

on:
workflow_call:
inputs:
version:
description: Release version
required: true
type: string

jobs:
build:
uses: ./.github/workflows/build.yaml
with:
check: true
preview: true
publish:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
ssh-key: ${{ secrets.RELEASE_PRIVATE_KEY }}
fetch-depth: 0
persist-credentials: true

- name: Setup GitHub Actions bot
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Setup release environment
run: make configure

- name: Download build
uses: actions/download-artifact@v3
with:
name: Lilex
path: build

- name: Generate source with new version
run: python scripts/lilex.py generate --version "${{ inputs.version }}"

- name: Save release notes
run: python scripts/changelog.py notes Next > notes.md

- name: Update changelog with new version
run: python scripts/changelog.py release "${{ inputs.version }}"

- name: Replace builded font files
run: |
rm -rf fonts
mv build fonts
- name: Create git commit and tag
run: |
git add sources/Lilex.glyphs
git add CHANGELOG.md
git add fonts
git status
git commit -m "chore: release ${{ inputs.version }} 🔥"
git tag "${{ inputs.version }}"
# - name: Push changes
# uses: ad-m/github-push-action@master
# with:
# ssh: true
# tags: true

# - name: Create GitHub release
# if: github.event_name == 'push'
# uses: softprops/action-gh-release@v2
# with:
# name: ${{ input.version }}
# body_path: notes.md
# token: ${{ secrets.USER_PAT }}
# prerelease: ${{ contains(input.version, '-') }}
# files: |
# Lilex.zip
46 changes: 26 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Project variables
VERSION = 2.520

# Project paths
BUNDLE_DIR = bundle
# BUNDLE_DIR = bundle
BUILD_DIR = build
REPORTS_DIR = reports
SCRIPTS_DIR = scripts
Expand Down Expand Up @@ -81,8 +78,7 @@ preview: ## show CLI special symbols preview

.PHONY: generate
generate: ## regenerate the font sources with classes and features
@$(VENV) python $(SCRIPTS_DIR)/lilex.py generate \
--version "$(VERSION)"
@$(VENV) python $(SCRIPTS_DIR)/lilex.py generate

.PHONY: build
build: ## build the font
Expand All @@ -97,21 +93,31 @@ build-preview: ## build the preview
run-preview: ## run the preview
cd preview; pnpm run dev

.PHONY: pack-bundle
pack-bundle: ## pack the bundle
rm -rf "$(BUNDLE_DIR)"
mkdir "$(BUNDLE_DIR)"
# Copy fonts
cp -r "$(BUILD_DIR)/"* "$(BUNDLE_DIR)/"
# Copy reports
cp "$(REPORTS_DIR)/"* "$(BUNDLE_DIR)/"
cd "$(BUNDLE_DIR)"; zip -r Lilex.zip ./*

.PHONY: bundle
bundle: ## build the bundle
# .PHONY: pack-bundle
# pack-bundle: ## pack the bundle
# rm -rf "$(BUNDLE_DIR)"
# mkdir "$(BUNDLE_DIR)"
# # Copy fonts
# cp -r "$(BUILD_DIR)/"* "$(BUNDLE_DIR)/"
# # Copy reports
# cp "$(REPORTS_DIR)/"* "$(BUNDLE_DIR)/"
# cd "$(BUNDLE_DIR)"; zip -r Lilex.zip ./*

# .PHONY: bundle
# bundle: ## build the bundle
# @make build
# @make check
# @make pack-bundle

.PHONY: release
release:
@make build
@make check
@make pack-bundle

.PHONY: release-notes
release-notes:
echo $(ARGS)
# @mkdir -p ./$(BUILD_DIR)
# $(VENV) python ./scripts/changelog.py notes Next > "./$(BUILD_DIR)/release-notes.md"

.PHONY: clean
clean: ## clean up
Expand Down
85 changes: 85 additions & 0 deletions scripts/changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3
"""Utility script release notes generation.
Usage: release_notes.py <version>
"""
import datetime

from arrrgs import arg, command, run

NEXT_VERSION_HEADING = "Next"
CHANGELOG_PATH = "CHANGELOG.md"
REPO_URL = "https://github.com/mishamyrt/Lilex"

def read_changelog() -> str:
with open(CHANGELOG_PATH, mode="r", encoding="utf-8") as file:
return file.read()

def parse_version_heading(line: str) -> str:
version = line[3:]
if not version.startswith("["):
return version
end = version.find("]")
if end == -1:
return version
return version[1:end]

def format_version_heading(version: str) -> str:
timestamp = datetime.date.today().strftime("%B %d, %Y")
release_heading = f"## [{version}] — {timestamp}"
return release_heading

def format_version_url(version: str) -> str:
return f"[{version}]: {REPO_URL}/releases/tag/{version}"

def collect_notes() -> dict[str, str]:
lines = read_changelog().split("\n")
releases = {}
version = ""
notes = ""
for line in lines:
if line.startswith("## "):
if version != "":
releases[version] = notes.strip("\n ")
notes = ""
version = parse_version_heading(line)
continue
if version == "":
continue
notes += line + "\n"
return releases

@command(
arg("version", help="Version number"),
name="notes"
)
def print_notes(args):
"""Saves the generated source file with features and classes"""
releases = collect_notes()
if args.version not in releases:
print(f"Version {args.version} not found")
print("Available versions:")
for version in releases:
print(f"- {version}")
return
for version, notes in releases.items():
if version == args.version:
print(notes)

@command(
arg("version", help="Version number")
)
def release(args):
"""Regenerates the changelog with the new version"""
# May 10, 2024
timestamp = datetime.date.today().strftime("%B %d, %Y")
release_heading = f"## [{args.version}] — {timestamp}"
changelog = read_changelog()
changelog = changelog.replace(f"## {NEXT_VERSION_HEADING}", release_heading)
changelog += "\n" + format_version_url(args.version) + "\n"
with open(CHANGELOG_PATH, mode="w", encoding="utf-8") as file:
file.write(changelog)
print("🟢 Changelog successfully updated")

if __name__ == "__main__":
run()

0 comments on commit 1494445

Please sign in to comment.