← Back to issue list

global environment not being registered for CRAFT_PROJECT_VERSION

View original Github issue

Metadata

Project
rockcraft
Number
#333
Type
issue
State
closed
Author
cjdcordeiro
Labels
—
Created
Updated
Closed

Current evaluation

Fixed by merged PR #336 (commit 42627c1a), which registers global project variables, including CRAFT_PROJECT_VERSION, before lifecycle steps.

Resolution: closed resolved

Reason: PR #336 added project and global environment expansion and was merged as commit 42627c1a, making CRAFT_PROJECT_VERSION available during builds.

Evaluated by: mr-cal-bot

No scores available.

Issue body

### Bug Description The `CRAFT_PROJECT_VERSION` depends on the rockcraft.yaml's `version` field and thus should be registered after the YAML is loaded. This should happen in https://github.com/canonical/rockcraft/blob/bdf64517487be2fac8fa28ddfe3919e08f9b3bde/rockcraft/lifecycle.py#L70 however, the callback does not seem to be working and this environment variable never gets loaded. ### To Reproduce Run `rockcraft --verbosity debug` on https://github.com/jnsgruk/zinc-k8s-operator/blob/main/rockcraft.yaml (originally reported by @jnsgruk in https://chat.charmhub.io/charmhub/pl/h9qytisgti8s3pu6yhe1pq8hpy). ### Environment Version: `0+git.bdf6451` ### rockcraft.yaml ```shell name: zinc version: 0.4.7 license: Apache-2.0 base: bare build_base: ubuntu:22.04 platforms: amd64: summary: Zinc is a lightweight search engine and alternative to Elasticsearch. description: | Zinc is a search engine that does full text indexing. It is a lightweight alternative to elasticsearch and runs in less than 100 MB of RAM. It uses bluge as the underlying indexing library. It is very simple and easy to operate as opposed to elasticsearch which requires a couple dozen knobs to understand and tune. It is a drop-in replacement for elasticsearch if you are just ingesting data using APIs and searching using kibana (Kibana is not supported with zinc. Zinc provides its own UI). run_user: _daemon_ environment: ZINC_DATA_PATH: /var/lib/zincsearch ZINC_PROMETHEUS_ENABLE: true ZINC_TELEMETRY: false ZINC_PROFILER: true services: zinc: override: replace startup: enabled command: /bin/go-runner --log-file=/var/lib/zincsearch/zinc.log --also-stdout=true --redirect-stderr=true /bin/zincsearch parts: zinc: plugin: go source: https://github.com/zincsearch/zincsearch source-type: git source-tag: v$CRAFT_PROJECT_VERSION build-snaps: - go/latest/stable - node/18/stable build-environment: - CGO_ENABLED: 0 - GOOS: linux override-build: | COMMIT_HASH="$(git rev-parse HEAD)" BUILD_DATE="$(date -u '+%Y-%m-%d_%I:%M:%S%p-GMT')" # Build the web ui, which is embedded in the go binary later pushd web npm install npm run build popd go mod tidy go build \ -ldflags="-s -w -X github.com/zincsearch/zincsearch/pkg/meta.Version=${CRAFT_PROJECT_VERSION} \ -X github.com/zincsearch/zincsearch/pkg/meta.CommitHash=${COMMIT_HASH} \ -X github.com/zincsearch/zincsearch/pkg/meta.BuildDate=${BUILD_DATE}" \ -o zincsearch \ cmd/zincsearch/main.go stage-packages: - libc6_libs - ca-certificates_data override-stage: | # Create some directories mkdir -p "${CRAFT_PART_INSTALL}/bin" # Install the zincsearch binary install -m 0755 "${CRAFT_PART_BUILD}/zincsearch" "${CRAFT_PART_INSTALL}/bin/zincsearch" # Run the default stage hook craftctl default # This part can be removed once Pebble supports log forwarding kube-log-runner: plugin: go source: https://github.com/kubernetes/release source-type: git source-tag: v0.15.1 source-subdir: images/build/go-runner build-snaps: - go/latest/stable build-environment: - CGO_ENABLED: 0 - GOOS: linux ``` ### Relevant log output ```shell Failed to pull source: command ['git', 'clone', '--recursive', '--branch', 'v$CRAFT_PROJECT_VERSION', 'https://github.com/zincsearch/zincsearch', '/root/parts/zinc/src'] exited with code 128. Recommended resolution: Make sure sources are correctly specified. ```

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Fixed by merged PR #336 (commit 42627c1a), which registers global project variables, including CRAFT_PROJECT_VERSION, before lifecycle steps.
stealth/space-bunny-alpha — closed resolved Fixed by merged PR #336 (commit 42627c1a), which expanded project/global environment variables, including CRAFT_PROJECT_VERSION, before lifecycle steps.
qwen/qwen3.6-35b-a3b — — Closed without documented fix. Reported CRAFT_PROJECT_VERSION failing to register post-YAML parsing, causing git clone failures. Comment clarified reproduction requires explicit variable syntax in source-tag.
qwen/qwen3.6-35b-a3b — — Closed without resolution. The lifecycle.py callback failed to register CRAFT_PROJECT_VERSION, causing unexpanded variable errors during builds. No fix was implemented.
qwen/qwen3.6-35b-a3b — — Closed without a fix or resolution. A maintainer clarified reproduction steps, but the CRAFT_PROJECT_VERSION environment variable registration bug remains unresolved.
qwen3.6-35b-a3b-mtp-q6 — — Closed without a documented fix or linked PR. The discussion only clarifies reproduction steps, indicating the issue was likely abandoned or resolved internally.

Update history

No update history recorded yet.

Related work

  • Likely Fixed By: canonical/rockcraft#336 (confidence 100%)

    Commit 42627c1a is titled "project: global environment expansion (#336)" and implements the resolving change.

Related issues

Issue Project State Summary Similarity
#336 fix global environment expansion rockcraft merged PR #336 (commit 42627c1a) by cjdcordeiro merged, fixing missing global variable expansion so CRAFT_PROJECT_VERSION and other CRAFT_ vars are set before parts lifecycle; project loading now returns YAML for unmarshal.
76%