From 5b1713b5e1068ea6c015a78e734b434aa42a55ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 5 Dec 2023 17:52:42 +0100 Subject: [PATCH 1/9] CI: Add workflow to build debian package as part of build --- .github/workflows/build-deb.yaml | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/build-deb.yaml diff --git a/.github/workflows/build-deb.yaml b/.github/workflows/build-deb.yaml new file mode 100644 index 0000000000..f0e680eb21 --- /dev/null +++ b/.github/workflows/build-deb.yaml @@ -0,0 +1,37 @@ +name: Build debian packages + +on: + push: + branches: + - main + tags: + - "*" + pull_request: + +env: + UBUNTU_VERSION: devel + +jobs: + build-deb-package: + name: Build ubuntu package + runs-on: ubuntu-latest + outputs: + run-id: ${{ github.run_id }} + pkg-name: ${{ env.PKG_NAME }} + pkg-version: ${{ env.PKG_VERSION }} + + steps: + - name: Checkout authd code + uses: actions/checkout@v4 + + - name: Build debian packages and sources + uses: canonical/desktop-engineering/gh-actions/common/build-debian@main + with: + docker-image: ubuntu:${{ env.UBUNTU_VERSION }} + extra-source-build-deps: | + ca-certificates + git + libssl-dev + extra-source-build-script: | + cargo install --locked --root=/usr cargo-vendor-filterer + command -v cargo-vendor-filterer From d3c221d9e9c420053685544305ef9fc7db0787e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 13 Dec 2024 17:04:54 +0000 Subject: [PATCH 2/9] CI: Add workflow to run autopkgtests on the previously built deb package Ensure that autopkgtests works with authd at every run --- .github/workflows/build-deb.yaml | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/build-deb.yaml b/.github/workflows/build-deb.yaml index f0e680eb21..a5b1f6ad61 100644 --- a/.github/workflows/build-deb.yaml +++ b/.github/workflows/build-deb.yaml @@ -35,3 +35,41 @@ jobs: extra-source-build-script: | cargo install --locked --root=/usr cargo-vendor-filterer command -v cargo-vendor-filterer + + run-autopkgtests: + name: Run autopkgtests + needs: build-deb-package + runs-on: ubuntu-latest + + container: + image: ubuntu:${{ env.UBUNTU_VERSION }} + + steps: + - name: Prepare container + run: | + set -eu + + echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90aptyes + apt update + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + run-id: ${{ needs.build-deb-package.outputs.run-id }} + + - name: Install dependencies + run: | + apt install autopkgtest + + - name: Create test user + run: | + apt install adduser + adduser --disabled-password --gecos "" tester + + - name: Run autopkgtests + run: | + mv -v ./*-debian-source/* . + mv -v ./*-debian-packages/* . + autopkgtest --apt-pocket proposed --apt-upgrade --no-built-binaries --user=tester \ + *_${{ needs.build-deb-package.outputs.pkg-version }}*.deb \ + ${{ needs.build-deb-package.outputs.pkg-name }}_${{ needs.build-deb-package.outputs.pkg-version }}_source.changes -- null From a35b553369183be40bcdee12f0f9647321001ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 19 Dec 2024 06:40:21 +0100 Subject: [PATCH 3/9] CI/build-deb: reuse desktop actions to run autopkgtests --- .github/workflows/build-deb.yaml | 33 ++++++-------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build-deb.yaml b/.github/workflows/build-deb.yaml index a5b1f6ad61..a0c318953e 100644 --- a/.github/workflows/build-deb.yaml +++ b/.github/workflows/build-deb.yaml @@ -17,8 +17,7 @@ jobs: runs-on: ubuntu-latest outputs: run-id: ${{ github.run_id }} - pkg-name: ${{ env.PKG_NAME }} - pkg-version: ${{ env.PKG_VERSION }} + pkg-src-changes: ${{ env.PKG_SOURCE_CHANGES }} steps: - name: Checkout authd code @@ -41,35 +40,15 @@ jobs: needs: build-deb-package runs-on: ubuntu-latest - container: - image: ubuntu:${{ env.UBUNTU_VERSION }} - steps: - - name: Prepare container - run: | - set -eu - - echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90aptyes - apt update - - name: Download artifacts uses: actions/download-artifact@v4 with: run-id: ${{ needs.build-deb-package.outputs.run-id }} - - - name: Install dependencies - run: | - apt install autopkgtest - - - name: Create test user - run: | - apt install adduser - adduser --disabled-password --gecos "" tester + merge-multiple: true - name: Run autopkgtests - run: | - mv -v ./*-debian-source/* . - mv -v ./*-debian-packages/* . - autopkgtest --apt-pocket proposed --apt-upgrade --no-built-binaries --user=tester \ - *_${{ needs.build-deb-package.outputs.pkg-version }}*.deb \ - ${{ needs.build-deb-package.outputs.pkg-name }}_${{ needs.build-deb-package.outputs.pkg-version }}_source.changes -- null + uses: canonical/desktop-engineering/gh-actions/common/run-autopkgtest@main + with: + lxd-image: ubuntu:${{ env.UBUNTU_VERSION }} + source-changes: ${{ needs.build-deb-package.outputs.pkg-src-changes }} From a2abdb978cfa94ccadf22697a03631ebde9ce394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 19 Dec 2024 07:13:02 +0100 Subject: [PATCH 4/9] debian/tests/run-tests: Try to use the backported go version Uniform the same code that we've in debian rules with debian tests --- debian/get-depends-go-bin-path.sh | 11 +++++++++++ debian/rules | 3 +-- debian/tests/run-tests.sh | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 debian/get-depends-go-bin-path.sh diff --git a/debian/get-depends-go-bin-path.sh b/debian/get-depends-go-bin-path.sh new file mode 100755 index 0000000000..d63a45c7b7 --- /dev/null +++ b/debian/get-depends-go-bin-path.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -eu + +debian_path=$(dirname "$0") +backported_go_version=$(grep-dctrl -s Build-Depends -n - "${debian_path}"/control | \ + sed -n "s,.*\bgolang-\([0-9.]\+\)\b.*,\1,p") + +if [ -n "${backported_go_version}" ]; then + echo "/usr/lib/go-${backported_go_version}/bin" +fi diff --git a/debian/rules b/debian/rules index f4e36955d8..6449654853 100755 --- a/debian/rules +++ b/debian/rules @@ -50,8 +50,7 @@ export DH_GOLANG_BUILDPKG := $(AUTHD_GO_PACKAGE)/... \ # We add the required backported version to the $PATH so that if it exists, then # we can use it. Otherwise we default to the go installed in original $PATH that # always matches with the latest available go version in the archive. -AUTHD_BACKPORTED_GO_VERSION := $(shell grep-dctrl -s Build-Depends -n - ./debian/control | sed -n "s,.*\bgolang-\([0-9.]\+\)\b.*,\1,p") -export PATH := $(shell printenv PATH):/usr/lib/go-$(AUTHD_BACKPORTED_GO_VERSION)/bin +export PATH := $(shell printenv PATH):$(shell ./debian/get-depends-go-bin-path.sh) BUILDDIR := $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE) diff --git a/debian/tests/run-tests.sh b/debian/tests/run-tests.sh index 10bdda5fa4..29aeb2df73 100755 --- a/debian/tests/run-tests.sh +++ b/debian/tests/run-tests.sh @@ -6,4 +6,7 @@ export AUTHD_SKIP_EXTERNAL_DEPENDENT_TESTS=1 export GOPROXY=off export GOTOOLCHAIN=local +PATH=$PATH:$("$(dirname "$0")"/../get-depends-go-bin-path.sh) +export PATH + go test -v ./... From f1bd88c4988c31494b13da3e84afe22f99875c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 19 Dec 2024 06:04:05 +0100 Subject: [PATCH 5/9] CI/build-deb: Use a matrix to run package builds in latest LTS and devel Those are so far the targets we care, so let's build and test packages in both scenarios --- .github/workflows/build-deb.yaml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-deb.yaml b/.github/workflows/build-deb.yaml index a0c318953e..6f9ba5f48e 100644 --- a/.github/workflows/build-deb.yaml +++ b/.github/workflows/build-deb.yaml @@ -9,12 +9,26 @@ on: pull_request: env: - UBUNTU_VERSION: devel + UBUNTU_VERSIONS: | + ["noble", "devel"] jobs: + define-versions: + name: Define build versions + runs-on: ubuntu-latest + outputs: + ubuntu-versions: ${{ env.UBUNTU_VERSIONS }} + steps: + - run: 'true' + build-deb-package: name: Build ubuntu package runs-on: ubuntu-latest + needs: define-versions + strategy: + fail-fast: false + matrix: + ubuntu-version: ${{ fromJSON(needs.define-versions.outputs.ubuntu-versions) }} outputs: run-id: ${{ github.run_id }} pkg-src-changes: ${{ env.PKG_SOURCE_CHANGES }} @@ -26,7 +40,7 @@ jobs: - name: Build debian packages and sources uses: canonical/desktop-engineering/gh-actions/common/build-debian@main with: - docker-image: ubuntu:${{ env.UBUNTU_VERSION }} + docker-image: ubuntu:${{ matrix.ubuntu-version }} extra-source-build-deps: | ca-certificates git @@ -37,8 +51,14 @@ jobs: run-autopkgtests: name: Run autopkgtests - needs: build-deb-package runs-on: ubuntu-latest + needs: + - define-versions + - build-deb-package + strategy: + fail-fast: false + matrix: + ubuntu-version: ${{ fromJSON(needs.define-versions.outputs.ubuntu-versions) }} steps: - name: Download artifacts @@ -50,5 +70,5 @@ jobs: - name: Run autopkgtests uses: canonical/desktop-engineering/gh-actions/common/run-autopkgtest@main with: - lxd-image: ubuntu:${{ env.UBUNTU_VERSION }} + lxd-image: ubuntu:${{ matrix.ubuntu-version }} source-changes: ${{ needs.build-deb-package.outputs.pkg-src-changes }} From 3fd53e7a42eef5a49d43ad3328c36fc28524b686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 19 Dec 2024 15:01:38 +0000 Subject: [PATCH 6/9] ci: Only run autpkgtests on main, on tags and if a debian file is modified --- .github/workflows/build-deb.yaml | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/.github/workflows/build-deb.yaml b/.github/workflows/build-deb.yaml index 6f9ba5f48e..b49159aa5c 100644 --- a/.github/workflows/build-deb.yaml +++ b/.github/workflows/build-deb.yaml @@ -49,17 +49,67 @@ jobs: cargo install --locked --root=/usr cargo-vendor-filterer command -v cargo-vendor-filterer + check-modified-files: + name: Check modified files + runs-on: ubuntu-latest + needs: + - build-deb-package + outputs: + list: ${{ fromJSON(steps.git-diff.outputs.modified_files) }} + + steps: + - name: Checkout authd code + uses: actions/checkout@v4 + with: + fetch-depth: 100 + + - id: git-diff + name: Check modified files + run: | + set -ue + + base_ref=${{ github.event.pull_request.base.sha }} + if [ -z "${base_ref}" ]; then + base_ref=${{ github.event.before }} + fi + if [ -z "${base_ref}" ]; then + base_ref=$(git log --root --reverse -n1 --format=%H) + fi + + # Build a JSON array of modified paths. + modified_files=$(git diff --name-only "${base_ref}" HEAD | \ + while read line; do + jq -n --arg path "$line" '$path' + done | jq -n '. |= [inputs]') + echo "${modified_files}" + + escaped_json=$(echo "${modified_files}" | jq '.| tostring') + echo "modified_files=${escaped_json}" >> "${GITHUB_OUTPUT}" + run-autopkgtests: name: Run autopkgtests runs-on: ubuntu-latest needs: - define-versions - build-deb-package + - check-modified-files strategy: fail-fast: false matrix: ubuntu-version: ${{ fromJSON(needs.define-versions.outputs.ubuntu-versions) }} + # Run autopkgtests only on: + # - Push events to main + # - When a file in the debian subdir is modified + # - When this file is modified + # - On new tags + # - On github release + if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || + contains(needs.check-modified-files.outputs.list, 'debian/') || + contains(needs.check-modified-files.outputs.list, '.github/workflows/build-deb.yaml') || + startsWith(github.ref, 'refs/tags/') || + github.event_name == 'release' }} + steps: - name: Download artifacts uses: actions/download-artifact@v4 From 628967f5adc6dae9ea5fdc4b0b6164c33504eaf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 17 Jan 2025 16:45:11 +0000 Subject: [PATCH 7/9] debian/changelog: Drop trailing whitespace As per lintian report --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 31f05a9f26..40b4d57d98 100644 --- a/debian/changelog +++ b/debian/changelog @@ -152,7 +152,7 @@ authd (0.2) noble; urgency=medium - libc - simple_logger - tokio - * Update tools and CI dependencies not related to package + * Update tools and CI dependencies not related to package functionality - google.golang.org/protobuf From 2a78294298faeb761d5eb4d9eee410d8503c6ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 17 Jan 2025 16:49:25 +0000 Subject: [PATCH 8/9] debian/copyright: Drop superflus files patterns Thanks lintian! --- debian/copyright | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/debian/copyright b/debian/copyright index 7b116b3acb..34d759aa6d 100644 --- a/debian/copyright +++ b/debian/copyright @@ -80,10 +80,6 @@ Files: vendor/github.com/charmbracelet/* Copyright: 2019-2023 Charmbracelet, Inc License: MIT -Files: vendor/github.com/containerd/console/* -Copyright: The containerd Authors. -License: Apache-2.0 - Files: vendor/github.com/coreos/* Copyright: 2015-2018 CoreOS, Inc. / 2014 Docker, Inc. License: Apache-2.0 @@ -100,10 +96,6 @@ Files: vendor/github.com/godbus/* Copyright: 2013 Georg Reinke (), Google License: BSD-2 -Files: vendor/github.com/golang/protobuf/* -Copyright: Copyright: 2010 The Go Authors. -License: BSD-3 - Files: vendor/github.com/google/uuid/* Copyright: 2009, 2014-2017, 2021 Google Inc. License: BSD-3 @@ -244,12 +236,10 @@ Files: vendor_rust/anyhow/* vendor_rust/fastrand/* vendor_rust/fixedbitset/* vendor_rust/hermit-abi/* - vendor_rust/home/* vendor_rust/indexmap/* vendor_rust/itertools/* vendor_rust/itoa/* vendor_rust/linux-raw-sys/* - vendor_rust/num_cpus/* vendor_rust/once_cell/* vendor_rust/paste/* vendor_rust/petgraph/* @@ -291,7 +281,6 @@ License: MIT Files: vendor_rust/backtrace/* vendor_rust/cc/* vendor_rust/cfg-if/* - vendor_rust/match_cfg/* vendor_rust/rustc-demangle/* vendor_rust/socket2/* Copyright: 2014 Alex Crichton @@ -321,10 +310,6 @@ Files: vendor_rust/errno/* Copyright: 2014 Chris Wong License: MIT -Files: vendor_rust/error-chain/* -Copyright: 2017 The Error-Chain Project Developers -License: MIT - Files: vendor_rust/fnv/* Copyright: 2017 Contributors License: MIT @@ -449,10 +434,6 @@ Files: vendor_rust/tokio/* Copyright: 2019, 2023 Tokio Contributors License: MIT -Files: vendor_rust/tokio-io-timeout/* -Copyright: 2017 The tokio-io-timeout Developers -License: MIT - Files: vendor_rust/tonic/* vendor_rust/tonic-build/* Copyright: 2020 Lucio Franco @@ -468,18 +449,6 @@ Files: vendor_rust/try-lock/* Copyright: 2018 Sean McArthur / 2016 Alex Crichton License: MIT -Files: vendor_rust/version_check/* -Copyright: 2017-2018 Sergio Benitez -License: MIT - -Files: vendor_rust/which/* -Copyright: 2015 fangyuanziti -License: MIT - -Files: vendor_rust/winapi*/* -Copyright: 2015-2018 The winapi-rs Developers -License: MIT - Files: vendor_rust/windows*/* Copyright: Microsoft Corporation. License: MIT From 0642fbb04e3be78ace0057a8654c5bf58d4b5110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 18 Jan 2025 00:21:59 +0000 Subject: [PATCH 9/9] build-deb: Lock the cargo-filterer-version to the noble one Newer versions require new cargo that is not in noble, so we don't try to use the newest version. Even though using a bit more advanced matrix we could do that... --- .github/workflows/build-deb.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-deb.yaml b/.github/workflows/build-deb.yaml index b49159aa5c..8a05bc73c9 100644 --- a/.github/workflows/build-deb.yaml +++ b/.github/workflows/build-deb.yaml @@ -11,6 +11,7 @@ on: env: UBUNTU_VERSIONS: | ["noble", "devel"] + CARGO_VENDOR_FILTERER_VERSION: 0.5.16 jobs: define-versions: @@ -46,7 +47,8 @@ jobs: git libssl-dev extra-source-build-script: | - cargo install --locked --root=/usr cargo-vendor-filterer + cargo install --locked --root=/usr \ + cargo-vendor-filterer@${{ env.CARGO_VENDOR_FILTERER_VERSION }} command -v cargo-vendor-filterer check-modified-files: