Skip to content

Commit 5403e74

Browse files
authored
Add callable workflow to bump the version of an extension (zed-industries#43566)
This adds an intial workflow file that can be pulled in to create a bump commit for an extension version in an extension repository. Release Notes: - N/A
1 parent 0713ddc commit 5403e74

File tree

9 files changed

+485
-33
lines changed

9 files changed

+485
-33
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Generated from xtask::workflows::extension_bump
2+
# Rebuild with `cargo xtask workflows`.
3+
name: extension_bump
4+
env:
5+
CARGO_TERM_COLOR: always
6+
RUST_BACKTRACE: '1'
7+
CARGO_INCREMENTAL: '0'
8+
ZED_EXTENSION_CLI_SHA: 7cfce605704d41ca247e3f84804bf323f6c6caaf
9+
on:
10+
workflow_call:
11+
inputs:
12+
bump-type:
13+
description: bump-type
14+
type: string
15+
default: patch
16+
secrets:
17+
app-id:
18+
description: The app ID used to create the PR
19+
required: true
20+
app-secret:
21+
description: The app secret for the corresponding app ID
22+
required: true
23+
jobs:
24+
check_extension:
25+
if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
26+
runs-on: namespace-profile-2x4-ubuntu-2404
27+
steps:
28+
- name: steps::checkout_repo
29+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
30+
with:
31+
clean: false
32+
- id: cache-zed-extension-cli
33+
name: extension_tests::cache_zed_extension_cli
34+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
35+
with:
36+
path: zed-extension
37+
key: zed-extension-${{ env.ZED_EXTENSION_CLI_SHA }}
38+
- name: extension_tests::download_zed_extension_cli
39+
if: steps.cache-zed-extension-cli.outputs.cache-hit != 'true'
40+
run: |
41+
wget --quiet "https://zed-extension-cli.nyc3.digitaloceanspaces.com/$ZED_EXTENSION_CLI_SHA/x86_64-unknown-linux-gnu/zed-extension"
42+
chmod +x zed-extension
43+
shell: bash -euxo pipefail {0}
44+
- name: extension_tests::check
45+
run: |
46+
mkdir -p /tmp/ext-scratch
47+
mkdir -p /tmp/ext-output
48+
./zed-extension --source-dir . --scratch-dir /tmp/ext-scratch --output-dir /tmp/ext-output
49+
shell: bash -euxo pipefail {0}
50+
timeout-minutes: 1
51+
check_bump_needed:
52+
if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
53+
runs-on: namespace-profile-2x4-ubuntu-2404
54+
steps:
55+
- name: steps::checkout_repo
56+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
57+
with:
58+
clean: false
59+
fetch-depth: 10
60+
- id: compare-versions-check
61+
name: extension_bump::compare_versions
62+
run: |+
63+
CURRENT_VERSION="$(sed -n 's/version = \"\(.*\)\"/\1/p' < extension.toml)"
64+
65+
git checkout "$(git log -1 --format=%H)"~1
66+
67+
PREV_COMMIT_VERSION="$(sed -n 's/version = \"\(.*\)\"/\1/p' < extension.toml)"
68+
69+
[[ "$CURRENT_VERSION" == "$PREV_COMMIT_VERSION" ]] && \
70+
echo "needs_bump=true" >> "$GITHUB_OUTPUT" || \
71+
echo "needs_bump=false" >> "$GITHUB_OUTPUT"
72+
73+
shell: bash -euxo pipefail {0}
74+
outputs:
75+
needs_bump: ${{ steps.compare-versions-check.outputs.needs_bump }}
76+
timeout-minutes: 1
77+
bump_extension_version:
78+
needs:
79+
- check_extension
80+
- check_bump_needed
81+
if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions') && needs.check_bump_needed.outputs.needs_bump == 'true'
82+
runs-on: namespace-profile-8x16-ubuntu-2204
83+
steps:
84+
- id: generate-token
85+
name: extension_bump::generate_token
86+
uses: actions/create-github-app-token@v2
87+
with:
88+
app-id: ${{ secrets.app-id }}
89+
private-key: ${{ secrets.app-secret }}
90+
- name: steps::checkout_repo
91+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
92+
with:
93+
clean: false
94+
- name: extension_bump::install_bump_2_version
95+
run: pip install bump2version
96+
shell: bash -euxo pipefail {0}
97+
- id: bump-version
98+
name: extension_bump::bump_version
99+
run: |
100+
OLD_VERSION="$(sed -n 's/version = \"\(.*\)\"/\1/p' < extension.toml)"
101+
102+
cat <<EOF > .bumpversion.cfg
103+
[bumpversion]
104+
current_version = "$OLD_VERSION"
105+
106+
[bumpversion:file:Cargo.toml]
107+
108+
[bumpversion:file:extension.toml]
109+
110+
EOF
111+
112+
bump2version --verbose ${{ inputs.bump-type }}
113+
NEW_VERSION="$(sed -n 's/version = \"\(.*\)\"/\1/p' < extension.toml)"
114+
cargo update --workspace
115+
116+
rm .bumpversion.cfg
117+
118+
echo "old_version=${OLD_VERSION}" >> "$GITHUB_OUTPUT"
119+
echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
120+
shell: bash -euxo pipefail {0}
121+
- name: extension_bump::create_pull_request
122+
uses: peter-evans/create-pull-request@v7
123+
with:
124+
title: Bump version to ${{ steps.bump-version.outputs.new_version }}
125+
body: This PR bumps the version of this extension to v${{ steps.bump-version.outputs.new_version }}
126+
commit-message: Bump version to v${{ steps.bump-version.outputs.new_version }}
127+
branch: bump-from-${{ steps.bump-version.outputs.old_version }}
128+
committer: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
129+
base: main
130+
delete-branch: true
131+
token: ${{ steps.generate-token.outputs.token }}
132+
sign-commits: true
133+
timeout-minutes: 1
134+
concurrency:
135+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
136+
cancel-in-progress: true

tooling/xtask/src/tasks/workflows.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod after_release;
77
mod cherry_pick;
88
mod compare_perf;
99
mod danger;
10+
mod extension_bump;
1011
mod extension_tests;
1112
mod nix_build;
1213
mod release_nightly;
@@ -44,6 +45,7 @@ pub fn run_workflows(_: GenerateWorkflowArgs) -> Result<()> {
4445
("run_agent_evals.yml", run_agent_evals::run_agent_evals()),
4546
("after_release.yml", after_release::after_release()),
4647
("extension_tests.yml", extension_tests::extension_tests()),
48+
("extension_bump.yml", extension_bump::extension_bump()),
4749
];
4850
fs::create_dir_all(dir)
4951
.with_context(|| format!("Failed to create directory: {}", dir.display()))?;

tooling/xtask/src/tasks/workflows/cherry_pick.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use gh_workflow::*;
33
use crate::tasks::workflows::{
44
runners,
55
steps::{self, NamedJob, named},
6-
vars::{self, Input, StepOutput},
6+
vars::{self, StepOutput, WorkflowInput},
77
};
88

99
pub fn cherry_pick() -> Workflow {
10-
let branch = Input::string("branch", None);
11-
let commit = Input::string("commit", None);
12-
let channel = Input::string("channel", None);
13-
let pr_number = Input::string("pr_number", None);
10+
let branch = WorkflowInput::string("branch", None);
11+
let commit = WorkflowInput::string("commit", None);
12+
let channel = WorkflowInput::string("channel", None);
13+
let pr_number = WorkflowInput::string("pr_number", None);
1414
let cherry_pick = run_cherry_pick(&branch, &commit, &channel);
1515
named::workflow()
1616
.run_name(format!("cherry_pick to {channel} #{pr_number}"))
@@ -24,7 +24,11 @@ pub fn cherry_pick() -> Workflow {
2424
.add_job(cherry_pick.name, cherry_pick.job)
2525
}
2626

27-
fn run_cherry_pick(branch: &Input, commit: &Input, channel: &Input) -> NamedJob {
27+
fn run_cherry_pick(
28+
branch: &WorkflowInput,
29+
commit: &WorkflowInput,
30+
channel: &WorkflowInput,
31+
) -> NamedJob {
2832
fn authenticate_as_zippy() -> (Step<Use>, StepOutput) {
2933
let step = named::uses(
3034
"actions",
@@ -39,9 +43,9 @@ fn run_cherry_pick(branch: &Input, commit: &Input, channel: &Input) -> NamedJob
3943
}
4044

4145
fn cherry_pick(
42-
branch: &Input,
43-
commit: &Input,
44-
channel: &Input,
46+
branch: &WorkflowInput,
47+
commit: &WorkflowInput,
48+
channel: &WorkflowInput,
4549
token: &StepOutput,
4650
) -> Step<Run> {
4751
named::bash(&format!("./script/cherry-pick {branch} {commit} {channel}"))

tooling/xtask/src/tasks/workflows/compare_perf.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use crate::tasks::workflows::steps::FluentBuilder;
55
use crate::tasks::workflows::{
66
runners,
77
steps::{self, NamedJob, named},
8-
vars::Input,
8+
vars::WorkflowInput,
99
};
1010

1111
pub fn compare_perf() -> Workflow {
12-
let head = Input::string("head", None);
13-
let base = Input::string("base", None);
14-
let crate_name = Input::string("crate_name", Some("".to_owned()));
12+
let head = WorkflowInput::string("head", None);
13+
let base = WorkflowInput::string("base", None);
14+
let crate_name = WorkflowInput::string("crate_name", Some("".to_owned()));
1515
let run_perf = run_perf(&base, &head, &crate_name);
1616
named::workflow()
1717
.on(Event::default().workflow_dispatch(
@@ -23,8 +23,12 @@ pub fn compare_perf() -> Workflow {
2323
.add_job(run_perf.name, run_perf.job)
2424
}
2525

26-
pub fn run_perf(base: &Input, head: &Input, crate_name: &Input) -> NamedJob {
27-
fn cargo_perf_test(ref_name: &Input, crate_name: &Input) -> Step<Run> {
26+
pub fn run_perf(
27+
base: &WorkflowInput,
28+
head: &WorkflowInput,
29+
crate_name: &WorkflowInput,
30+
) -> NamedJob {
31+
fn cargo_perf_test(ref_name: &WorkflowInput, crate_name: &WorkflowInput) -> Step<Run> {
2832
named::bash(&format!(
2933
"
3034
if [ -n \"{crate_name}\" ]; then
@@ -39,7 +43,7 @@ pub fn run_perf(base: &Input, head: &Input, crate_name: &Input) -> NamedJob {
3943
named::uses("taiki-e", "install-action", "hyperfine")
4044
}
4145

42-
fn compare_runs(head: &Input, base: &Input) -> Step<Run> {
46+
fn compare_runs(head: &WorkflowInput, base: &WorkflowInput) -> Step<Run> {
4347
named::bash(&format!(
4448
"cargo perf-compare --save=results.md {base} {head}"
4549
))

0 commit comments

Comments
 (0)