Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit d4b6d46

Browse files
committed
REALSE ON tag push and silent errors
1 parent 1273478 commit d4b6d46

File tree

8 files changed

+202
-13
lines changed

8 files changed

+202
-13
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ""
5+
labels: ""
6+
assignees: ""
7+
---
8+
9+
**Describe the bug**
10+
A clear and concise description of what the bug is.
11+
12+
**To Reproduce**
13+
Steps to reproduce the behavior:
14+
15+
1.
16+
2.
17+
3.
18+
19+
**Expected behavior**
20+
A clear and concise description of what you expected to happen.
21+
22+
**Screenshots**
23+
If applicable, add screenshots to help explain your problem.
24+
25+
**Desktop (please complete the following information):**
26+
27+
- OS: [e.g. Ubuntu 22.04, macOS 11.4]
28+
- Node version [e.g 16.4.2]
29+
- Code Version [e.g. 1.1.0]
30+
31+
**Additional context**
32+
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: GitHub Discussions
4+
url: https://github.com/apitoolkit/apitoolkit-express/discussions
5+
about: Please discuss non bug-related topics there
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ""
5+
labels: ""
6+
assignees: ""
7+
---
8+
9+
**Is your feature request related to a problem? Please describe.**
10+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11+
12+
**Describe the solution you'd like**
13+
A clear and concise description of what you want to happen.
14+
15+
**Describe alternatives you've considered**
16+
A clear and concise description of any alternative solutions or features you've considered.
17+
18+
**Additional context**
19+
Add any other context or screenshots about the feature request here.

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "pip" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"

.github/workflows/release_package.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Release Python Package
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
jobs:
7+
release:
8+
runs-on: ubuntu-latest
9+
steps:
10+
# Checkout project repository
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
14+
# Setup Python environment
15+
- name: Setup Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.9"
19+
20+
# Install dependencies
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install wheel twine
25+
26+
# Extract version from tag
27+
- name: Get version from tag
28+
run: echo "NEW_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
29+
30+
# Determine if it's a pre-release
31+
- name: Check if pre-release
32+
run: |
33+
if [[ ${{ env.NEW_VERSION }} == *"-"* ]]; then
34+
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
35+
else
36+
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
37+
fi
38+
39+
# Update changelog unreleased section with new version
40+
- name: Update changelog
41+
uses: superfaceai/release-changelog-action@v1
42+
with:
43+
path-to-changelog: CHANGELOG.md
44+
version: ${{ env.NEW_VERSION }}
45+
operation: release
46+
47+
- name: Update version
48+
run: |
49+
sed -i "s/version=.*,/version='${{ env.NEW_VERSION }}',/" setup.py
50+
51+
# Configure Git
52+
- name: Git configuration
53+
run: |
54+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
55+
git config --global user.name "GitHub Actions"
56+
57+
# Commit changes
58+
- name: Commit version and changelog
59+
run: |
60+
git add CHANGELOG.md
61+
git add setup.py
62+
git commit -m "chore: release ${{ env.NEW_VERSION }}"
63+
64+
# Push changes and tags
65+
- name: Push changes
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
run: |
69+
git push origin HEAD:main
70+
71+
# Build package
72+
- name: Build package
73+
run: python setup.py sdist bdist_wheel
74+
75+
- name: Publish to PyPI
76+
env:
77+
TWINE_USERNAME: __token__
78+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
79+
run: |
80+
python -m twine upload dist/*
81+
82+
# Read version changelog
83+
- id: get-changelog
84+
name: Get version changelog
85+
uses: superfaceai/release-changelog-action@v1
86+
with:
87+
path-to-changelog: CHANGELOG.md
88+
version: ${{ env.NEW_VERSION }}
89+
operation: read
90+
91+
# Update GitHub release with changelog
92+
- name: Update GitHub release documentation
93+
uses: softprops/action-gh-release@v1
94+
with:
95+
tag_name: ${{ env.NEW_VERSION }}
96+
body: ${{ steps.get-changelog.outputs.changelog }}
97+
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## Unreleased

apitoolkit_flask/__init__.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,31 @@ def __init__(self, api_key, root_url="https://app.apitoolkit.io", redact_headers
2727
self.tags = tags
2828
response = requests.get(
2929
url=root_url + "/api/client_metadata", headers={"Authorization": f"Bearer {api_key}"})
30-
response.raise_for_status()
31-
data = response.json()
32-
credentials = service_account.Credentials.from_service_account_info(
33-
data["pubsub_push_service_account"])
34-
self.publisher = pubsub_v1.PublisherClient(credentials=credentials)
35-
self.topic_name = 'projects/{project_id}/topics/{topic}'.format(
36-
project_id=data['pubsub_project_id'],
37-
topic=data['topic_id'],
38-
)
39-
self.meta = data
30+
if response.status_code == 401:
31+
raise Exception(f"APIToolkit Error: Invalid API key")
32+
elif response.status_code >= 400:
33+
print(f"APIToolkit: Error getting client metadata {response.status_code}")
34+
else:
35+
data = response.json()
36+
credentials = service_account.Credentials.from_service_account_info(
37+
data["pubsub_push_service_account"])
38+
self.publisher = pubsub_v1.PublisherClient(credentials=credentials)
39+
self.topic_name = 'projects/{project_id}/topics/{topic}'.format(
40+
project_id=data['pubsub_project_id'],
41+
topic=data['topic_id'],
42+
)
43+
self.meta = data
4044

4145
def getInfo(self):
4246
return {"project_id": self.meta["project_id"], "service_version": self.service_version, "tags": self.tags}
4347

4448
def publish_message(self, payload):
49+
50+
if self.topic_name is None or self.publisher is None:
51+
if self.debug:
52+
print("APIToolkit: No topic or publisher (restart your server to fix)")
53+
return
54+
4555
data = json.dumps(payload).encode('utf-8')
4656
if self.debug:
4757
print("APIToolkit: publish message")
@@ -109,6 +119,12 @@ def beforeRequest(self):
109119
def afterRequest(self, response):
110120
if self.debug:
111121
print("APIToolkit: afterRequest")
122+
123+
if self.meta is None:
124+
if self.debug:
125+
print("APIToolkit: Project ID not set (restart your server to fix)")
126+
return
127+
112128
end_time = time.perf_counter_ns()
113129
apitoolkit_request_data = g.get("apitoolkit_request_data", {})
114130
duration = (end_time - apitoolkit_request_data.get("start_time", 0))

apitoolkit_flask/test_apitoolkit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from apitoolkit_flask import APIToolkit
12
from flask import Flask, request, jsonify
23
from werkzeug.test import Client
34
import sys
4-
from . import APIToolkit
55
import base64
66
import json
77

@@ -20,8 +20,7 @@
2020
]
2121

2222
apitoolkit = APIToolkit(
23-
api_key="<API_KEY>",
24-
root_url="http://localhost:8080",
23+
api_key="",
2524
redact_headers=redact_headers,
2625
redact_request_body=redact_req,
2726
redact_response_body=exampleDataRedaction,

0 commit comments

Comments
 (0)