Skip to content
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

Cannot get vcs source in github PR event trigger #1098

Closed
clement-chaneching opened this issue Jan 16, 2025 · 4 comments
Closed

Cannot get vcs source in github PR event trigger #1098

clement-chaneching opened this issue Jan 16, 2025 · 4 comments

Comments

@clement-chaneching
Copy link

I cannot manage to build my docker image during a PR event trigger.

I am using this trigger:

  docker-build-and-deploy:
    if: contains(github.event.pull_request.labels.*.name, 'label')

With this docker build action that tries to install a package:

- name: Build and push
        uses: docker/build-push-action@v6
        env:
          DOCKER_BUILD_SUMMARY: false
          SETUPTOOLS_SCM_PRETEND_VERSION: "0.0.0"
        with:
          cache-to: type=inline
          provenance: false
          build-args: |
            BUILDKIT_CONTEXT_KEEP_GIT_DIR=1

The package has this pyproject.toml:

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
root = "../.."
fallback_version="0.0.0"

Here is the error:

#16 42.08   × environment: error installing/updating PyPI dependencies
#16 42.08   ├─▶ Failed to prepare distributions
#16 42.08   ├─▶ Failed to fetch wheel: experiments @ file:///app/packages/experiments
#16 42.08   ╰─▶ Build backend failed to build wheel through `build_editable()` with exit
#16 42.08       status: 1
#16 42.08       --- stdout:
#16 42.08       
#16 42.08       --- stderr:
#16 42.08       /root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/python3.10/
#16 42.08       site-packages/setuptools_scm/git.py:167: UserWarning: "/app" is shallow
#16 42.08       and may cause errors
#16 42.08         warnings.warn(f'"{wd.path}" is shallow and may cause errors')
#16 42.08       /root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/python3.10/
#16 42.08       site-packages/setuptools_scm/version.py:102: UserWarning: tag 'refs/
#16 42.08       pull/2096/merge' no version found
#16 42.08         warnings.warn(f"tag {tag!r} no version found")
#16 42.08       Traceback (most recent call last):
#16 42.08         File "<string>", line 11, in <module>
#16 42.08         File "/root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/
#16 42.08       python3.10/site-packages/hatchling/build.py", line 83, in build_editable
#16 42.08           return os.path.basename(next(builder.build(directory=wheel_directory,
#16 42.08       versions=['editable'])))
#16 42.08         File "/root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/
#16 42.08       python3.10/site-packages/hatchling/builders/plugin/interface.py", line
#16 42.08       90, in build
#16 42.08           self.metadata.validate_fields()
#16 42.08         File "/root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/
#16 42.08       python3.10/site-packages/hatchling/metadata/core.py", line 265, in
#16 42.08       validate_fields
#16 42.08           _ = self.version
#16 42.08         File "/root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/
#16 42.08       python3.10/site-packages/hatchling/metadata/core.py", line 149, in
#16 42.08       version
#16 42.08           self._version = self._get_version()
#16 42.08         File "/root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/
#16 42.08       python3.10/site-packages/hatchling/metadata/core.py", line 248, in
#16 42.08       _get_version
#16 42.08           version = self.hatch.version.cached
#16 42.08         File "/root/.cache/rattler/cache/uv-cache/builds-v0/.tmpt35zt9/lib/
#16 42.08       python3.10/site-packages/hatchling/metadata/core.py", line 1456, in
#16 42.08       cached
#16 42.08           raise type(e)(message) from None
#16 42.08       AssertionError: Error getting the version from source `vcs`:
#16 42.08       ---

Is it because it tries to fetch a PR instead of a tag?
UserWarning: tag 'refs/pull/2096/merge' no version found

I tried using checkout with fetch-depth:0, setting SETUPTOOLS_SCM_PRETEND_VERSION and fallback without success.
The docker build works well when using a workflow_dispatch or merge to main event, but I cant get it to work during a PR event based on a label.

Thanks for your help!

@RonnyPfannschmidt
Copy link
Contributor

off hand its uncear why its not seeing the details

can you add SETUPTOOLS_SCM_DEBUG=1 to the environment to see more of the output

with pretend version set it should not even look at the scm

@clement-chaneching
Copy link
Author

Thanks for replying!
I added SETUPTOOLS_SCM_DEBUG=1 in the github action and the Dockerfiles, but it doesnt output any additional logs.
It works locally, on workflow dispatch and push events as well, but not on my pull_request github action trigger

The task that fails is when it builds my docker image with pixi:

ENV SETUPTOOLS_SCM_PRETEND_VERSION=1
ENV SETUPTOOLS_SCM_DEBUG=1

RUN --mount=type=secret,id=GAUTH,uid=1000 \
    pixi install -e my_environment --locked --pypi-keyring-provider subprocess

And in my pixi.toml i have:
experiments = { path = "packages/experiments", editable = true }

Which has the following pyproject.toml:

[project]
name = "experiments"
dynamic = ["version"]
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["experiments"]

[tool.hatch.build.targets.wheel.sources]
"experiments" = "experiments"

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
root = "../.."
fallback_version="0.0.0"

[tool.hatch.metadata]
allow-direct-references = true

I m not sure what additional information I can provide.

@RonnyPfannschmidt
Copy link
Contributor

Then you need to make the build tool verbose as well

Without the extra logs there's nothing i can do

@clement-chaneching
Copy link
Author

I couldnt get any additional logs, even by setting buildx debug and progress=plain, but it looks like adding ENV SETUPTOOLS_SCM_PRETEND_VERSION=1.0.0 in the dockerfile directly fixed it.
Cant find any better workaround for now! Thanks for the help and sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants