From 150cc47f3364d491a3230cfbbbb4cbc50b96cdf9 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 28 Jan 2026 19:45:55 +0100 Subject: [PATCH] chore: add Release Please GHA workflow --- .github/workflows/ci.yml | 4 ++ .github/workflows/release-prepare.yml | 54 ------------------------- .github/workflows/release.yml | 58 +++++++++++---------------- .release-please-manifest.json | 3 ++ CMakeLists.txt | 6 +-- include/merve/version.h | 8 ++-- release-please-config.json | 11 +++++ tools/release/__init__.py | 0 tools/release/create_release.py | 22 ---------- tools/release/lib/__init__.py | 0 tools/release/lib/release.py | 20 --------- tools/release/lib/versions.py | 43 -------------------- tools/release/requirements.txt | 2 - tools/release/update_versions.py | 19 --------- 14 files changed, 48 insertions(+), 202 deletions(-) delete mode 100644 .github/workflows/release-prepare.yml create mode 100644 .release-please-manifest.json create mode 100644 release-please-config.json delete mode 100644 tools/release/__init__.py delete mode 100644 tools/release/create_release.py delete mode 100644 tools/release/lib/__init__.py delete mode 100644 tools/release/lib/release.py delete mode 100644 tools/release/lib/versions.py delete mode 100644 tools/release/requirements.txt delete mode 100644 tools/release/update_versions.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52bf551..616a358 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,12 +6,16 @@ on: paths-ignore: - '**.md' - 'docs/**' + - .github/** + - '!.github/workflows/ci.yml' push: branches: - main paths-ignore: - '**.md' - 'docs/**' + - .github/** + - '!.github/workflows/ci.yml' permissions: contents: read diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml deleted file mode 100644 index ad2e01c..0000000 --- a/.github/workflows/release-prepare.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Release Prepare - -on: - workflow_dispatch: - inputs: - tag: - type: string - required: true - description: "Tag for the next release. Ex.: v1.0.0" - -env: - NEXT_RELEASE_TAG: ${{ github.event.inputs.tag }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -jobs: - prepare-release-and-pull-request: - permissions: - contents: write - pull-requests: write - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Prepare Python - uses: actions/setup-python@v5 - with: - cache: 'pip' - - - name: Install dependencies - run: pip install -r ./tools/release/requirements.txt - - - name: Update source code versions - run: ./tools/release/update_versions.py - - - name: Setup Ninja - run: sudo apt-get install ninja-build - - - name: Build - run: cmake -B build -G Ninja && cmake --build build - - - name: Test - run: ctest --output-on-failure --test-dir build - - - name: Create PR with code updates for new release - uses: peter-evans/create-pull-request@v7 - with: - commit-message: "chore: release ${{ env.NEXT_RELEASE_TAG }}" - branch: "release/${{ env.NEXT_RELEASE_TAG }}" - title: "chore: release ${{ env.NEXT_RELEASE_TAG }}" - body: | - This pull PR updates the source code version to ${{ env.NEXT_RELEASE_TAG }} - delete-branch: true - sign-commits: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f6d8e8a..b5e8bea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,53 +1,38 @@ -name: Release Create +name: Release Please on: - pull_request: - types: [closed] + push: + branches: + - main -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +permissions: + contents: read jobs: - check-release-conditions: + release-please: runs-on: ubuntu-latest - if: | - github.event.pull_request.merged == true && - github.event.pull_request.base.ref == 'main' && - startsWith(github.event.pull_request.head.ref, 'release/v') && - startsWith(github.event.pull_request.user.login, 'github-actions') - + permissions: + contents: write + pull-requests: write + outputs: + release_created: ${{ steps.release.outputs.release_created }} + release_tag: ${{ steps.release.outputs.tag_name }} steps: - - name: Check release conditions - run: | - echo "All conditions have been met!" + - uses: googleapis/release-please-action@16a9c90856f42705d54a6fda1823352bdc62cf38 # v4.4.0 + id: release create-release: permissions: contents: write - needs: check-release-conditions + needs: release-please + if: ${{ needs.release-please.outputs.release_created }} runs-on: ubuntu-latest - env: - NEXT_RELEASE_TAG: ${{ github.event.pull_request.head.ref }} steps: - name: Checkout - uses: actions/checkout@v4 - - - name: Prepare Python - uses: actions/setup-python@v5 + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 with: - cache: 'pip' - - - name: Install dependencies - run: pip install -r ./tools/release/requirements.txt - - - name: Extract Tag from branch name - run: | - NEXT_RELEASE_TAG=$(echo $NEXT_RELEASE_TAG | sed 's/^release\///') - echo "NEXT_RELEASE_TAG=${NEXT_RELEASE_TAG}" >> $GITHUB_ENV - - - name: Target release Tag - run: echo "New tag $NEXT_RELEASE_TAG" + persist-credentials: false - name: Setup Ninja run: sudo apt-get install ninja-build @@ -65,4 +50,7 @@ jobs: cp merve.h merve.cpp ../../singleheader/ - name: Create release - run: ./tools/release/create_release.py + run: gh release upload "$RELEASE_TAG" singleheader/* + env: + GH_TOKEN: ${{ github.token }} + RELEASE_TAG: ${{ needs.release-please.outputs.release_tag }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..1772e6f --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "1.0.0" +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 2919e3c..38efdad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,11 @@ cmake_minimum_required(VERSION 3.16) project(merve DESCRIPTION "Fast lexer to extract named exports via analysis from CommonJS modules" LANGUAGES C CXX - VERSION 1.0.0 + VERSION 1.0.0 # x-release-please-version ) -set(MERVE_LIB_VERSION "1.0.0" CACHE STRING "lexer library version") -set(MERVE_LIB_SOVERSION "1" CACHE STRING "lexer library soversion") +set(MERVE_LIB_VERSION "1.0.0" CACHE STRING "lexer library version") # x-release-please-version +set(MERVE_LIB_SOVERSION "1" CACHE STRING "lexer library soversion") # x-release-please-major include(GNUInstallDirs) diff --git a/include/merve/version.h b/include/merve/version.h index 530ff3b..10d0fa4 100644 --- a/include/merve/version.h +++ b/include/merve/version.h @@ -5,14 +5,14 @@ #ifndef MERVE_VERSION_H #define MERVE_VERSION_H -#define MERVE_VERSION "1.0.0" +#define MERVE_VERSION "1.0.0" // x-release-please-version namespace lexer { enum { - MERVE_VERSION_MAJOR = 1, - MERVE_VERSION_MINOR = 0, - MERVE_VERSION_REVISION = 0, + MERVE_VERSION_MAJOR = 1, // x-release-please-major + MERVE_VERSION_MINOR = 0, // x-release-please-minor + MERVE_VERSION_REVISION = 0, // x-release-please-patch }; } // namespace lexer diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..74f443f --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,11 @@ +{ + "packages": { + ".": { + "release-type": "simple", + "extra-files": [ + "CMakeLists.txt", + "include/lexer/version.h" + ] + } + } +} diff --git a/tools/release/__init__.py b/tools/release/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tools/release/create_release.py b/tools/release/create_release.py deleted file mode 100644 index 03bb443..0000000 --- a/tools/release/create_release.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python3 - -from os import environ, path -from github import Github -from lib.release import create_release - -WORK_DIR = path.dirname(path.abspath(__file__)).replace("/tools/release", "") - -NEXT_TAG = environ.get("NEXT_RELEASE_TAG", None) -REPO_NAME = environ.get("GITHUB_REPOSITORY", None) -TOKEN = environ.get("GITHUB_TOKEN", None) -if not NEXT_TAG or not REPO_NAME or not TOKEN: - raise Exception("Bad environment variables. Invalid GITHUB_REPOSITORY, GITHUB_TOKEN or NEXT_RELEASE_TAG") - -g = Github(TOKEN) -repository = g.get_repo(REPO_NAME) - -release = create_release(repository, NEXT_TAG) -release.upload_asset("singleheader/lexer.cpp") -release.upload_asset("singleheader/lexer.h") -release.upload_asset("singleheader/singleheader.zip") -release.update_release(name=release.name, message=release.body, draft=False, make_latest="true") diff --git a/tools/release/lib/__init__.py b/tools/release/lib/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tools/release/lib/release.py b/tools/release/lib/release.py deleted file mode 100644 index b9a5303..0000000 --- a/tools/release/lib/release.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 - -import re -from github.Repository import Repository -from github.GitRelease import GitRelease - - -def is_valid_tag(tag: str) -> bool: - tag_regex = r"^v\d+\.\d+\.\d+$" - return bool(re.match(tag_regex, tag)) - - -def create_release(repository: Repository, tag: str) -> GitRelease: - if not is_valid_tag(tag): - raise Exception(f"Invalid tag: {tag}") - - try: - return repository.create_git_release(tag=tag, name=tag, draft=True, prerelease=False, generate_release_notes=True) - except Exception as exp: - raise Exception(f"create_release: Error creating release/tag {tag}: {exp!s}") from exp diff --git a/tools/release/lib/versions.py b/tools/release/lib/versions.py deleted file mode 100644 index 7fc618b..0000000 --- a/tools/release/lib/versions.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 - -import fileinput -import re - - -def update_cmakelists_version(new_version: str, file_path: str) -> None: - inside_project = False - with fileinput.FileInput(file_path, inplace=True) as cmakelists: - for line in cmakelists: - if "set(MERVE_LIB_VERSION" in line: - line = re.sub(r"[0-9]+\.[0-9]+\.[0-9]+", new_version, line) - elif "set(MERVE_LIB_SOVERSION" in line: - line = re.sub(r"[0-9]+", new_version.split(".")[0], line) - - elif "project(" in line: - inside_project = True - elif inside_project: - if "VERSION" in line: - line = re.sub(r"[0-9]+\.[0-9]+\.[0-9]+", new_version, line) - inside_project = False - print(line, end="") - - -def update_lexer_version_h(new_version: str, file_path: str) -> None: - new_version_list = new_version.split(".") - with fileinput.FileInput(file_path, inplace=True) as version_h: - inside_enum = False - for line in version_h: - if "#define MERVE_VERSION" in line: - line = f'#define MERVE_VERSION "{new_version}"\n' - - elif "enum {" in line: - inside_enum = True - elif inside_enum: - if line.strip().startswith("MERVE_VERSION_MAJOR"): - line = re.sub(r"\d+", new_version_list[0], line) - elif line.strip().startswith("MERVE_VERSION_MINOR"): - line = re.sub(r"\d+", new_version_list[1], line) - elif line.strip().startswith("MERVE_VERSION_REVISION"): - line = re.sub(r"\d+", new_version_list[2], line) - - print(line, end="") diff --git a/tools/release/requirements.txt b/tools/release/requirements.txt deleted file mode 100644 index a717a49..0000000 --- a/tools/release/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -PyGithub==2.8.1 -pytest==9.0.2 diff --git a/tools/release/update_versions.py b/tools/release/update_versions.py deleted file mode 100644 index 71f3367..0000000 --- a/tools/release/update_versions.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -import os -import lib.versions as update_versions -from lib.release import is_valid_tag - -WORK_DIR = os.path.dirname(os.path.abspath(__file__)).replace("/tools/release", "") - -MERVE_VERSION_H = f"{WORK_DIR}/include/lexer/version.h" -CMAKE_LISTS = f"{WORK_DIR}/CMakeLists.txt" - -NEXT_TAG = os.environ["NEXT_RELEASE_TAG"] -if not NEXT_TAG or not is_valid_tag(NEXT_TAG): - raise Exception(f"Bad environment variables. Invalid NEXT_RELEASE_TAG {NEXT_TAG}.") - -NEXT_TAG = NEXT_TAG[1:] # from v1.0.0 to 1.0.0 - -update_versions.update_lexer_version_h(NEXT_TAG, MERVE_VERSION_H) -update_versions.update_cmakelists_version(NEXT_TAG, CMAKE_LISTS)