diff --git a/.github/workflows/build-pkg.yml b/.github/workflows/build-pkg.yml new file mode 100644 index 0000000..f018811 --- /dev/null +++ b/.github/workflows/build-pkg.yml @@ -0,0 +1,125 @@ +name: Build Arch Linux packages + +on: + push: + tags: + - '**' + release: + types: [published] + +permissions: + contents: read + +# Serialize tag/release runs for the same tag to avoid competing asset uploads. +concurrency: + group: build-pkg-${{ github.event.release.tag_name || github.ref_name }} + cancel-in-progress: false + +jobs: + build: + name: archlinux / ${{ matrix.arch }} + strategy: + fail-fast: false + matrix: + include: + # The official Arch Linux image is x86_64 only, so aarch64 uses an + # Arch Linux ARM image that is rebuilt daily. + - arch: x86_64 + runner: ubuntu-24.04 + image: archlinux:base-devel + - arch: aarch64 + runner: ubuntu-24.04-arm + image: menci/archlinuxarm:base-devel + runs-on: ${{ matrix.runner }} + permissions: + contents: write + env: + RELEASE_TAG: ${{ github.event.release.tag_name || github.ref_name }} + steps: + - name: Check out tagged source + uses: actions/checkout@v7 + with: + ref: refs/tags/${{ env.RELEASE_TAG }} + persist-credentials: false + + # Build on a native-architecture runner. Keep release tooling on the + # host, outside the build container. + - name: Build Arch Linux packages + env: + BUILD_IMAGE: ${{ matrix.image }} + BUILD_ARCH: ${{ matrix.arch }} + run: | + host_uid="$(id -u)" + docker run --rm \ + -e BUILD_ARCH -e HOST_UID="$host_uid" \ + -v "$GITHUB_WORKSPACE:/build/ptre" \ + -w /build/ptre "$BUILD_IMAGE" bash -euo pipefail -c ' + test "$(uname -m)" = "$BUILD_ARCH" + # The images ship without a local signing key; create one. + pacman-key --init + pacman-key --populate + # cargo is a virtual package, so pick the rust provider here. + pacman -Syu --noconfirm --needed base-devel rust + + # makepkg refuses to run as root. Use the host UID so the build + # user can write to the checkout and the host can read the output. + useradd -m -u "$HOST_UID" builder + echo "builder ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/builder + + # check() in arch/PKGBUILD also runs the release tests. + cd arch + sudo -u builder makepkg --syncdeps --noconfirm --force + mkdir -p ../dist + cp -- *.pkg.tar.* ../dist/ + # Subsequent workflow steps run as the host runner, not container root. + chown -R "$HOST_UID" ../dist + ' + + - name: Remove debug packages + run: | + shopt -s nullglob + debug_packages=(dist/*-debug-*.pkg.tar.*) + if (( ${#debug_packages[@]} > 0 )); then + printf 'Removing debug symbol packages:\n%s\n' "${debug_packages[@]}" + rm -- "${debug_packages[@]}" + fi + packages=(dist/*.pkg.tar.*) + if (( ${#packages[@]} == 0 )); then + echo '::error::No non-debug Arch Linux packages were built.' + exit 1 + fi + + - name: Save build artifacts + uses: actions/upload-artifact@v4 + with: + name: arch-packages-${{ matrix.arch }} + path: dist/*.pkg.tar.* + if-no-files-found: error + + - name: Upload to the corresponding release if it exists + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + encoded_tag="$(jq -rn --arg tag "$RELEASE_TAG" '$tag | @uri')" + status="$(curl --silent --show-error --retry 3 \ + --output "$RUNNER_TEMP/ptre-release.json" --write-out '%{http_code}' \ + --header "Authorization: Bearer $GH_TOKEN" \ + --header 'Accept: application/vnd.github+json' \ + "$GITHUB_API_URL/repos/$GH_REPO/releases/tags/$encoded_tag")" + case "$status" in + 200) + gh release upload "$RELEASE_TAG" dist/*.pkg.tar.* --clobber + ;; + 404) + if [[ "$GITHUB_EVENT_NAME" == release ]]; then + echo '::error::The triggering release could not be found.' + exit 1 + fi + echo 'No release exists for this tag; packages are available in Actions artifacts.' + ;; + *) + echo "::error::Release lookup failed (HTTP $status)." + exit 1 + ;; + esac diff --git a/.gitignore b/.gitignore index 0728338..dc039ec 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,10 @@ target # Added by cargo - /target + +## Archlinux packaging +arch/src/* +arch/pkg/* +arch/*.pkg.tar.* +arch/*.log diff --git a/.workflow/build-pkg.yml b/.workflow/build-pkg.yml new file mode 100644 index 0000000..abe634b --- /dev/null +++ b/.workflow/build-pkg.yml @@ -0,0 +1,56 @@ +version: "1.0" +name: build-pkg +displayName: Build Arch Linux packages +stages: +- name: Arch Linux x86_64 + displayName: Arch Linux x86_64 + strategy: naturally + trigger: auto + steps: + - step: execute@docker + name: build_pkg + displayName: Build pkg + image: archlinux:base-devel + command: + - set -euo pipefail + - test "$(uname -m)" = x86_64 + - "" + - "# The image ships without a local signing key; create one." + - pacman-key --init + - pacman-key --populate + - "# cargo is a virtual package, so pick the rust provider here." + - pacman -Syu --noconfirm --needed base-devel rust + - "" + - "# makepkg refuses to run as root, so build as a normal user." + - useradd -m builder + - "echo 'builder ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/builder" + - chown -R builder . + - "" + - "# check() in arch/PKGBUILD also runs the release tests." + - (cd arch && sudo -u builder makepkg --syncdeps --noconfirm --force) + - "" + - mkdir -p dist + - for package in arch/*.pkg.tar.*; do + - ' case "$package" in *-debug-*) continue ;; esac' + - ' cp "$package" dist/' + - done + - test -n "$(find dist -maxdepth 1 -name '*.pkg.tar.*' -print -quit)" + artifacts: + - name: PKG_PACKAGES + path: + - dist + type: .tar.gz + - step: publish@general_artifacts + name: publish_pkg + displayName: Publish packages + dependArtifact: PKG_PACKAGES + artifactName: arch-packages-x86_64 +triggers: + trigger: auto + push: + tags: + prefix: + - "" + precise: [] + include: [] +notify: [] diff --git a/README.md b/README.md index 6aacc94..4beb2c6 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,30 @@ $ ./build-deb -c Note that this will also clear the artifacts generated. +#### Archlinux +> **NOTE**: Network connection WILL BE REQUIRED!! + +To build a Arch `zstd` package, simply run: + +```shell +$ ./build-pkg -d +``` + +Dependencies will automatically being installed to your computer. + +Next time you may run: + +```shell +$ ./build-pkg +``` + +To do a cleanup, run: +```shell +$ ./build-pkg -c +``` + +Note that this will also clear the artifacts generated. +

(back to top)

@@ -141,7 +165,7 @@ _For more examples, please refer to the [documentation directory](./doc/)._ - [ ] Provide i18n translations. - [ ] Packaging - [X] Debian. - - [ ] Archlinux. + - [X] Archlinux. - [ ] Fedore/OpenSUSE. - [ ] Nix. - [ ] AmberPM. diff --git a/README.zh.md b/README.zh.md index 0972ab1..6c8e0a7 100644 --- a/README.zh.md +++ b/README.zh.md @@ -104,6 +104,27 @@ $ ./build-deb -c 请注意:执行清理后构建产物会被一并删除。 +#### Archlinux +> **注意**: 您必须在打包期间保持网络连接 + +对于第一次打`zstd`包,请执行: +```bash +$ ./build-pkg -d +``` + +依赖会被自动下载安装至您的系统,下一次只需要执行如下命令即可: + +```bash +$ ./build-pkg +``` + +构建后要清理仓库,请执行: +```bash +$ ./build-pkg -c +``` + +请注意:执行清理后构建产物会被一并删除。 +

(回到顶部)

@@ -136,7 +157,7 @@ _对于更多示例,请访问[文档目录](./doc/)。_ - [ ] 提供国际化翻译 - [ ] 打包 - [X] Debian - - [ ] Archlinux + - [X] Archlinux - [ ] Fedore/OpenSUSE - [ ] Nix - [ ] AmberPM diff --git a/arch/PKGBUILD b/arch/PKGBUILD new file mode 100644 index 0000000..b5debd0 --- /dev/null +++ b/arch/PKGBUILD @@ -0,0 +1,34 @@ +# Maintainer: CharOfString + +pkgname=ptre +pkgver=0.1.4 +pkgrel=1 +pkgdesc='Lightweight text editor' +arch=('x86_64' 'aarch64') +url='https://github.com/CharOfString/ptre' +license=('GPL-3.0-or-later') +depends=('gcc-libs' 'glibc') +makedepends=('cargo') +options=('!lto') + +_cargo() { + export RUSTUP_TOOLCHAIN=stable + export CARGO_TARGET_DIR="$srcdir/target" + cargo "$@" --manifest-path "$startdir/../Cargo.toml" +} + +prepare() { + _cargo fetch --locked --target "$(rustc --print host-tuple)" +} + +build() { + _cargo build --frozen --release +} + +check() { + _cargo test --frozen --release +} + +package() { + install -Dm0755 -t "$pkgdir/usr/bin/" "$srcdir/target/release/$pkgname" +} diff --git a/build-pkg b/build-pkg new file mode 100755 index 0000000..35804ab --- /dev/null +++ b/build-pkg @@ -0,0 +1,158 @@ +#!/bin/bash + +# Copyright (C) 2026 CharOfString +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Build an installable Archlinux package for easy deployment and removal on test machines. +# +# Package details come from arch/PKGBUILD rather than being hard-coded here. +# +# Usage: ./build-arch [options] +# +# Options: +# -d, --install-deps Install build dependencies first, then build. +# -c, --clean Clean build artifacts and exit. +# -h, --help Show help. + +set -o pipefail + +PROJ_ROOT="$(cd "$(dirname "$0")" && pwd)" +ARCH_DIR="$PROJ_ROOT/arch" + +INSTALL_DEPS=false +ACT_CLEANUPS=false + +# Show help. +print_help() { + echo "Usage: $0 [options]" + echo "" + echo "Options:" + echo " -d, --install-deps Install build dependencies from arch/PKGBUILD, then build" + echo " -c, --clean Clean build artifacts and exit" + echo " -h, --help Show this help" + echo "" + echo "Examples:" + echo " $0 -d # Install build dependencies and build" + echo " $0 # Build with dependencies already installed" + echo " $0 -c # Clean build artifacts" + exit 0 +} + +# Parse arguments. +parse_args() { + while [[ $# -gt 0 ]]; do + case $1 in + -c|--clean) + ACT_CLEANUPS=true + shift + ;; + -d|--install-deps) + INSTALL_DEPS=true + shift + ;; + -h|--help) + print_help + ;; + *) + echo "Unknown option: $1" + echo "The following help may be useful:" + print_help + ;; + esac + done +} + +# Check whether a command is available. +is_cmd_exists() { + command -v "$1" &> /dev/null +} + +# Validate the project layout. +detect_project() { + if [[ ! -f "$ARCH_DIR/PKGBUILD" ]]; then + echo "Error: arch/PKGBUILD was not found under $PROJ_ROOT." + echo "Place this script next to arch/ in the project root." + exit 1 + fi + echo "Project root: $PROJ_ROOT" +} + +# Check basic tools; arch/PKGBUILD declares the remaining build dependencies. +check_toolchains() { + echo "Checking basic build tools..." + if ! is_cmd_exists makepkg || ! is_cmd_exists pacman; then + echo "Missing makepkg or pacman. Please run this script on Archlinux." + echo "Try: sudo pacman -S --needed base-devel" + exit 1 + fi + echo "Basic build tools are available." +} + +# Clean build artifacts. +exec_clean() { + echo "Cleaning build artifacts..." + cd "$ARCH_DIR" || exit 1 + + # Remove the packages that makepkg builds, wherever PKGDEST puts them. + local packages=() + mapfile -t packages < <(makepkg --packagelist 2>/dev/null) + rm -f -- "${packages[@]}" + rm -rf src/ pkg/ + + echo "Cleanup complete." +} + +# Build packages. +exec_build() { + local makepkg_args=("-f") + # makepkg -s installs missing dependencies with pacman. + if [[ "$INSTALL_DEPS" == true ]]; then + makepkg_args+=("-s") + fi + # pacman cannot see Rust from the rustup script, so use the cargo on PATH. + if is_cmd_exists cargo && ! pacman -T cargo &> /dev/null; then + echo "Note: cargo was not installed by pacman; skipping the dependency check." + makepkg_args+=("-d") + fi + + cd "$ARCH_DIR" || exit 1 + echo "Building with makepkg (options: ${makepkg_args[*]})..." + makepkg "${makepkg_args[@]}" || exit 1 + + echo "Build complete. Archlinux packages:" + local package + while read -r package; do + if [[ -f "$package" ]]; then + echo " $package" + fi + done < <(makepkg --packagelist) +} + +# Main entry point. +echo "=============================================" +echo " Pointer Arch Build Script REL 1.0.0" +echo "=============================================" +echo "" + +parse_args "$@" +detect_project + +if [[ "$ACT_CLEANUPS" == true ]]; then + exec_clean + exit 0 +fi + +check_toolchains +exec_build diff --git a/src/buffers/terminal/tests.rs b/src/buffers/terminal/tests.rs index 36eda8b..6a1b2e3 100644 --- a/src/buffers/terminal/tests.rs +++ b/src/buffers/terminal/tests.rs @@ -105,10 +105,10 @@ fn status_bar_shows_keys_of_focused_pane() { .collect::() }; app.terminal.visible = true; - assert!(status(&mut app).contains("F10: menu C-c t t: terminal")); + assert!(status(&mut app).contains("F10: menu ※ C-c t t: terminal")); app.terminal.focused = true; let text = status(&mut app); - assert!(text.contains("C-x o: focus M-v/C-v: scroll")); + assert!(text.contains("C-x o: focus ※ M-v/C-v: scroll")); assert!(!text.contains("F10")); }