extension_ci: Merge extension workflow files into one file (#48810)

This PR consolidates the two workflow files shipped to extensions into
one, which stops us from requiring a separate runner for what can
actually be done in one workflow.

It also
- adds a check that version bumps will now only be created by zed-zippy
in separate commits.
- Makes the bumping of versions faster and more reliable.
- (Hopefully) fixes an issue we were seeing in some CI tests.

Release Notes:

- N/A
This commit is contained in:
Finn Evers authored and GitHub committed 2026-02-09 21:18:53 +01:00
1 parent fb0af50553
commit 82dedcbc6c
11 files changed
+221 -269

No files matched your search

@@ -1,12 +1,12 @@
use gh_workflow::{ctx::Context, *};
use indoc::indoc;
use indoc::{formatdoc, indoc};
use crate::tasks::workflows::{
extension_release::extension_workflow_secrets,
extension_tests::{self},
runners,
steps::{
self, CommonJobConditions, DEFAULT_REPOSITORY_OWNER_GUARD, FluentBuilder, NamedJob, named,
self, CommonJobConditions, DEFAULT_REPOSITORY_OWNER_GUARD, FluentBuilder, NamedJob,
checkout_repo, dependant_job, named,
},
vars::{
JobOutput, StepOutput, WorkflowInput, WorkflowSecret, one_workflow_per_non_main_branch,
@@ -23,28 +23,34 @@ pub(crate) fn extension_bump() -> Workflow {
let force_bump = WorkflowInput::bool("force-bump", None);
let (app_id, app_secret) = extension_workflow_secrets();
let (check_bump_needed, needs_bump, current_version) = check_bump_needed();
let (check_version_changed, version_changed, current_version) = check_version_changed();
let needs_bump = needs_bump.as_job_output(&check_bump_needed);
let current_version = current_version.as_job_output(&check_bump_needed);
let version_changed = version_changed.as_job_output(&check_version_changed);
let current_version = current_version.as_job_output(&check_version_changed);
let dependencies = [&check_bump_needed];
let dependencies = [&check_version_changed];
let bump_version = bump_extension_version(
&dependencies,
&current_version,
&bump_type,
&needs_bump,
&version_changed,
&force_bump,
&app_id,
&app_secret,
);
let create_label = create_version_label(
&dependencies,
&needs_bump,
&version_changed,
&current_version,
&app_id,
&app_secret,
);
let trigger_release = trigger_release(
&[&check_version_changed, &create_label],
current_version,
&app_id,
&app_secret,
);
named::workflow()
.add_event(
@@ -69,12 +75,13 @@ pub(crate) fn extension_bump() -> Workflow {
"ZED_EXTENSION_CLI_SHA",
extension_tests::ZED_EXTENSION_CLI_SHA,
))
.add_job(check_bump_needed.name, check_bump_needed.job)
.add_job(check_version_changed.name, check_version_changed.job)
.add_job(bump_version.name, bump_version.job)
.add_job(create_label.name, create_label.job)
.add_job(trigger_release.name, trigger_release.job)
}
fn check_bump_needed() -> (NamedJob, StepOutput, StepOutput) {
fn check_version_changed() -> (NamedJob, StepOutput, StepOutput) {
let (compare_versions, version_changed, current_version) = compare_versions();
let job = Job::default()
@@ -96,7 +103,7 @@ fn check_bump_needed() -> (NamedJob, StepOutput, StepOutput) {
fn create_version_label(
dependencies: &[&NamedJob],
needs_bump: &JobOutput,
version_changed_output: &JobOutput,
current_version: &JobOutput,
app_id: &WorkflowSecret,
app_secret: &WorkflowSecret,
@@ -105,8 +112,9 @@ fn create_version_label(
generate_token(&app_id.to_string(), &app_secret.to_string(), None);
let job = steps::dependant_job(dependencies)
.cond(Expression::new(format!(
"{DEFAULT_REPOSITORY_OWNER_GUARD} && github.event_name == 'push' && github.ref == 'refs/heads/main' && {} == 'false'",
needs_bump.expr(),
"{DEFAULT_REPOSITORY_OWNER_GUARD} && github.event_name == 'push' && \
github.ref == 'refs/heads/main' && {version_changed} == 'true'",
version_changed = version_changed_output.expr(),
)))
.runs_on(runners::LINUX_SMALL)
.timeout_minutes(1u32)
@@ -122,28 +130,24 @@ fn create_version_tag(current_version: &JobOutput, generated_token: StepOutput)
Input::default()
.add(
"script",
format!(
indoc! {r#"
github.rest.git.createRef({{
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v{}',
sha: context.sha
}})"#
},
current_version
),
formatdoc! {r#"
github.rest.git.createRef({{
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v{current_version}',
sha: context.sha
}})"#
},
)
.add("github-token", generated_token.to_string()),
)
}
/// Compares the current and previous commit and checks whether versions changed inbetween.
fn compare_versions() -> (Step<Run>, StepOutput, StepOutput) {
let check_needs_bump = named::bash(format!(
indoc! {
r#"
CURRENT_VERSION="$({})"
pub(crate) fn compare_versions() -> (Step<Run>, StepOutput, StepOutput) {
let check_needs_bump = named::bash(formatdoc! {
r#"
CURRENT_VERSION="$({VERSION_CHECK})"
PR_PARENT_SHA="${{{{ github.event.pull_request.head.sha }}}}"
if [[ -n "$PR_PARENT_SHA" ]]; then
@@ -154,31 +158,29 @@ fn compare_versions() -> (Step<Run>, StepOutput, StepOutput) {
git checkout "$(git log -1 --format=%H)"~1
fi
PARENT_COMMIT_VERSION="$({})"
PARENT_COMMIT_VERSION="$({VERSION_CHECK})"
[[ "$CURRENT_VERSION" == "$PARENT_COMMIT_VERSION" ]] && \
echo "needs_bump=true" >> "$GITHUB_OUTPUT" || \
echo "needs_bump=false" >> "$GITHUB_OUTPUT"
echo "version_changed=false" >> "$GITHUB_OUTPUT" || \
echo "version_changed=true" >> "$GITHUB_OUTPUT"
echo "current_version=${{CURRENT_VERSION}}" >> "$GITHUB_OUTPUT"
"#
},
VERSION_CHECK, VERSION_CHECK
))
})
.id("compare-versions-check");
let needs_bump = StepOutput::new(&check_needs_bump, "needs_bump");
let version_changed = StepOutput::new(&check_needs_bump, "version_changed");
let current_version = StepOutput::new(&check_needs_bump, "current_version");
(check_needs_bump, needs_bump, current_version)
(check_needs_bump, version_changed, current_version)
}
fn bump_extension_version(
dependencies: &[&NamedJob],
current_version: &JobOutput,
bump_type: &WorkflowInput,
needs_bump: &JobOutput,
force_bump: &WorkflowInput,
version_changed_output: &JobOutput,
force_bump_output: &WorkflowInput,
app_id: &WorkflowSecret,
app_secret: &WorkflowSecret,
) -> NamedJob {
@@ -188,9 +190,9 @@ fn bump_extension_version(
let job = steps::dependant_job(dependencies)
.cond(Expression::new(format!(
"{DEFAULT_REPOSITORY_OWNER_GUARD} &&\n({} == 'true' || {} == 'true')",
force_bump.expr(),
needs_bump.expr(),
"{DEFAULT_REPOSITORY_OWNER_GUARD} &&\n({force_bump} == 'true' || {version_changed} == 'false')",
force_bump = force_bump_output.expr(),
version_changed = version_changed_output.expr(),
)))
.runs_on(runners::LINUX_SMALL)
.timeout_minutes(1u32)
@@ -254,32 +256,29 @@ fn install_bump_2_version() -> Step<Run> {
}
fn bump_version(current_version: &JobOutput, bump_type: &WorkflowInput) -> (Step<Run>, StepOutput) {
let step = named::bash(format!(
indoc! {r#"
OLD_VERSION="{}"
let step = named::bash(formatdoc! {r#"
OLD_VERSION="{current_version}"
BUMP_FILES=("extension.toml")
if [[ -f "Cargo.toml" ]]; then
BUMP_FILES+=("Cargo.toml")
fi
BUMP_FILES=("extension.toml")
if [[ -f "Cargo.toml" ]]; then
BUMP_FILES+=("Cargo.toml")
fi
bump2version \
--search "version = \"{{current_version}}"\" \
--replace "version = \"{{new_version}}"\" \
--current-version "$OLD_VERSION" \
--no-configured-files {} "${{BUMP_FILES[@]}}"
bump2version \
--search "version = \"{{current_version}}"\" \
--replace "version = \"{{new_version}}"\" \
--current-version "$OLD_VERSION" \
--no-configured-files {bump_type} "${{BUMP_FILES[@]}}"
if [[ -f "Cargo.toml" ]]; then
cargo update --workspace
fi
if [[ -f "Cargo.toml" ]]; then
cargo update --workspace --offline
fi
NEW_VERSION="$({})"
NEW_VERSION="$({VERSION_CHECK})"
echo "new_version=${{NEW_VERSION}}" >> "$GITHUB_OUTPUT"
"#
},
current_version, bump_type, VERSION_CHECK
))
echo "new_version=${{NEW_VERSION}}" >> "$GITHUB_OUTPUT"
"#
})
.id("bump-version");
let new_version = StepOutput::new(&step, "new_version");
@@ -287,21 +286,18 @@ fn bump_version(current_version: &JobOutput, bump_type: &WorkflowInput) -> (Step
}
fn create_pull_request(new_version: StepOutput, generated_token: StepOutput) -> Step<Use> {
let formatted_version = format!("v{}", new_version);
let formatted_version = format!("v{new_version}");
named::uses("peter-evans", "create-pull-request", "v7").with(
Input::default()
.add("title", format!("Bump version to {}", new_version))
.add("title", format!("Bump version to {new_version}"))
.add(
"body",
format!(
"This PR bumps the version of this extension to {}",
formatted_version
),
format!("This PR bumps the version of this extension to {formatted_version}",),
)
.add(
"commit-message",
format!("Bump version to {}", formatted_version),
format!("Bump version to {formatted_version}"),
)
.add("branch", "zed-zippy-autobump")
.add(
@@ -316,6 +312,65 @@ fn create_pull_request(new_version: StepOutput, generated_token: StepOutput) ->
)
}
fn trigger_release(
dependencies: &[&NamedJob],
version: JobOutput,
app_id: &WorkflowSecret,
app_secret: &WorkflowSecret,
) -> NamedJob {
let extension_registry = RepositoryTarget::new("zed-industries", &["extensions"]);
let (generate_token, generated_token) = generate_token(
&app_id.to_string(),
&app_secret.to_string(),
Some(extension_registry),
);
let (get_extension_id, extension_id) = get_extension_id();
let job = dependant_job(dependencies)
.with_repository_owner_guard()
.runs_on(runners::LINUX_SMALL)
.add_step(generate_token)
.add_step(checkout_repo())
.add_step(get_extension_id)
.add_step(release_action(extension_id, version, generated_token));
named::job(job)
}
fn get_extension_id() -> (Step<Run>, StepOutput) {
let step = named::bash(indoc! {
r#"
EXTENSION_ID="$(sed -n 's/id = \"\(.*\)\"/\1/p' < extension.toml)"
echo "extension_id=${EXTENSION_ID}" >> "$GITHUB_OUTPUT"
"#})
.id("get-extension-id");
let extension_id = StepOutput::new(&step, "extension_id");
(step, extension_id)
}
fn release_action(
extension_id: StepOutput,
version: JobOutput,
generated_token: StepOutput,
) -> Step<Use> {
named::uses("huacnlee", "zed-extension-action", "v2")
.add_with(("extension-name", extension_id.to_string()))
.add_with(("push-to", "zed-industries/extensions"))
.add_with(("tag", format!("v{version}")))
.add_env(("COMMITTER_TOKEN", generated_token.to_string()))
}
fn extension_workflow_secrets() -> (WorkflowSecret, WorkflowSecret) {
let app_id = WorkflowSecret::new("app-id", "The app ID used to create the PR");
let app_secret =
WorkflowSecret::new("app-secret", "The app secret for the corresponding app ID");
(app_id, app_secret)
}
pub(crate) struct RepositoryTarget {
owner: Option<String>,
repositories: Option<String>,
@@ -1,75 +0,0 @@
use gh_workflow::{Event, Job, Run, Step, Use, Workflow, WorkflowCall};
use indoc::indoc;
use crate::tasks::workflows::{
extension_bump::{RepositoryTarget, generate_token},
runners,
steps::{CommonJobConditions, NamedJob, checkout_repo, named},
vars::{StepOutput, WorkflowSecret},
};
pub(crate) fn extension_release() -> Workflow {
let (app_id, app_secret) = extension_workflow_secrets();
let create_release = create_release(&app_id, &app_secret);
named::workflow()
.on(
Event::default().workflow_call(WorkflowCall::default().secrets([
(app_id.name.to_owned(), app_id.secret_configuration()),
(
app_secret.name.to_owned(),
app_secret.secret_configuration(),
),
])),
)
.add_job(create_release.name, create_release.job)
}
fn create_release(app_id: &WorkflowSecret, app_secret: &WorkflowSecret) -> NamedJob {
let extension_registry = RepositoryTarget::new("zed-industries", &["extensions"]);
let (generate_token, generated_token) = generate_token(
&app_id.to_string(),
&app_secret.to_string(),
Some(extension_registry),
);
let (get_extension_id, extension_id) = get_extension_id();
let job = Job::default()
.with_repository_owner_guard()
.runs_on(runners::LINUX_SMALL)
.add_step(generate_token)
.add_step(checkout_repo())
.add_step(get_extension_id)
.add_step(release_action(extension_id, generated_token));
named::job(job)
}
fn get_extension_id() -> (Step<Run>, StepOutput) {
let step = named::bash(indoc! {
r#"
EXTENSION_ID="$(sed -n 's/id = \"\(.*\)\"/\1/p' < extension.toml)"
echo "extension_id=${EXTENSION_ID}" >> "$GITHUB_OUTPUT"
"#})
.id("get-extension-id");
let extension_id = StepOutput::new(&step, "extension_id");
(step, extension_id)
}
fn release_action(extension_id: StepOutput, generated_token: StepOutput) -> Step<Use> {
named::uses("huacnlee", "zed-extension-action", "v2")
.add_with(("extension-name", extension_id.to_string()))
.add_with(("push-to", "zed-industries/extensions"))
.add_env(("COMMITTER_TOKEN", generated_token.to_string()))
}
pub(crate) fn extension_workflow_secrets() -> (WorkflowSecret, WorkflowSecret) {
let app_id = WorkflowSecret::new("app-id", "The app ID used to create the PR");
let app_secret =
WorkflowSecret::new("app-secret", "The app secret for the corresponding app ID");
(app_id, app_secret)
}
@@ -1,7 +1,8 @@
use gh_workflow::*;
use indoc::indoc;
use indoc::{formatdoc, indoc};
use crate::tasks::workflows::{
extension_bump::compare_versions,
run_tests::{orchestrate_without_package_filter, tests_pass},
runners,
steps::{self, CommonJobConditions, FluentBuilder, NamedJob, named},
@@ -58,7 +59,7 @@ fn run_clippy() -> Step<Run> {
fn check_rust() -> NamedJob {
let job = Job::default()
.with_repository_owner_guard()
.runs_on(runners::LINUX_LARGE)
.runs_on(runners::LINUX_LARGE_RAM)
.timeout_minutes(6u32)
.add_step(steps::checkout_repo())
.add_step(steps::cache_rust_dependencies_namespace())
@@ -78,6 +79,8 @@ fn check_rust() -> NamedJob {
pub(crate) fn check_extension() -> NamedJob {
let (cache_download, cache_hit) = cache_zed_extension_cli();
let (check_version_job, version_changed, _) = compare_versions();
let job = Job::default()
.with_repository_owner_guard()
.runs_on(runners::LINUX_LARGE_RAM)
@@ -85,7 +88,9 @@ pub(crate) fn check_extension() -> NamedJob {
.add_step(steps::checkout_repo())
.add_step(cache_download)
.add_step(download_zed_extension_cli(cache_hit))
.add_step(check());
.add_step(check())
.add_step(check_version_job)
.add_step(verify_version_did_not_change(version_changed));
named::job(job)
}
@@ -126,3 +131,14 @@ pub fn check() -> Step<Run> {
"#
})
}
fn verify_version_did_not_change(version_changed: StepOutput) -> Step<Run> {
named::bash(formatdoc! {r#"
if [[ {version_changed} == "true" && "${{{{ github.event_name }}}}" == "pull_request" && "${{{{ github.event.pull_request.user.login }}}}" != "zed-zippy[bot]" ]] ; then
echo "Version change detected in your change!"
echo "Version changes happen in separate PRs and will be performed by the zed-zippy bot"
exit 42
fi
"#
})
}
@@ -4,7 +4,6 @@ use indexmap::IndexMap;
use crate::tasks::workflows::vars;
pub(crate) mod bump_version;
pub(crate) mod release_version;
pub(crate) mod run_tests;
pub(crate) trait WithAppSecrets: Sized {
@@ -2,13 +2,13 @@ use gh_workflow::{
Event, Expression, Input, Job, Level, Permissions, PullRequest, PullRequestType, Push, Run,
Step, UsesJob, Workflow, WorkflowDispatch,
};
use indexmap::IndexMap;
use indoc::indoc;
use crate::tasks::workflows::{
extensions::WithAppSecrets,
runners,
steps::{CommonJobConditions, NamedJob, named},
vars::{self, JobOutput, StepOutput, one_workflow_per_non_main_branch_and_token},
vars::{JobOutput, StepOutput, one_workflow_per_non_main_branch_and_token},
};
pub(crate) fn bump_version() -> Workflow {
@@ -59,13 +59,7 @@ pub(crate) fn call_bump_version(
.add("bump-type", bump_type.to_string())
.add("force-bump", true),
)
.secrets(IndexMap::from([
("app-id".to_owned(), vars::ZED_ZIPPY_APP_ID.to_owned()),
(
"app-secret".to_owned(),
vars::ZED_ZIPPY_APP_PRIVATE_KEY.to_owned(),
),
]));
.with_app_secrets();
named::job(job)
}
@@ -1,31 +0,0 @@
use gh_workflow::{Event, Job, Level, Permissions, Push, UsesJob, Workflow};
use crate::tasks::workflows::{
extensions::WithAppSecrets,
steps::{NamedJob, named},
};
pub(crate) fn release_version() -> Workflow {
let create_release = call_release_version();
named::workflow()
.on(Event::default().push(Push::default().add_tag("v**")))
.add_job(create_release.name, create_release.job)
}
pub(crate) fn call_release_version() -> NamedJob<UsesJob> {
let job = Job::default()
.permissions(
Permissions::default()
.contents(Level::Write)
.pull_requests(Level::Write),
)
.uses(
"zed-industries",
"zed",
".github/workflows/extension_release.yml",
"main",
)
.with_app_secrets();
named::job(job)
}