-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into clean-cmmands
- Loading branch information
Showing
4 changed files
with
65 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -7,28 +7,35 @@ on: | |
- published | ||
|
||
jobs: | ||
build_frontend: | ||
name: Build frontend Javascript code | ||
build: | ||
name: Build source distribution | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
node-version: 22 | ||
|
||
- name: Build frontend | ||
working-directory: frontend | ||
run: npm ci && npm run build | ||
- name: Install build | ||
run: python -m pip install build | ||
|
||
- name: Set version number | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py | ||
|
||
- name: Build | ||
run: python -m build | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist/ | ||
name: build-output | ||
path: dist/opuscleaner-*.* | ||
|
||
run_tests: | ||
needs: [build_frontend] | ||
needs: [build] | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
@@ -38,95 +45,26 @@ jobs: | |
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist | ||
name: build-output | ||
path: dist | ||
|
||
- name: Install | ||
run: python3 -m pip install . | ||
run: python3 -m pip install dist/opuscleaner-*.whl | ||
|
||
- name: Run runtime unittest | ||
run: python3 -m unittest discover -s test | ||
|
||
- name: Run filters unittest | ||
run: python3 -m unittest discover -s opuscleaner/filters | ||
|
||
build_sdist: | ||
needs: [build_frontend] | ||
name: Build source distribution | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v3 | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist | ||
|
||
- name: Set version number | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py | ||
|
||
- name: Build sdist | ||
run: pipx run build --sdist | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: sdist | ||
path: dist/opuscleaner-*.tar.gz | ||
|
||
build_wheels: | ||
needs: [build_frontend] | ||
name: Build wheels | ||
runs-on: ubuntu-latest | ||
# name: Build wheels on ${{ matrix.os }} | ||
# runs-on: ${{ matrix.os }} | ||
# strategy: | ||
# matrix: | ||
# os: [ubuntu-latest, windows-2019, macos-13] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v3 | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: frontend | ||
path: frontend/dist | ||
|
||
- name: Set version number | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
run: echo "VERSION = \"${GITHUB_REF_NAME:1}\"" > opuscleaner/__about__.py | ||
|
||
- name: Build wheels | ||
run: python -m pip wheel -w wheelhouse . | ||
|
||
# - name: Install cibuildwheel | ||
# run: python -m pip install cibuildwheel==2.12.0 | ||
|
||
# - name: Build wheels | ||
# run: python -m cibuildwheel --output-dir wheelhouse | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: wheels | ||
path: ./wheelhouse/opuscleaner-*.whl | ||
|
||
upload_pypi: | ||
needs: [build_wheels, build_sdist] | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'release' && github.event.action == 'published' | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: wheels | ||
path: dist | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: sdist | ||
name: build-output | ||
path: dist | ||
|
||
- uses: pypa/[email protected] | ||
|
This file contains 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
This file contains 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
This file contains 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,32 @@ | ||
import subprocess | ||
import os | ||
from typing import Any | ||
import logging | ||
|
||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class NpmBuildHook(BuildHookInterface): | ||
@property | ||
def working_dir(self): | ||
return self.config.get("working_dir", ".") | ||
|
||
def initialize(self, version: str, build_data: dict[str, Any]) -> None: | ||
# if we can't build because we don't have the build dir, skip | ||
if not os.path.exists(self.working_dir): | ||
logger.info(f"Skipping npm build because {self.working_dir=} does not exist") | ||
return | ||
# if we don't need to build because we have all the artifacts, skip | ||
if all(os.path.exists(artifact) for artifact in self.config.get("artifacts", [])): | ||
logger.info(f"Skipping npm build because all artifacts exist") | ||
return | ||
subprocess.check_output( | ||
"npm install && npm run build", | ||
shell=True, | ||
cwd=self.working_dir) | ||
|
||
def clean(self, versions: list[str]) -> None: | ||
subprocess.check_output("npm run clean", shell=True, cwd=self.working_dir) |