Build Debian package #1299
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Debian package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| archivebox_version: | |
| description: "Exact ArchiveBox version" | |
| required: true | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: debian-archivebox | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: Resolve ArchiveBox version | |
| run: | | |
| set -Eeuo pipefail | |
| VERSION="${{ inputs.archivebox_version }}" | |
| test -n "$VERSION" | |
| echo "ARCHIVEBOX_VERSION=$VERSION" >> "$GITHUB_ENV" | |
| - name: Install build tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y dpkg-dev | |
| NFPM_VERSION="2.45.1" | |
| curl -fsSL "https://github.com/goreleaser/nfpm/releases/download/v${NFPM_VERSION}/nfpm_${NFPM_VERSION}_Linux_x86_64.tar.gz" \ | |
| | sudo tar -xz -C /usr/local/bin nfpm | |
| nfpm --version | |
| - name: Test apt repository update | |
| run: ./tests/test_update_apt_repo.sh | |
| - name: Build .deb | |
| run: ./bin/build_deb.sh | |
| - name: Load build metadata | |
| run: cat dist/build.env >> "$GITHUB_ENV" | |
| - name: Record release tag | |
| id: release-tag | |
| run: | | |
| TAG="v${ARCHIVEBOX_VERSION}" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| - name: Verify package metadata | |
| run: | | |
| DEB_FILES=(dist/*.deb) | |
| test "${#DEB_FILES[@]}" -eq 1 | |
| DEB_FILE="${DEB_FILES[0]}" | |
| dpkg-deb --info "$DEB_FILE" | |
| dpkg-deb --contents "$DEB_FILE" | |
| dpkg-deb --field "$DEB_FILE" | |
| - name: Integration test installed package | |
| run: | | |
| set -Eeuo pipefail | |
| DEB_FILES=(dist/*.deb) | |
| test "${#DEB_FILES[@]}" -eq 1 | |
| DEB_FILE="${DEB_FILES[0]}" | |
| sudo apt-get install -y "./$DEB_FILE" | |
| mkdir -p /tmp/archivebox-ci-fixture "$HOME/archivebox" | |
| tee /tmp/archivebox-ci-fixture/index.html >/dev/null <<'HTML' | |
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>ArchiveBox Debian CI Fixture</title> | |
| </head> | |
| <body> | |
| <main> | |
| <h1>ArchiveBox Debian CI Fixture</h1> | |
| <p>This page must be archived by the installed Debian package.</p> | |
| </main> | |
| </body> | |
| </html> | |
| HTML | |
| coproc FIXTURE_SERVER { | |
| python3 -u -c ' | |
| from functools import partial | |
| from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer | |
| handler = partial( | |
| SimpleHTTPRequestHandler, | |
| directory="/tmp/archivebox-ci-fixture", | |
| ) | |
| server = ThreadingHTTPServer(("127.0.0.1", 18080), handler) | |
| print("READY", flush=True) | |
| server.serve_forever() | |
| ' | |
| } | |
| SERVER_PID="$FIXTURE_SERVER_PID" | |
| trap 'kill "$SERVER_PID" 2>/dev/null || true' EXIT | |
| read -r SERVER_READY <&"${FIXTURE_SERVER[0]}" | |
| test "$SERVER_READY" = READY | |
| curl -fsS http://127.0.0.1:18080/ >/dev/null | |
| sudo bash -lc ' | |
| set -Eeuo pipefail | |
| mkdir -p /root/archivebox-ci/data | |
| cd /root/archivebox-ci/data | |
| archivebox init | |
| timeout 30m archivebox install | |
| archivebox status | |
| test "$(stat -c %U .)" = archivebox | |
| test "$(stat -c %U /root)" = root | |
| test "$(stat -c %G /root)" = archivebox | |
| test -n "$(find /root -maxdepth 0 -perm /0010 -print)" | |
| test -z "$(find /root -maxdepth 0 -perm /0001 -print)" | |
| sudo -u archivebox sh -c "cd /root/archivebox-ci/data && archivebox status" | |
| if find . -user root -print -quit | grep -q .; then | |
| echo "[X] Root invocation left root-owned collection files behind:" >&2 | |
| find . -user root -ls >&2 | |
| exit 1 | |
| fi | |
| ' | |
| ( | |
| mkdir -p "$HOME/archivebox/data" && cd "$HOME/archivebox/data" | |
| archivebox init | |
| sudo timeout 30m archivebox install | |
| archivebox version | |
| archivebox status | |
| test -w . | |
| test -w archive | |
| test -w logs | |
| test -w sources | |
| test -w "$HOME/.config/abx/lib" | |
| if find . "$HOME/.config/abx" -user root -print -quit | grep -q .; then | |
| echo "[X] sudo archivebox install left root-owned files behind:" >&2 | |
| find . "$HOME/.config/abx" -user root -ls >&2 | |
| exit 1 | |
| fi | |
| timeout 10m archivebox add "http://127.0.0.1:18080/" | |
| archivebox status | |
| test -s index.sqlite3 | |
| test -d archive | |
| test -w tmp | |
| find archive -mindepth 2 -type f -print | tee /tmp/archivebox-ci-output-files.txt | |
| test "$(wc -l < /tmp/archivebox-ci-output-files.txt)" -gt 0 | |
| grep -R -I "ArchiveBox Debian CI Fixture" archive | |
| ) | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: archivebox-${{ env.ARCHIVEBOX_DEB_VERSION }}.deb | |
| path: dist/*.deb | |
| - name: Publish GitHub release | |
| if: github.ref == 'refs/heads/main' && !contains(inputs.archivebox_version, 'rc') | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| TAG="${{ steps.release-tag.outputs.tag }}" | |
| gh release create "$TAG" dist/*.deb dist/build.env \ | |
| --title "ArchiveBox ${ARCHIVEBOX_VERSION}" \ | |
| --notes "Thin apt wrapper for archivebox==${ARCHIVEBOX_VERSION}" \ | |
| --prerelease | |
| - name: Publish apt repository | |
| if: github.ref == 'refs/heads/main' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| PAGES_DIR="$(mktemp -d)" | |
| git clone --depth 1 --branch gh-pages \ | |
| "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \ | |
| "$PAGES_DIR" | |
| ./bin/update_apt_repo.sh "$PAGES_DIR" dist/*.deb | |
| git -C "$PAGES_DIR" config user.name "github-actions[bot]" | |
| git -C "$PAGES_DIR" config user.email "github-actions[bot]@users.noreply.github.com" | |
| git -C "$PAGES_DIR" add -A | |
| if git -C "$PAGES_DIR" diff --cached --quiet; then | |
| echo "[i] Apt repository is already current." | |
| else | |
| git -C "$PAGES_DIR" commit -m "Update ArchiveBox deb for ${ARCHIVEBOX_VERSION}" | |
| git -C "$PAGES_DIR" push origin HEAD:gh-pages | |
| fi |