Skip to content

Commit

Permalink
Fix examples manifest version detection (#3863)
Browse files Browse the repository at this point in the history
### What

Continued from #3859

- `ref` is no longer set to `github.sha` by default, because that checks
out a commit. Instead it's left empty, which checks out the branch +
uses the merge commit on PRs and head commit on `push`.
- Also fix how we detect branch name in `re_build_tools`, it defaults to
`GITHUB_REF` if it exists, otherwise it runs the command as it did
before. `GITHUB_REF` is set when a workflow starts, and contains the
fully-formed ref of the branch that the workflow was started on, e.g.
`refs/heads/jan/fix-exmaples/manifest-version` - we can parse the branch
name from that.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3863) (if
applicable)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/3863)
- [Docs
preview](https://rerun.io/preview/a0f00e401d830d472b7df6f0144a22e4b1ff4139/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/a0f00e401d830d472b7df6f0144a22e4b1ff4139/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
  • Loading branch information
jprochazk and emilk authored Oct 16, 2023
1 parent 6d8c4a9 commit fb797e4
Show file tree
Hide file tree
Showing 22 changed files with 108 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checkboxes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Python
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_build_and_test_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:

- uses: actions/checkout@v4
with:
ref: ${{ inputs.RELEASE_COMMIT || ((github.event_name == 'pull_request' && github.event.pull_request.head.ref) || github.sha) }}
ref: ${{ inputs.RELEASE_COMMIT || ((github.event_name == 'pull_request' && github.event.pull_request.head.ref) || '') }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_build_and_upload_rerun_c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:

- uses: actions/checkout@v4
with:
ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.ref) || github.sha }}
ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.ref) || '' }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_build_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_build_web_demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.ref) || github.sha }}
ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.ref) || '' }}

- name: Download Web Viewer
uses: actions/download-artifact@v3
Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/reusable_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- uses: extractions/setup-just@v1
env:
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand Down Expand Up @@ -267,7 +267,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Install taplo-cli
uses: taiki-e/install-action@v2
Expand All @@ -286,7 +286,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -329,7 +329,7 @@ jobs:
- name: Checkout Actions Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Check spelling of entire workspace
uses: crate-ci/typos@master
Expand All @@ -344,7 +344,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Cargo Deny
shell: bash
Expand All @@ -359,7 +359,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Run clang format on all relevant files
uses: jidicula/clang-format-action@v4.11.0
Expand All @@ -378,7 +378,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand All @@ -400,3 +400,4 @@ jobs:
- name: Build doc-code examples
shell: bash
run: ./docs/code-examples/cpp_build_all.sh --werror

6 changes: 3 additions & 3 deletions .github/workflows/reusable_deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Don't do a shallow clone
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha) }}
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || '') }}

- name: Set up Python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Don't do a shallow clone since we need to push gh-pages
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha) }}
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || '') }}

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha) }}
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || '') }}

- name: Re-deploy rerun.io
uses: ./.github/actions/deploy-vercel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_pip_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha) }}
ref: ${{ inputs.COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || '') }}

- name: Set up Python
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_pr_summary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Python
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_release_crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha) }}
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || '') }}

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_run_notebook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Download Wheel Artifact
uses: actions/download-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_track_size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Get context
id: context
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_update_pr_body.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Python
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_upload_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Download RRD
uses: actions/download-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_upload_web_demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Download web demo assets
uses: actions/download-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_upload_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- uses: actions/checkout@v4
with:
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha) }}
ref: ${{ inputs.RELEASE_COMMIT || (github.event_name == 'pull_request' && github.event.pull_request.head.ref || '') }}

- name: Download RRD
uses: actions/download-artifact@v3
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 29 additions & 3 deletions crates/re_build_tools/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,42 @@ pub fn rebuild_if_branch_or_commit_changes() {
}
}

pub fn commit_hash() -> anyhow::Result<String> {
/// Get the full commit hash
pub fn git_commit_hash() -> anyhow::Result<String> {
let git_hash = run_command("git", &["rev-parse", "HEAD"])?;
if git_hash.is_empty() {
anyhow::bail!("empty commit hash");
}
Ok(git_hash)
}

pub fn branch() -> anyhow::Result<String> {
run_command("git", &["symbolic-ref", "--short", "HEAD"])
/// Get the first 7 characters of the commit hash
pub fn git_commit_short_hash() -> anyhow::Result<String> {
Ok(git_commit_hash()?[0..7].to_string())
}

fn parse_branch_from_github_ref() -> Option<String> {
// The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>,
// for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>.
// For example, refs/heads/feature-branch-1.
// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

let github_ref = std::env::var("GITHUB_REF").ok()?;
let branch = github_ref
.strip_prefix("refs/")?
.split_once('/')?
.1
.to_owned();
Some(branch)
}

/// Get the current git branch name
pub fn git_branch() -> anyhow::Result<String> {
if let Some(branch) = parse_branch_from_github_ref() {
Ok(branch)
} else {
run_command("git", &["symbolic-ref", "--short", "HEAD"])
}
}

/// From <https://git-scm.com/docs/git-rev-parse>:
Expand Down
16 changes: 14 additions & 2 deletions crates/re_build_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod rebuild_detector;

pub(crate) use self::rebuild_detector::Packages;

pub use self::git::{git_branch, git_commit_hash, git_commit_short_hash};
pub use self::hashing::{
compute_crate_hash, compute_dir_filtered_hash, compute_dir_hash, compute_file_hash,
compute_strings_hash, iter_dir, read_versioning_hash, write_versioning_hash,
Expand Down Expand Up @@ -142,8 +143,14 @@ pub fn export_build_info_vars_for_crate(crate_name: &str) {
}

if export_git_info {
set_env("RE_BUILD_GIT_HASH", &git::commit_hash().unwrap_or_default());
set_env("RE_BUILD_GIT_BRANCH", &git::branch().unwrap_or_default());
set_env(
"RE_BUILD_GIT_HASH",
&git::git_commit_hash().unwrap_or_default(),
);
set_env(
"RE_BUILD_GIT_BRANCH",
&git::git_branch().unwrap_or_default(),
);

// Make sure the above are up-to-date
git::rebuild_if_branch_or_commit_changes();
Expand Down Expand Up @@ -249,3 +256,8 @@ fn rust_llvm_versions() -> anyhow::Result<(String, String)> {
llvm_version.unwrap_or_else(|| "unknown".to_owned()),
))
}

/// Returns info parsed from an invocation of the `cargo metadata` command
pub fn cargo_metadata() -> anyhow::Result<cargo_metadata::Metadata> {
Ok(cargo_metadata::MetadataCommand::new().exec()?)
}
2 changes: 1 addition & 1 deletion crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ web-sys = { workspace = true, features = ["Window"] }
re_build_tools.workspace = true

# External
anyhow.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
serde_yaml.workspace = true
xshell.workspace = true
Loading

0 comments on commit fb797e4

Please sign in to comment.