Skip to content

Commit

Permalink
Add test header and semver ci (#304)
Browse files Browse the repository at this point in the history
* header and semver ci

* format

* format

* fix

* fix

* fix

* auto update semantic version

* update ci

* fix

* auto update semantic version

* refine

---------

Co-authored-by: wjymtg <[email protected]>
  • Loading branch information
wjymtg and wjymtg authored Jan 8, 2025
1 parent ced2dc4 commit cd569fb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/semver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Semantic Versioning

on:
pull_request:
types: [ labeled ]

permissions:
contents: write

jobs:
update-semver:
if: contains(fromJSON('["major", "minor", "patch"]'), github.event.label.name)
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: pip install semver argparse

- name: Get PR labels
id: pr-labels
uses: joerick/[email protected]

- name: Increment SemVer
run: |
python increment_version.py --labels ${{steps.pr-labels.outputs.labels}}
- name: Commit SemVer
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "auto update semantic version"
23 changes: 23 additions & 0 deletions increment_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import argparse

import semver

parser = argparse.ArgumentParser()
parser.add_argument("--labels", type=str)
args = vars(parser.parse_args())
print(f"args: {args}")

with open("version.txt", "r+") as file:
current_semver_str = file.read()
print(f"current ver: {current_semver_str}")
ver = semver.Version.parse(current_semver_str)
if "patch" in args["labels"]:
ver = ver.bump_patch()
if "minor" in args["labels"]:
ver = ver.bump_minor()
if "major" in args["labels"]:
ver = ver.bump_major()
print(f"new ver: {ver}")
file.seek(0)
file.write(str(ver))
file.truncate()
7 changes: 5 additions & 2 deletions src/bizy_server/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import bizyair
import bizyair.common
from bizyair.common.env_var import BIZYAIR_SERVER_ADDRESS
from bizyair.common.env_var import BIZYAIR_PRODUCTION_TEST, BIZYAIR_SERVER_ADDRESS

from .errno import ErrorNo, errnos
from .error_handler import ErrorHandler
from .utils import is_string_valid

CLIENT_VERSION = "v20241029"
with open(f"{os.path.dirname(__file__)}/../../version.txt", "r") as file:
CLIENT_VERSION = file.read()


class APIClient:
Expand All @@ -32,6 +33,8 @@ def auth_header(self):
"authorization": auth,
"x-bizyair-client-version": CLIENT_VERSION,
}
if BIZYAIR_PRODUCTION_TEST != None:
headers["x-bizyair-production-test"] = BIZYAIR_PRODUCTION_TEST
return headers, None
except ValueError as e:
error_message = e.args[0] if e.args else "Invalid API key"
Expand Down
1 change: 1 addition & 0 deletions src/bizyair/common/env_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ def create_api_key_file(api_key):
BIZYAIR_DEV_GET_TASK_RESULT_SERVER = env(
"BIZYAIR_DEV_GET_TASK_RESULT_SERVER", str, None
)
BIZYAIR_PRODUCTION_TEST = env("BIZYAIR_PRODUCTION_TEST", str, None)
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.4.2

0 comments on commit cd569fb

Please sign in to comment.