Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"
- uses: bazelbuild/setup-bazelisk@v3
- name: Set up Python
uses: actions/setup-python@v5
Expand All @@ -30,7 +40,7 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: opencc-bazel-${{ matrix.os }}
name: opencc-${{ env.VERSION }}-bazel-${{ matrix.os }}
path: |
bazel-bin/**
bazel-testlogs/**
12 changes: 11 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ jobs:
os: [ubuntu-latest, macos-latest, macos-14]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"
- name: make build
run: make build VERBOSE=1 REL_BUILD_DOCUMENTATION=OFF
- name: make test
Expand All @@ -28,7 +38,7 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: opencc-cmake-${{ matrix.os }}
name: opencc-${{ env.VERSION }}-cmake-${{ matrix.os }}
path: |
build/rel/**
build/dbg/**
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ jobs:
steps:
- uses: msys2/setup-msys2@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"
- name: Install dependencies
run: pacman -S --noconfirm base-devel mingw-w64-x86_64-toolchain cmake ninja python
- name: Build with mingw-w64
Expand Down Expand Up @@ -48,7 +57,7 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: opencc-mingw
name: opencc-${{ env.VERSION }}-mingw
path: |
install/**
build/src/tools/*.exe
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ jobs:
can_run_binaries: false
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
Expand Down Expand Up @@ -90,7 +100,7 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: opencc-msvc-${{ matrix.arch }}
name: opencc-${{ env.VERSION }}-msvc-${{ matrix.arch }}
path: |
dist/OpenCC-msvc-${{ matrix.package_suffix }}.zip
dist/opencc-msvc-${{ matrix.package_suffix }}/**
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ jobs:
node-version: 20
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand All @@ -37,7 +47,7 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: opencc-nodejs-${{ matrix.os }}-node-${{ matrix.node-version }}
name: opencc-${{ env.VERSION }}-nodejs-${{ matrix.os }}-node-${{ matrix.node-version }}
path: |
node/build/**
**/npm-debug.log
25 changes: 23 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -42,7 +52,7 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: opencc-python-${{ matrix.python-version }}
name: opencc-${{ env.VERSION }}-python-${{ matrix.python-version }}
path: |
pytest.xml

Expand All @@ -54,13 +64,24 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"

- name: Build package and upload from docker (Linux)
if: runner.os == 'Linux'
run: |
docker run --rm -v "${PWD}:/opt/OpenCC" \
-e TWINE_USERNAME=__token__ \
-e TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }} \
-e VERSION=${VERSION} \
ubuntu:22.04 /bin/bash /opt/OpenCC/release-pypi-linux.sh testonly

- name: Build package and upload (macOS)
Expand All @@ -82,6 +103,6 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: opencc-pypi-${{ matrix.os }}
name: opencc-${{ env.VERSION }}-pypi-${{ matrix.os }}
path: |
dist/**
11 changes: 11 additions & 0 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
VERSION=$(bash scripts/compute-version.sh)
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Computed version: $VERSION"

- name: Build package and upload from docker (Linux)
if: runner.os == 'Linux'
run: |
docker run --rm -v "${PWD}:/opt/OpenCC" \
-e TWINE_USERNAME=__token__ \
-e TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }} \
-e VERSION=${VERSION} \
ubuntu:22.04 /bin/bash /opt/OpenCC/release-pypi-linux.sh

- name: Build package and upload (macOS)
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-winget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ilammy/msvc-dev-cmd@v1
with:
Expand Down
14 changes: 3 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,10 @@ option(USE_SYSTEM_TCLAP "Use system version of TCLAP" OFF)
######## Package information
set (PACKAGE_URL https://github.com/BYVoid/OpenCC)
set (PACKAGE_BUGREPORT https://github.com/BYVoid/OpenCC/issues)
set (OPENCC_VERSION_MAJOR 1)
set (OPENCC_VERSION_MINOR 2)
set (OPENCC_VERSION_REVISION 1)

if (CMAKE_BUILD_TYPE MATCHES Debug)
set (version_suffix .Debug)
endif (CMAKE_BUILD_TYPE MATCHES Debug)

set (
OPENCC_VERSION
${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}${version_suffix}
)
# Derive version from Git tags (falls back to hardcoded default when Git is unavailable)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(GitVersion)

set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${PACKAGE_NAME}-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}"
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ graft deps
graft test
graft data
graft doc
include CMakeLists.txt OpenCCConfig.cmake.in opencc.pc.in README* LICENSE*
graft cmake
include AUTHORS CMakeLists.txt OpenCCConfig.cmake.in opencc.pc.in README* LICENSE*
global-exclude *~ *.py[cod] *.so
include python/**/__init__.py
graft python/tests
101 changes: 101 additions & 0 deletions cmake/GitVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# GitVersion.cmake — Derive project version from Git tags.
#
# Sets in parent scope:
# OPENCC_VERSION Full version string (e.g. "1.2.1" or "1.2.1.dev4+gabc1234")
# OPENCC_VERSION_MAJOR Major component
# OPENCC_VERSION_MINOR Minor component
# OPENCC_VERSION_REVISION Patch/revision component
# OPENCC_VERSION_SUFFIX Everything after M.m.p (e.g. ".dev4+gabc1234.dirty") or ""
# OPENCC_VERSION_IS_RELEASE TRUE if this is an exact-tag release build
#
# Falls back to hardcoded default when Git is unavailable.
#

set(_OPENCC_FALLBACK_MAJOR 1)
set(_OPENCC_FALLBACK_MINOR 2)
set(_OPENCC_FALLBACK_REVISION 1)

find_package(Git QUIET)

set(_git_version_computed FALSE)

if(GIT_FOUND)
# Try git describe --tags --long --always
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --long --always
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE _git_raw
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _git_result
)

if(_git_result EQUAL 0 AND _git_raw)
# Detect dirty working tree
set(_dirty_suffix "")
execute_process(
COMMAND "${GIT_EXECUTABLE}" diff --quiet
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE _diff_result
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" diff --cached --quiet
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE _diff_cached_result
)
if(NOT _diff_result EQUAL 0 OR NOT _diff_cached_result EQUAL 0)
set(_dirty_suffix ".dirty")
endif()

# Case 1: Exact tag — v1.2.3-0-g<sha> or ver.1.2.3-0-g<sha>
# NOTE: version tag patterns here must be kept in sync with scripts/compute-version.sh
string(REGEX MATCH "^(v|ver\\.)([0-9]+)\\.([0-9]+)\\.([0-9]+)-0-g[0-9a-f]+$" _match_tag "${_git_raw}")
if(_match_tag)
set(OPENCC_VERSION_MAJOR "${CMAKE_MATCH_2}")
set(OPENCC_VERSION_MINOR "${CMAKE_MATCH_3}")
set(OPENCC_VERSION_REVISION "${CMAKE_MATCH_4}")
set(OPENCC_VERSION_SUFFIX "${_dirty_suffix}")
set(OPENCC_VERSION_IS_RELEASE TRUE)
set(_git_version_computed TRUE)
endif()

# Case 2: Dev build — v1.2.3-N-g<sha> or ver.1.2.3-N-g<sha> (N > 0)
if(NOT _git_version_computed)
string(REGEX MATCH "^(v|ver\\.)([0-9]+)\\.([0-9]+)\\.([0-9]+)-([0-9]+)-g([0-9a-f]+)$" _match_dev "${_git_raw}")
if(_match_dev)
set(OPENCC_VERSION_MAJOR "${CMAKE_MATCH_2}")
set(OPENCC_VERSION_MINOR "${CMAKE_MATCH_3}")
set(OPENCC_VERSION_REVISION "${CMAKE_MATCH_4}")
set(OPENCC_VERSION_SUFFIX ".dev${CMAKE_MATCH_5}+g${CMAKE_MATCH_6}${_dirty_suffix}")
set(OPENCC_VERSION_IS_RELEASE FALSE)
set(_git_version_computed TRUE)
endif()
endif()

# Case 3: No tag — raw SHA only
if(NOT _git_version_computed)
set(OPENCC_VERSION_MAJOR "${_OPENCC_FALLBACK_MAJOR}")
set(OPENCC_VERSION_MINOR "${_OPENCC_FALLBACK_MINOR}")
set(OPENCC_VERSION_REVISION "${_OPENCC_FALLBACK_REVISION}")
set(OPENCC_VERSION_SUFFIX "+g${_git_raw}${_dirty_suffix}")
set(OPENCC_VERSION_IS_RELEASE FALSE)
set(_git_version_computed TRUE)
endif()
endif()
endif()

# Fallback: no Git or git describe failed
if(NOT _git_version_computed)
message(STATUS "Git not available — using fallback version ${_OPENCC_FALLBACK_MAJOR}.${_OPENCC_FALLBACK_MINOR}.${_OPENCC_FALLBACK_REVISION}")
set(OPENCC_VERSION_MAJOR "${_OPENCC_FALLBACK_MAJOR}")
set(OPENCC_VERSION_MINOR "${_OPENCC_FALLBACK_MINOR}")
set(OPENCC_VERSION_REVISION "${_OPENCC_FALLBACK_REVISION}")
set(OPENCC_VERSION_SUFFIX "")
set(OPENCC_VERSION_IS_RELEASE FALSE)
endif()

# Compose full version string
set(OPENCC_VERSION "${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}${OPENCC_VERSION_SUFFIX}")

message(STATUS "OpenCC version: ${OPENCC_VERSION}")
6 changes: 3 additions & 3 deletions release-pypi-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ eval "$(conda shell.bash hook)"
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r

for VERSION in 3.9 3.10 3.11 3.12 3.13 3.14; do
for PYTHON_VERSION in 3.9 3.10 3.11 3.12 3.13 3.14; do
# Create and activate environment
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -y -n py$VERSION python=$VERSION
conda activate py$VERSION
conda create -y -n py$PYTHON_VERSION python=$PYTHON_VERSION
conda activate py$PYTHON_VERSION

# Build and package
pip install --no-cache-dir build
Expand Down
6 changes: 3 additions & 3 deletions release-pypi-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ eval "$(conda shell.bash hook)"
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r

for VERSION in 3.9 3.10 3.11 3.12 3.13 3.14; do
for PYTHON_VERSION in 3.9 3.10 3.11 3.12 3.13 3.14; do
# Create and activate environment
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -y -n py$VERSION python=$VERSION
conda activate py$VERSION
conda create -y -n py$PYTHON_VERSION python=$PYTHON_VERSION
conda activate py$PYTHON_VERSION

# Build and package
pip install --no-cache-dir build
Expand Down
Loading
Loading