forge
Explore
Log in

Don't you dare go Hollow

Pushing an annotated tag starts its CI run: the pushed tag object is peeled to its commit before the workflow is read, so the run, its statuses and any release are for that commit (pull mirror tag updates take the same path) ✅ test: an annotated v* tag starts a run on the commit under it

Browse files at this commit

7d1f5e9c726f356926e3b2800a21145f82b8b484Ahmet Kaan GümüşParent: c71bf40
All checks have passed
Show checks
  • fix
    • pushing an annotated tag starts its CI run: the pushed tag object is peeled to its commit before the workflow is read, so the run, its statuses and any release are for that commit (pull mirror tag updates take the same path) ✅ test: an annotated v* tag starts a run on the commit under it
Show full message
🐛 fix: pushing an annotated tag starts its CI run: the pushed tag object is peeled to its commit before the workflow is read, so the run, its statuses and any release are for that commit (pull mirror tag updates take the same path) ✅ test: an annotated v* tag starts a run on the commit under it
crates/forge-git/src/browse.rsmodified+13 -0
@@ -191,6 +191,19 @@ pub fn default_branch_commit(repo: &Path, branch: &str) -> Result<Option<String>
191191 Ok(is_commit(&repo, id)?.then(|| id.to_hex().to_string()))
192192 }
193193
194+/// The commit a full object id names, peeling annotated tags (a pushed `git tag -a` points its
195+/// ref at a tag object). None when the object is missing or does not peel to a commit.
196+pub fn peel_to_commit(repo: &Path, oid: &str) -> Result<Option<String>> {
197+ let repo = open(repo)?;
198+ let Some(object) = repo.try_find_object(parse_oid(oid)?).map_err(gerr)? else {
199+ return Ok(None);
200+ };
201+ Ok(object
202+ .peel_to_commit()
203+ .ok()
204+ .map(|c| c.id.to_hex().to_string()))
205+}
206+
194207 /// Resolve user input to a full commit oid. Accepts a branch or tag name, or a 4-64 char hex prefix
195208 /// that matches exactly one commit. Anything else resolves to None.
196209 pub fn resolve_commit(repo: &Path, rev: &str) -> Result<Option<String>> {
crates/forge-web/src/ci/schedule.rsmodified+53 -1
@@ -9,7 +9,7 @@ use forge_core::authz::{Action, authorize};
99 use forge_core::ci::{CiRun, NewJob};
1010 use forge_core::store::commit_status::StatusState;
1111 use forge_core::{PullRequest, Repo};
12-use forge_git::browse::{read_blob, resolve_commit};
12+use forge_git::browse::{peel_to_commit, read_blob, resolve_commit};
1313 use tokio::io::AsyncWriteExt;
1414
1515 use super::api::fit_to_cap;
@@ -84,6 +84,12 @@ pub async fn on_ref_update(
8484 return;
8585 };
8686 let result = async {
87+ // An annotated tag's ref names a tag object: the run, its statuses and any release are
88+ // for the commit it points at.
89+ let Some(commit) = peeled_commit(state, &repo.id, new_oid).await else {
90+ return forge_core::Result::Ok(());
91+ };
92+ let new_oid = commit.as_str();
8793 let loaded = load(state, &repo.id, new_oid).await;
8894 if let Plan::Run {
8995 jobs,
@@ -515,6 +521,26 @@ pub(super) async fn config_at(state: &AppState, repo_id: &str, commit: &str) ->
515521 }
516522 }
517523
524+/// The commit `oid` peels to, logging why when it names none.
525+async fn peeled_commit(state: &AppState, repo_id: &str, oid: &str) -> Option<String> {
526+ let dir = match forge_git::repo::repo_path(&state.git.data_dir, repo_id) {
527+ Ok(path) => path,
528+ Err(e) => {
529+ tracing::error!(error = %e, repo_id, "ci: bad repo path");
530+ return None;
531+ }
532+ };
533+ let rev = oid.to_owned();
534+ match blocking(move || peel_to_commit(&dir, &rev)).await {
535+ Ok(Some(commit)) => Some(commit),
536+ Ok(None) => None, // a tag on a tree or blob: nothing to build
537+ Err(e) => {
538+ tracing::error!(error = %e, repo_id, oid, "ci: peeling the pushed ref failed");
539+ None
540+ }
541+ }
542+}
543+
518544 async fn load(state: &AppState, repo_id: &str, commit: &str) -> Loaded {
519545 let repo_dir = match forge_git::repo::repo_path(&state.git.data_dir, repo_id) {
520546 Ok(path) => path,
@@ -947,6 +973,32 @@ run = "make"
947973 .expect("run");
948974 assert_eq!(run.trigger, "tag");
949975 assert_eq!(run.git_ref, "refs/tags/v1.0");
976+
977+ // An annotated tag's ref names a tag object; the run is for the commit under it.
978+ let head = commit(&fx.work, &[(CONFIG_PATH, CONFIG_TAGS)]);
979+ git(&fx.work, &["tag", "-a", "v2.0", "-m", "v2.0"]);
980+ let tag_obj = git(&fx.work, &["rev-parse", "v2.0"]);
981+ assert_ne!(tag_obj, head);
982+ land(&fx, &tag_obj, "refs/tags/v2.0");
983+ after_ref_update(
984+ &fx.state,
985+ &fx.repo,
986+ &fx.owner.id,
987+ "refs/tags/v2.0",
988+ ZERO,
989+ &tag_obj,
990+ )
991+ .await
992+ .expect("post update");
993+ assert_eq!(runs_total(&fx).await, 3);
994+ let run = fx
995+ .state
996+ .store
997+ .run_by_number(&fx.repo.id, 3)
998+ .await
999+ .expect("query")
1000+ .expect("run");
1001+ assert_eq!(run.commit_oid, head);
9501002 }
9511003
9521004 /// Opens a pull request `author` -> `branch` whose head repo is `head_repo_id`, and runs the