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. +
@@ -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