Skip to content

Commit 1c3eb26

Browse files
authored
Dynamic Version Integration in HTTP Headers with Release-Triggered Workflows (#96)
* Add dynamic version to HTTP headers * Update auto-release.yml * Optimize GitHub Actions setup for package release * Update README.md * update requirements
1 parent 8f90fe3 commit 1c3eb26

File tree

6 files changed

+44
-27
lines changed

6 files changed

+44
-27
lines changed

.github/workflows/auto-release.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1-
name: Pypi Release
1+
name: PyPI Release, Test, and Deploy
2+
23
on:
3-
workflow_run:
4-
workflows: [ "CI Tests" ]
5-
branches: [ master ]
6-
types:
7-
- completed
8-
# Allows you to run this workflow manually from the Actions tab
4+
release:
5+
types: [published]
6+
97
jobs:
8+
ci-tests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- name: Set up Python
16+
uses: actions/[email protected]
17+
with:
18+
python-version: '3.x'
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r requirements.txt
23+
- name: Run tox
24+
run: python -m tox
25+
1026
build-and-release:
11-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
27+
needs: ci-tests
1228
runs-on: ubuntu-latest
1329
steps:
1430
- uses: actions/checkout@v2
31+
with:
32+
fetch-depth: 0
1533
- uses: actions/[email protected]
1634
with:
1735
python-version: '3.x'
18-
- name: "Install dependencies"
36+
- name: Install dependencies
1937
run: |
20-
python3 -m pip install setuptools wheel twine
38+
python -m pip install --upgrade pip
39+
pip install -r requirements.txt
2140
- name: "Build and uploads to PyPI"
2241
run: |
2342
python3 setup.py sdist bdist_wheel

.github/workflows/tests.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ LOGGING = {
322322

323323
## Release Notes
324324

325+
- 4.1.3
326+
- Enhanced LogzioSender to dynamically set the user-agent header using the package version.
327+
- Adjusted GitHub Actions to trigger on new releases.
328+
- Streamlined versioning in deployments by automating Git tag extraction for PACKAGE_VERSION.
325329
- 4.1.2
326330
- Fix DeprecationWarning
327331
- Adjusted tests to logging:3.12

logzio/sender.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import sys
55
from datetime import datetime
6+
from importlib.metadata import version
67
from threading import Thread, enumerate
78
from time import sleep
89

@@ -14,7 +15,9 @@
1415
import Queue as queue
1516
else:
1617
import queue as queue
17-
18+
PACKAGE_NAME = "logzio-python-handler"
19+
PACKAGE_VERSION = version(PACKAGE_NAME)
20+
SHIPPER_HEADER = {"user-agent": f"{PACKAGE_NAME}-version-{PACKAGE_VERSION}-logs"}
1821
MAX_BULK_SIZE_IN_BYTES = 1 * 1024 * 1024 # 1 MB
1922

2023

@@ -108,7 +111,7 @@ def _flush_queue(self):
108111
self.number_of_retries = self.number_of_retries
109112

110113
should_backup_to_disk = True
111-
headers = {"Content-type": "text/plain"}
114+
headers = {"Content-type": "text/plain", **SHIPPER_HEADER}
112115

113116
for current_try in range(self.number_of_retries):
114117
should_retry = False

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ requests>=2.27.0
22
protobuf>=3.20.2
33
setuptools>=68.0.0 # not directly required, pinned to avoid a vulnerability
44
future>=0.18.3 # used in tests
5+
tox>=4.15.0
6+
wheel
7+
twine>=5.0.0
8+
setuptools_scm

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name="logzio-python-handler",
7-
version='4.1.2',
7+
use_scm_version=True,
88
description="Logging handler to send logs to your Logz.io account with bulk SSL",
99
keywords="logging handler logz.io bulk https",
1010
author="roiravhon",
@@ -23,6 +23,7 @@
2323
test_requires=[
2424
"future"
2525
],
26+
setup_requires=['setuptools_scm'],
2627
include_package_data=True,
2728
classifiers=[
2829
'Development Status :: 5 - Production/Stable',

0 commit comments

Comments
 (0)