Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ env:
CARGO_TERM_COLOR: always

jobs:
pr-linux-release-build:
name: PR Linux release build
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: x86_64-unknown-linux-gnu

- name: Build Linux release binary
run: cargo build --release --target x86_64-unknown-linux-gnu

test:
name: Test
runs-on: ubuntu-latest
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/publish-npm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ name: Publish npm

on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main

permissions:
contents: read
Expand Down
89 changes: 88 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ permissions:
# If there's a prerelease-style suffix to the version, then the release(s)
# will be marked as a prerelease.
on:
pull_request:
push:
tags:
- '**[0-9]+.[0-9]+.[0-9]+*'
Expand All @@ -60,6 +59,28 @@ jobs:
with:
persist-credentials: false
submodules: recursive
- name: Sync Cargo.toml version from tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Unsupported tag version: ${GITHUB_REF_NAME}"
exit 1
fi
python3 - <<'PY'
import os
import re
from pathlib import Path

version = os.environ["GITHUB_REF_NAME"][1:]
cargo_toml = Path("Cargo.toml")
text = cargo_toml.read_text()
updated = re.sub(r'^version = ".*"$', f'version = "{version}"', text, count=1, flags=re.MULTILINE)
cargo_toml.write_text(updated)
print(f"Set Cargo.toml package version to {version}")
PY
- name: Install dist
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
Expand Down Expand Up @@ -120,6 +141,28 @@ jobs:
with:
persist-credentials: false
submodules: recursive
- name: Sync Cargo.toml version from tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Unsupported tag version: ${GITHUB_REF_NAME}"
exit 1
fi
python3 - <<'PY'
import os
import re
from pathlib import Path

version = os.environ["GITHUB_REF_NAME"][1:]
cargo_toml = Path("Cargo.toml")
text = cargo_toml.read_text()
updated = re.sub(r'^version = ".*"$', f'version = "{version}"', text, count=1, flags=re.MULTILINE)
cargo_toml.write_text(updated)
print(f"Set Cargo.toml package version to {version}")
PY
- name: Install Rust non-interactively if not already installed
if: ${{ matrix.container }}
run: |
Expand Down Expand Up @@ -179,6 +222,28 @@ jobs:
with:
persist-credentials: false
submodules: recursive
- name: Sync Cargo.toml version from tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Unsupported tag version: ${GITHUB_REF_NAME}"
exit 1
fi
python3 - <<'PY'
import os
import re
from pathlib import Path

version = os.environ["GITHUB_REF_NAME"][1:]
cargo_toml = Path("Cargo.toml")
text = cargo_toml.read_text()
updated = re.sub(r'^version = ".*"$', f'version = "{version}"', text, count=1, flags=re.MULTILINE)
cargo_toml.write_text(updated)
print(f"Set Cargo.toml package version to {version}")
PY
- name: Install cached dist
uses: actions/download-artifact@v7
with:
Expand Down Expand Up @@ -229,6 +294,28 @@ jobs:
with:
persist-credentials: false
submodules: recursive
- name: Sync Cargo.toml version from tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Unsupported tag version: ${GITHUB_REF_NAME}"
exit 1
fi
python3 - <<'PY'
import os
import re
from pathlib import Path

version = os.environ["GITHUB_REF_NAME"][1:]
cargo_toml = Path("Cargo.toml")
text = cargo_toml.read_text()
updated = re.sub(r'^version = ".*"$', f'version = "{version}"', text, count=1, flags=re.MULTILINE)
cargo_toml.write_text(updated)
print(f"Set Cargo.toml package version to {version}")
PY
- name: Install cached dist
uses: actions/download-artifact@v7
with:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Close stale issues and pull requests

on:
schedule:
- cron: "30 1 * * *"
workflow_dispatch:

permissions:
issues: write
pull-requests: write

jobs:
stale:
runs-on: ubuntu-latest
steps:
- name: Mark stale issues and pull requests
uses: actions/stale@v10
2 changes: 2 additions & 0 deletions dist-workspace.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ members = ["cargo:."]
[dist]
# The preferred dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.31.0"
# Allow local customizations to generated CI workflow without forcing dist init
allow-dirty = ["ci"]
# CI backends to support
ci = "github"
# The installers to generate for each app
Expand Down
86 changes: 0 additions & 86 deletions src/tmux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,29 +183,6 @@ pub fn tmux_list_sessions() -> Vec<TmuxSession> {
sessions
}

pub fn tmux_capture_pane(session_name: &str, lines: usize) -> Result<String> {
let start = format!("-{lines}");
let output = tmux_command()
.args(capture_pane_window_args(session_name, &start))
.output()
.context("failed to run tmux capture-pane")?;

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
if stderr.contains("can't find window: 0") {
let retry = tmux_command()
.args(capture_pane_session_args(session_name, &start))
.output()
.context("failed to rerun tmux capture-pane")?;
ensure_success(&retry, "capture-pane")?;
return Ok(String::from_utf8_lossy(&retry.stdout).to_string());
}
}

ensure_success(&output, "capture-pane")
.map(|_| String::from_utf8_lossy(&output.stdout).to_string())
}

pub fn tmux_get_pane_pid(session_name: &str) -> Option<u32> {
let output = tmux_command()
.args(list_panes_args(session_name))
Expand Down Expand Up @@ -392,28 +369,6 @@ fn list_sessions_args() -> Vec<String> {
]
}

fn capture_pane_window_args(session_name: &str, start: &str) -> Vec<String> {
vec![
"capture-pane".to_string(),
"-t".to_string(),
format!("{session_name}:0.0"),
"-p".to_string(),
"-S".to_string(),
start.to_string(),
]
}

fn capture_pane_session_args(session_name: &str, start: &str) -> Vec<String> {
vec![
"capture-pane".to_string(),
"-t".to_string(),
session_name.to_string(),
"-p".to_string(),
"-S".to_string(),
start.to_string(),
]
}

fn list_panes_args(session_name: &str) -> Vec<String> {
vec![
"list-panes".to_string(),
Expand Down Expand Up @@ -691,22 +646,6 @@ mod tests {
);
}

#[test]
fn test_capture_pane_window_args_builder() {
assert_eq!(
capture_pane_window_args("ok-test", "-50"),
vec!["capture-pane", "-t", "ok-test:0.0", "-p", "-S", "-50"]
);
}

#[test]
fn test_capture_pane_session_args_builder() {
assert_eq!(
capture_pane_session_args("ok-test", "-50"),
vec!["capture-pane", "-t", "ok-test", "-p", "-S", "-50"]
);
}

#[test]
fn test_list_panes_args_builder() {
assert_eq!(
Expand Down Expand Up @@ -744,31 +683,6 @@ mod tests {
assert!(!tmux_session_exists(&session_name));
}

#[test]
fn test_tmux_capture_pane() {
if !tmux_available() {
return;
}
let session_name = unique_session_name("capture");
let _cleanup = SessionCleanup::new(session_name.clone());

tmux_create_session(
&session_name,
Path::new("."),
Some("printf 'line-one\\nline-two\\n'; sleep 2"),
)
.expect("create session should succeed");

assert!(wait_for_session(&session_name, Duration::from_secs(2)));
let captured = tmux_capture_pane(&session_name, 20).expect("capture should succeed");
assert!(captured.contains("line-one"));
assert!(captured.contains("line-two"));

if tmux_session_exists(&session_name) {
let _ = tmux_kill_session(&session_name);
}
}

fn tmux_available() -> bool {
Command::new("tmux")
.arg("-V")
Expand Down