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
125 changes: 125 additions & 0 deletions .github/workflows/build-pkg.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ target


# Added by cargo

/target

## Archlinux packaging
arch/src/*
arch/pkg/*
arch/*.pkg.tar.*
arch/*.log
56 changes: 56 additions & 0 deletions .workflow/build-pkg.yml
Original file line number Diff line number Diff line change
@@ -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: []
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<p align="right">(<a href="#readme-top">back to top</a>)</p>


Expand Down Expand Up @@ -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.
Expand Down
23 changes: 22 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ $ ./build-deb -c

请注意:执行清理后构建产物会被一并删除。

#### Archlinux
> **注意**: 您必须在打包期间保持网络连接

对于第一次打`zstd`包,请执行:
```bash
$ ./build-pkg -d
```

依赖会被自动下载安装至您的系统,下一次只需要执行如下命令即可:

```bash
$ ./build-pkg
```

构建后要清理仓库,请执行:
```bash
$ ./build-pkg -c
```

请注意:执行清理后构建产物会被一并删除。

<p align="right">(<a href="#readme-top">回到顶部</a>)</p>


Expand Down Expand Up @@ -136,7 +157,7 @@ _对于更多示例,请访问[文档目录](./doc/)。_
- [ ] 提供国际化翻译
- [ ] 打包
- [X] Debian
- [ ] Archlinux
- [X] Archlinux
- [ ] Fedore/OpenSUSE
- [ ] Nix
- [ ] AmberPM
Expand Down
34 changes: 34 additions & 0 deletions arch/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Maintainer: CharOfString <root@charofstring.cc>

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"
}
Loading
Loading