Skip to content

Commit 7f79547

Browse files
Add a way to set apt preferences
Signed-off-by: Leonardo Held <[email protected]>
1 parent 7d30375 commit 7f79547

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

.github/workflows/test.yml

+25
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,31 @@ jobs:
281281
test -f debian/artifacts/test_1_amd64.buildinfo
282282
test -f debian/artifacts/test_1_amd64.changes
283283
284+
extra-apt-preferences:
285+
needs: [setup-hook]
286+
runs-on: ubuntu-latest
287+
steps:
288+
- uses: actions/checkout@v4
289+
- run: cat test/Makefile_extra-preferences >>test/Makefile
290+
- uses: ./
291+
env:
292+
DEB_BUILD_OPTIONS: noautodbgsym
293+
with:
294+
buildpackage-opts: --build=binary --no-sign
295+
extra-apt-preferences: |
296+
Package: *
297+
Pin: origin deb.debian.org
298+
Pin-Priority: 900
299+
setup-hook: |
300+
apt-get update # Called here manually only for testing purposes!
301+
! apt-cache policy | grep -B3 'origin deb.debian.org' | grep -q '900'
302+
source-dir: test
303+
- run: |
304+
dpkg --info debian/artifacts/test_1_amd64.deb
305+
dpkg --contents debian/artifacts/test_1_amd64.deb | grep ./usr/bin/mybin
306+
test -f debian/artifacts/test_1_amd64.buildinfo
307+
test -f debian/artifacts/test_1_amd64.changes
308+
284309
full-build:
285310
runs-on: ubuntu-latest
286311
steps:

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ deb822 style, see
115115

116116
Optional and empty by default.
117117

118+
#### `extra-apt-preferences`
119+
Extra APT preferences to configure package priorities in the build environment.
120+
121+
This allows you to pin packages from specific sources or set priorities to control
122+
package selection during installation or upgrades. The preferences should be
123+
provided in a format supported by APT, typically as entries in Package, Pin, and
124+
Pin-Priority fields. For more details, see `man apt_preferences`.
125+
126+
Optional and empty by default.
127+
118128
#### `extra-repo-keys`
119129
Extra keys for APT to trust in the build environment. Useful in combination
120130
with [`extra-repos`](#extra-repos).

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ inputs:
3232
extra-repos:
3333
description: Extra APT repositories to configure in the build environment (one-line-style or deb822-style format)
3434
required: false
35+
extra-apt-preferences:
36+
description: Extra APT preferences fragments file to configure the priorities between multiple feeds
37+
required: false
3538
host-arch:
3639
description: Foreign architecture to setup cross-building for
3740
required: false
@@ -58,6 +61,7 @@ runs:
5861
INPUT_EXTRA_DOCKER_ARGS: ${{ inputs.extra-docker-args }}
5962
INPUT_EXTRA_REPO_KEYS: ${{ inputs.extra-repo-keys }}
6063
INPUT_EXTRA_REPOS: ${{ inputs.extra-repos }}
64+
INPUT_EXTRA_APT_PREFERENCES: ${{ inputs.extra-apt-preferences }}
6165
INPUT_HOST_ARCH: ${{ inputs.host-arch }}
6266
INPUT_SETUP_HOOK: ${{ inputs.setup-hook }}
6367
INPUT_SOURCE_DIR: ${{ inputs.source-dir }}

scripts/install_build_deps

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ else
3131
fi
3232
printf "%s\n" "$INPUT_EXTRA_REPOS" >"/etc/apt/sources.list.d/build-deb-action${extra_repos_ext}"
3333

34+
printf "%s\n" "$INPUT_EXTRA_APT_PREFERENCES" > "/etc/apt/preferences.d/extra-preferences.pref"
35+
3436
apt-get update
3537

3638
# shellcheck disable=SC2086

scripts/run

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ env \
115115
--unset=INPUT_BEFORE_BUILD_HOOK \
116116
--unset=INPUT_EXTRA_REPO_KEYS \
117117
--unset=INPUT_EXTRA_REPOS \
118+
--unset=INPUT_EXTRA_APT_PREFERENCES \
118119
--unset=INPUT_SETUP_HOOK \
119120
>"$env_file"
120121

@@ -127,6 +128,7 @@ container_id=$(
127128
--env=GITHUB_ACTION_PATH=/github/action \
128129
--env=GITHUB_WORKSPACE=/github/workspace \
129130
--env=INPUT_EXTRA_REPOS \
131+
--env=INPUT_EXTRA_APT_PREFERENCES \
130132
--mount="type=bind,src=${GITHUB_ACTION_PATH},dst=/github/action,ro" \
131133
--mount="type=bind,src=${build_dir},dst=/github/build" \
132134
--mount="type=bind,src=${GITHUB_WORKSPACE},dst=/github/workspace" \

test/Makefile_extra-preferences

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
.PHONY: test
3+
test:
4+
apt-cache policy | grep -B3 'origin deb.debian.org' | grep -q '900'

0 commit comments

Comments
 (0)