TheBevyFlock / bevy_new_2d

This template is a great way to get started on a new 2D Bevy game!
https://the-bevy-flock.itch.io/bevy-new-2d
MIT License
172 stars 30 forks source link

CI fails: "the lock file etc/Cargo.lock needs to be updated but --locked was passed to prevent this" #302

Closed zhaop closed 1 month ago

zhaop commented 1 month ago

I followed the README and set up a project with this template. Now on my GitHub repo's actions tab I see Tests, Clippy and Docs all fail:

Tests -> Run tests:

Run cargo test --locked --workspace --all-features --all-targets
  cargo test --locked --workspace --all-features --all-targets
  # Workaround for https://github.com/rust-lang/cargo/issues/6669
  cargo test --locked --workspace --all-features --doc
  shell: /usr/bin/bash -e {0}
  env:
    CARGO_TERM_COLOR: always
    RUSTFLAGS: --deny warnings
    RUSTDOCFLAGS: --deny warnings
    CARGO_HOME: /home/runner/.cargo
    CARGO_INCREMENTAL: 0
    workflow_path: .github/workflows/ci.yaml
    Updating crates.io index
error: the lock file /home/runner/work/projectname/projectname/Cargo.lock needs to be updated but --locked was passed to prevent this
If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
Error: Process completed with exit code 101.

Clippy -> Run clippy lints:

Run cargo clippy --locked --workspace --all-targets --all-features -- --deny warnings
  cargo clippy --locked --workspace --all-targets --all-features -- --deny warnings
  shell: /usr/bin/bash -e {0}
  env:
    CARGO_TERM_COLOR: always
    RUSTFLAGS: --deny warnings
    RUSTDOCFLAGS: --deny warnings
    CARGO_HOME: /home/runner/.cargo
    CARGO_INCREMENTAL: 0
    workflow_path: .github/workflows/ci.yaml
    Updating crates.io index
error: the lock file /home/runner/work/projectname/projectname/Cargo.lock needs to be updated but --locked was passed to prevent this
If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
Error: Process completed with exit code 101.

Docs -> Check documentation:

Run cargo doc --locked --workspace --all-features --document-private-items --no-deps
  cargo doc --locked --workspace --all-features --document-private-items --no-deps
  shell: /usr/bin/bash -e {0}
  env:
    CARGO_TERM_COLOR: always
    RUSTFLAGS: --deny warnings
    RUSTDOCFLAGS: --deny warnings
    CARGO_HOME: /home/runner/.cargo
    CARGO_INCREMENTAL: 0
    workflow_path: .github/workflows/ci.yaml
    Updating crates.io index
error: the lock file /home/runner/work/projectname/projectname/Cargo.lock needs to be updated but --locked was passed to prevent this
If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
Error: Process completed with exit code 101.
benfrankel commented 1 month ago

Related to https://github.com/TheBevyFlock/bevy_quickstart/issues/291.

I suppose when following the README, your initial commit won't include a Cargo.lock file?

EDIT: Actually it looks like it should be included... maybe the current Cargo.lock file is outdated somehow.

zhaop commented 1 month ago

Trying to reproduce this with a public repo this time: https://github.com/zhaop/quickstart-test/actions

Actions are running; and there is a Cargo.lock in there.

EDIT: The same failures are here: https://github.com/zhaop/quickstart-test/actions/runs/10818362101

benfrankel commented 1 month ago

I was able to reproduce this as well, with a fresh cargo generate followed by cargo test --locked. After making an initial commit and running cargo test, the Cargo.lock file does indeed change:

2024-09-11_1726092514_724x745

I believe this could be fixed by adding a post-generate hook that runs cargo update.

This issue (as well as https://github.com/TheBevyFlock/bevy_quickstart/issues/300) highlights the need for a CI workflow that runs cargo generate followed by cargo test etc. in the generated repo. Examples of this can be found in other cargo-generate template repos, including the following:

benfrankel commented 1 month ago

Fixed via documentation, but a better solution would be to run cargo update -p {{project-name}} in a post-generate hook to save one user step.