forked from confluentinc/confluent-kafka-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Workflow to build and publish gr-patched version of librdkafka/confluent-kafka #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcin-krystianc
merged 4 commits into
G-Research:2.6.1-gr
from
marcin-krystianc:dev-20250219-simple_package_index
Feb 20, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import os | ||
import sys | ||
from pathlib import Path | ||
from github import Github | ||
from typing import List, Dict | ||
import itertools | ||
import requests | ||
|
||
HTML_TEMPLATE = """<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{package_name}</title> | ||
</head> | ||
<body> | ||
<h1>{package_name}</h1> | ||
{package_links} | ||
</body> | ||
</html> | ||
""" | ||
|
||
class PackageIndexBuilder: | ||
def __init__(self, token: str, repo_name: str, output_dir: str): | ||
self.github = Github(token) | ||
self.repo_name = repo_name | ||
self.output_dir = Path(output_dir) | ||
self.packages: Dict[str, List[Dict]] = {} | ||
|
||
# Set up authenticated session | ||
self.session = requests.Session() | ||
self.session.headers.update({ | ||
"Authorization": f"token {token}", | ||
"Accept": "application/octet-stream", | ||
}) | ||
|
||
def collect_packages(self): | ||
|
||
print ("Query release assets") | ||
repo = self.github.get_repo(self.repo_name) | ||
|
||
for release in repo.get_releases(): | ||
for asset in release.get_assets(): | ||
if asset.name.endswith(('.whl', '.tar.gz')): | ||
package_name = asset.name.split('-')[0].replace('_', '-') | ||
if package_name not in self.packages: | ||
self.packages[package_name] = [] | ||
|
||
self.packages[package_name].append({ | ||
'filename': asset.name, | ||
'url': asset.url, | ||
'size': asset.size, | ||
'upload_time': asset.created_at.strftime('%Y-%m-%d %H:%M:%S'), | ||
}) | ||
|
||
def generate_index_html(self): | ||
# Generate main index | ||
package_list = self.packages.keys() | ||
main_index = HTML_TEMPLATE.format( | ||
package_name="Simple Package Index", | ||
package_links="\n".join([f'<a href="{x}/">{x}</a><br/>' for x in package_list]) | ||
) | ||
|
||
with open(self.output_dir / "index.html", "w") as f: | ||
f.write(main_index) | ||
|
||
for package, assets in self.packages.items(): | ||
|
||
package_dir = self.output_dir / package | ||
package_dir.mkdir(exist_ok=True) | ||
|
||
# Generate package-specific index.html | ||
file_links = [] | ||
assets = sorted(assets, key=lambda x: x["filename"]) | ||
for filename, items in itertools.groupby(assets, key=lambda x: x["filename"]): | ||
file_links.append(f'<a href="./{filename}">{filename}</a><br/>') | ||
url = next(items)['url'] | ||
|
||
# Download the file | ||
with open(package_dir / filename, 'wb') as f: | ||
print (f"Downloading '{filename}' from '{url}'") | ||
response = self.session.get(url, stream=True) | ||
response.raise_for_status() | ||
for chunk in response.iter_content(chunk_size=8192): | ||
if chunk: | ||
f.write(chunk) | ||
|
||
package_index = HTML_TEMPLATE.format( | ||
package_name=package, | ||
package_links="\n".join(file_links) | ||
) | ||
|
||
with open(package_dir / "index.html", "w") as f: | ||
f.write(package_index) | ||
|
||
def build(self): | ||
# Create output directory | ||
self.output_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# Collect and generate | ||
self.collect_packages() | ||
self.generate_index_html() | ||
|
||
|
||
def main(): | ||
# Get environment variables | ||
token = os.environ.get("GITHUB_TOKEN") | ||
repo = os.environ.get("GITHUB_REPOSITORY") | ||
print (repo) | ||
output_dir = os.environ.get("OUTPUT_DIR", "dist") | ||
|
||
if not all([token, repo]): | ||
print ("Missing required environment variables") | ||
sys.exit(1) | ||
|
||
builder = PackageIndexBuilder(token, repo, output_dir) | ||
builder.build() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# .github/workflows/build-wheels.yml | ||
name: Build and Package Wheels | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
env: | ||
LIBRDKAFKA_VERSION: v2.6.1-gr | ||
|
||
jobs: | ||
|
||
build-linux-x64: | ||
name: Build wheels for Linux x64 | ||
runs-on: ubuntu-latest | ||
env: | ||
OS_NAME: linux | ||
ARCH: x64 | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build wheels | ||
run: | | ||
./tools/wheels/build-wheels.sh "${LIBRDKAFKA_VERSION#v}" wheelhouse | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheels-${{ env.OS_NAME }}-${{ env.ARCH }} | ||
path: wheelhouse/confluent_kafka*.whl | ||
|
||
build-windows: | ||
name: Build wheels for Windows | ||
runs-on: windows-latest | ||
env: | ||
OS_NAME: windows | ||
ARCH: x64 | ||
CHERE_INVOKING: yes | ||
MSYSTEM: UCRT64 | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup MSYS2 | ||
uses: msys2/setup-msys2@v2 | ||
- name: Build wheels | ||
shell: bash | ||
run: | | ||
./tools/mingw-w64/msys2-dependencies.sh | ||
bash tools/mingw-w64/semaphore_commands.sh | ||
bash tools/wheels/install-librdkafka.sh ${LIBRDKAFKA_VERSION#v} dest | ||
tools/wheels/build-wheels.bat x64 win_amd64 dest wheelhouse | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheels-${{ env.OS_NAME }}-${{ env.ARCH }} | ||
path: wheelhouse/confluent_kafka*.whl | ||
|
||
publish_pypi_index: | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | ||
name: Build a PyPI-compatible index | ||
needs: [build-linux-x64, build-windows] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
actions: read | ||
packages: read | ||
pages: write | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
path: artifacts | ||
pattern: wheels-* | ||
merge-multiple: true | ||
|
||
- name: Create release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
files: | | ||
artifacts/confluent_kafka* | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Generate Package Index | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install PyGithub | ||
python .github/scripts/generate_index.py | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
OUTPUT_DIR: dist | ||
|
||
- name: Upload Site Artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: 'dist' | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: actions/deploy-pages@v4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "confluent-kafka" | ||
version = "2.6.1" | ||
version = "2.6.1+gr" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An official way to denote version |
||
description = "Confluent's Python client for Apache Kafka" | ||
classifiers = [ | ||
"Development Status :: 5 - Production/Stable", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,19 @@ echo "$0: Installing librdkafka $VER to $DEST" | |
[[ -d "$DEST" ]] || mkdir -p "$DEST" | ||
pushd "$DEST" | ||
|
||
curl -L -o lrk$VER.zip https://www.nuget.org/api/v2/package/librdkafka.redist/$VER | ||
# Check if variable exists | ||
if [ -z "${GITHUB_TOKEN}" ]; then | ||
echo "Error: GITHUB_TOKEN is not set" | ||
exit 1 | ||
fi | ||
|
||
curl -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Downloads appropriate patched version of librdkafka from our NuGet packages index. |
||
-H "Accept: application/vnd.github.v3+json" \ | ||
-L \ | ||
-o lrk$VER.zip \ | ||
https://nuget.pkg.github.com/G-Research/download/librdkafka.redist/$VER/librdkafka.redist.$VER.nupkg | ||
|
||
#curl -L -o lrk$VER.zip https://www.nuget.org/api/v2/package/librdkafka.redist/$VER | ||
|
||
unzip lrk$VER.zip | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attach wheels as release artifacts, these will be downloaded by the Python script to build a PIP-compatible simple package index.