Skip to content
Merged
Changes from all commits
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
12 changes: 11 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
echo "npm_tag=$NPM_TAG" >> "$GITHUB_OUTPUT"

build-native:
needs: preflight
needs: [preflight, compute-version]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -177,6 +177,16 @@ jobs:
sudo ln -sf /lib/x86_64-linux-gnu/libgcc_s.so.1 "${GNU_LIB}/libgcc_s.so"
sudo ln -sf /lib/x86_64-linux-gnu/libgcc_s.so.1 "${GNU_LIB}/libgcc_s.so.1"

- name: Sync Cargo.toml version
env:
VERSION: ${{ needs.compute-version.outputs.version }}
shell: bash
run: |
[[ -n "$VERSION" ]] || { echo "::error::VERSION is empty — compute-version output missing"; exit 1; }
CARGO="crates/codegraph-core/Cargo.toml"
awk -v v="$VERSION" '!done && /^version =/{$0="version = \""v"\""; done=1}1' "$CARGO" > "${CARGO}.tmp"
mv "${CARGO}.tmp" "$CARGO"
Comment on lines +184 to +188

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 awk replaces all ^version = lines, not just the [package] version

The pattern /^version =/ is a "replace all" in awk (every matching line is rewritten). Currently crates/codegraph-core/Cargo.toml only has one such line so this works, but it would silently corrupt the file the moment a second top-level version = … appears (e.g. a workspace [package.metadata] block, a feature-flag version, etc.).

Compare this with scripts/sync-native-versions.js, which uses a first-match-only replace (no g flag on the regex). For consistency and safety, scope the replacement to the first occurrence only:

Suggested change
run: |
CARGO="crates/codegraph-core/Cargo.toml"
awk -v v="$VERSION" '/^version =/{$0="version = \""v"\""}1' "$CARGO" > "${CARGO}.tmp"
mv "${CARGO}.tmp" "$CARGO"
CARGO="crates/codegraph-core/Cargo.toml"
sed -i.tmp '0,/^version =/{s/^version = "[^"]*"/version = "'"$VERSION"'"/}' "$CARGO"
rm -f "${CARGO}.tmp"

Alternatively, using awk with an early-exit flag after the first replacement:

awk -v v="$VERSION" '!done && /^version =/{$0="version = \""v"\""; done=1}1' "$CARGO" > "${CARGO}.tmp"
mv "${CARGO}.tmp" "$CARGO"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ff3e76a. Added an early-exit flag to the awk command so only the first ^version = line is replaced:

awk -v v="$VERSION" '!done && /^version =/{$0="version = \""v"\""; done=1}1' "$CARGO" > "${CARGO}.tmp"

This matches the first-occurrence-only behavior of scripts/sync-native-versions.js and prevents corruption if a second version = line appears in a different TOML section.

Comment on lines +180 to +188

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No guard against an empty $VERSION value

If compute-version does not produce a version output (e.g. a job failure that somehow still lets downstream jobs proceed, or a future refactor that renames the output key), the awk command will silently write version = "" into Cargo.toml. Cargo will then error with a confusing TOML validation message rather than a clear "version is empty" diagnostic.

A one-line guard at the top of the run block keeps the failure obvious:

Suggested change
- name: Sync Cargo.toml version
env:
VERSION: ${{ needs.compute-version.outputs.version }}
shell: bash
run: |
CARGO="crates/codegraph-core/Cargo.toml"
awk -v v="$VERSION" '/^version =/{$0="version = \""v"\""}1' "$CARGO" > "${CARGO}.tmp"
mv "${CARGO}.tmp" "$CARGO"
- name: Sync Cargo.toml version
env:
VERSION: ${{ needs.compute-version.outputs.version }}
shell: bash
run: |
[[ -n "$VERSION" ]] || { echo "::error::VERSION is empty — compute-version output missing"; exit 1; }
CARGO="crates/codegraph-core/Cargo.toml"
awk -v v="$VERSION" '/^version =/{$0="version = \""v"\""}1' "$CARGO" > "${CARGO}.tmp"
mv "${CARGO}.tmp" "$CARGO"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c43a2e4. Added a guard at the top of the run block:

[[ -n "$VERSION" ]] || { echo "::error::VERSION is empty — compute-version output missing"; exit 1; }

The workflow will now fail immediately with a clear GitHub Actions error annotation if $VERSION is empty, rather than silently writing version = "" into Cargo.toml.


- name: Install napi-rs CLI
run: npm install -g @napi-rs/cli@3

Expand Down
Loading