collective / sc.recipe.staticresources

This package is used as a buildout recipe to bundle static resources for Plone add-ons using webpack.
Other
2 stars 0 forks source link

[Documentation] Use entry_points to build static resources in fullrelease call #88

Open idgserpro opened 3 years ago

idgserpro commented 3 years ago

Usually when using this package (like collective.cover) you need to follow a different workflow if you're into just calling fullrelease:

    run longtest and fullrelease, as usually
    answer "no" when asked to upload to PyPI and continue normally
    do a checkout to the tag you're releasing
    run bin/build-cover to update static files
    create the distribution files using python setup.py sdist bdist_wheel as usual
    upload the files using twine upload dist/*

It's possible to use entry_points from zest.releaser and hooks to call the webpack compiling stage when creating the build, after the checkout. Take collective.cover, for example:

Edit your setup.cfg:

[zest.releaser]
extra-message = [skip ci]
hook_package_dir = src/collective/cover
releaser.after_checkout =
    entry_points.build_webpack

And add an entry_points.py:

import os
import time

OK_EXIT_CODE = 0
BUILD_CMD = 'build-cover'

def _run_cmd(cmd, exception_msg="Error when running cmd {0}"):
    exit_code = os.system(cmd)  # nosec
    if exit_code != OK_EXIT_CODE:
        raise OSError(exception_msg.format(cmd))

def build_webpack(data):
    tmpdir = data['tagworkingdir']
    print(tmpdir)  # NOQA
    time.sleep(3)
    bin_location = '{0}/bin'.format(tmpdir)
    _run_cmd('virtualenv {0}'.format(tmpdir))
    _run_cmd('{0}/pip install -r requirements.txt'.format(bin_location))
    _run_cmd('{0}/buildout'.format(bin_location))
    _run_cmd('{0}/{1}'.format(bin_location, BUILD_CMD))

If you want to check for virtualenv and another dependencies before doing the hook, you can add a prereleaser.before for example in entry_points.check_deps_to_build.