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>
191 Ok(is_commit(&repo, id)?.then(|| id.to_hex().to_string()))191 Ok(is_commit(&repo, id)?.then(|| id.to_hex().to_string()))
192 }192 }
193 193
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+
194 /// Resolve user input to a full commit oid. Accepts a branch or tag name, or a 4-64 char hex prefix207 /// Resolve user input to a full commit oid. Accepts a branch or tag name, or a 4-64 char hex prefix
195 /// that matches exactly one commit. Anything else resolves to None.208 /// that matches exactly one commit. Anything else resolves to None.
196 pub fn resolve_commit(repo: &Path, rev: &str) -> Result<Option<String>> {209 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};
9 use forge_core::ci::{CiRun, NewJob};9 use forge_core::ci::{CiRun, NewJob};
10 use forge_core::store::commit_status::StatusState;10 use forge_core::store::commit_status::StatusState;
11 use forge_core::{PullRequest, Repo};11 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};
13 use tokio::io::AsyncWriteExt;13 use tokio::io::AsyncWriteExt;
14 14
15 use super::api::fit_to_cap;15 use super::api::fit_to_cap;
@@ -84,6 +84,12 @@ pub async fn on_ref_update(
84 return;84 return;
85 };85 };
86 let result = async {86 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();
87 let loaded = load(state, &repo.id, new_oid).await;93 let loaded = load(state, &repo.id, new_oid).await;
88 if let Plan::Run {94 if let Plan::Run {
89 jobs,95 jobs,
@@ -515,6 +521,26 @@ pub(super) async fn config_at(state: &AppState, repo_id: &str, commit: &str) ->
515 }521 }
516 }522 }
517 523
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+
518 async fn load(state: &AppState, repo_id: &str, commit: &str) -> Loaded {544 async fn load(state: &AppState, repo_id: &str, commit: &str) -> Loaded {
519 let repo_dir = match forge_git::repo::repo_path(&state.git.data_dir, repo_id) {545 let repo_dir = match forge_git::repo::repo_path(&state.git.data_dir, repo_id) {
520 Ok(path) => path,546 Ok(path) => path,
@@ -947,6 +973,32 @@ run = "make"
947 .expect("run");973 .expect("run");
948 assert_eq!(run.trigger, "tag");974 assert_eq!(run.trigger, "tag");
949 assert_eq!(run.git_ref, "refs/tags/v1.0");975 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);
950 }1002 }
951 1003
952 /// Opens a pull request `author` -> `branch` whose head repo is `head_repo_id`, and runs the1004 /// Opens a pull request `author` -> `branch` whose head repo is `head_repo_id`, and runs the