Skip to content

Improve Build and Dist Infrastructure #6

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
merged 14 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Build custom build action yaml and improve packaging script.
  • Loading branch information
JSv4 committed Apr 1, 2024
commit 83a7e25a72fe48a7c1da7ecda739c6f47bc1fb66
22 changes: 8 additions & 14 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
Expand All @@ -22,18 +14,20 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install hatch
- name: Build package
run: python -m build
run: hatch build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
run: |
hatch publish -u "__token__" -a ${{ secrets.PYPI_API_TOKEN }}
8 changes: 5 additions & 3 deletions build_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def main():
version = get_version()
print(f"Version: {version}")

dist_dir = "./src/python_redlines/dist/"

# Build for Linux
print("Building for Linux...")
run_command('dotnet publish ./csproj -c Release -r linux-x64 --self-contained')
Expand All @@ -58,15 +60,15 @@ def main():

# Compress the Linux build
linux_build_dir = './csproj/bin/Release/net8.0/linux-x64'
compress_files(linux_build_dir, f"./dist/linux-x64-{version}.tar.gz")
compress_files(linux_build_dir, f"{dist_dir}/linux-x64-{version}.tar.gz")

# Compress the Windows build
windows_build_dir = './csproj/bin/Release/net8.0/win-x64'
compress_files(windows_build_dir, f"./dist/win-x64-{version}.zip")
compress_files(windows_build_dir, f"{dist_dir}/win-x64-{version}.zip")

# Compress the macOS build
macos_build_dir = './csproj/bin/Release/net8.0/osx-x64'
compress_files(macos_build_dir, f"./dist/osx-x64-{version}.tar.gz")
compress_files(macos_build_dir, f"{dist_dir}/osx-x64-{version}.tar.gz")

print("Build and compression complete.")

Expand Down
2 changes: 2 additions & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Binary file removed dist/osx-x64-0.0.1.tar.gz
Binary file not shown.
Binary file removed dist/win-x64-0.0.1.zip
Binary file not shown.
9 changes: 9 additions & 0 deletions hatch_run_build_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import subprocess
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

class HatchRunBuildHook(BuildHookInterface):
PLUGIN_NAME = 'hatch-run-build'

def initialize(self, version, build_data):
# Run the 'hatch run build' command
subprocess.run(['hatch', 'run', 'build'], check=True)
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ artifacts = [
"*.tar.gz",
]

# Build hook to build the binaries for distribution...
[tool.hatch.build.hooks.custom]
path = "hatch_run_build_hook.py"

[project]
name = "python-redlines"
dynamic = ["version"]
Expand Down
3 changes: 2 additions & 1 deletion src/python_redlines/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*
*
!.gitignore
3 changes: 2 additions & 1 deletion src/python_redlines/dist/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
!*
*
!.gitignore
Binary file not shown.