Skip to content

Commit 61fc13e

Browse files
committed
Add support for running apt with --no-install-recommends and --no-upgrade.
1 parent f542f5f commit 61fc13e

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ There are three kinds of version labels you can use.
3535
- `packages` - Space delimited list of packages to install.
3636
- `version` - Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed.
3737
- `execute_install_scripts` - Execute Debian package pre and post install script upon restore. See [Caveats / Non-file Dependencies](#non-file-dependencies) for more information.
38+
- `no_install_recommends` - Add the `--no-install-recommends` option to the `apt install` command for cache creation to prevent automatic installation of recommended packages.
39+
- `no_upgrade` - Add the `--no-upgrade` option to the `apt install` command for cache creation to prevent automatic upgrade of existing packages.
3840
- `empty_packages_behavior` - Desired behavior when the given `packages` is empty. `'error'` (default), `'warn'` or `'ignore'`.
3941
- `add-repository` - Space delimited list of repositories to add via `apt-add-repository` before installing packages. Supports PPA (e.g., `ppa:user/repo`) and other repository formats.
4042

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ inputs:
1818
description: 'Execute Debian package pre and post install script upon restore. See README.md caveats for more information.'
1919
required: false
2020
default: 'false'
21+
no_install_recommends:
22+
description: 'Don''t install recommended packages when creating new cache.'
23+
required: false
24+
default: 'false'
25+
no_upgrade:
26+
description: 'Don''t upgrade existing packages when creating new cache.'
27+
required: false
28+
default: 'false'
2129
empty_packages_behavior:
2230
description: >
2331
Desired behavior when the provided package list is empty.
@@ -94,6 +102,8 @@ runs:
94102
/ \
95103
"$CACHE_HIT" \
96104
"$EXEC_INSTALL_SCRIPTS" \
105+
"$NO_INSTALL_RECOMMENDS" \
106+
"$NO_UPGRADE" \
97107
"$DEBUG" \
98108
"$ADD_REPOSITORY" \
99109
"$PACKAGES"
@@ -104,6 +114,8 @@ runs:
104114
env:
105115
CACHE_HIT: "${{ steps.load-cache.outputs.cache-hit }}"
106116
EXEC_INSTALL_SCRIPTS: "${{ inputs.execute_install_scripts }}"
117+
NO_INSTALL_RECOMMENDS: "${{ inputs.no_install_recommends }}"
118+
NO_UPGRADE: "${{ inputs.no_upgrade }}"
107119
DEBUG: "${{ inputs.debug }}"
108120
ADD_REPOSITORY: "${{ inputs.add-repository }}"
109121
PACKAGES: "${{ inputs.packages }}"

install_and_cache_pkgs.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ source "${script_dir}/lib.sh"
1515
# Directory that holds the cached packages.
1616
cache_dir="${1}"
1717

18+
# Don't install recommended packages.
19+
no_install_recommends="${3}"
20+
21+
# Don't upgrade existing packages.
22+
no_upgrade="${4}"
23+
1824
# Repositories to add before installing packages.
19-
add_repository="${3}"
25+
add_repository="${5}"
2026

2127
# List of the packages to use.
22-
input_packages="${@:4}"
28+
input_packages="${@:6}"
2329

2430
if ! apt-fast --version > /dev/null 2>&1; then
2531
log "Installing apt-fast for optimized installs..."
@@ -69,9 +75,17 @@ manifest_all=""
6975

7076
install_log_filepath="${cache_dir}/install.log"
7177

78+
declare -a apt_options
79+
if test "${no_install_recommends}" = "true" ; then
80+
apt_options+=( "--no-install-recommends" )
81+
fi
82+
if test "${no_upgrade}" = "true" ; then
83+
apt_options+=( "--no-upgrade" )
84+
fi
85+
7286
log "Clean installing ${package_count} packages..."
7387
# Zero interaction while installing or upgrading the system via apt.
74-
sudo DEBIAN_FRONTEND=noninteractive apt-fast --yes install ${packages} > "${install_log_filepath}"
88+
sudo DEBIAN_FRONTEND=noninteractive apt-fast --yes install ${apt_options[@]} ${packages} > "${install_log_filepath}"
7589
log "done"
7690
log "Installation log written to ${install_log_filepath}"
7791

post_cache_action.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@ cache_hit="${3}"
2121
# Cache and execute post install scripts on restore.
2222
execute_install_scripts="${4}"
2323

24+
# Don't install recommended packages.
25+
no_install_recommends="${5}"
26+
27+
# Don't upgrade existing packages.
28+
no_upgrade="${6}"
29+
2430
# Debug mode for diagnosing issues.
25-
debug="${5}"
31+
debug="${7}"
2632
test "${debug}" = "true" && set -x
2733

2834
# Repositories to add before installing packages.
29-
add_repository="${6}"
35+
add_repository="${8}"
3036

3137
# List of the packages to use.
32-
packages="${@:7}"
38+
packages="${@:9}"
3339

3440
if test "${cache_hit}" = "true"; then
3541
${script_dir}/restore_pkgs.sh "${cache_dir}" "${cache_restore_root}" "${execute_install_scripts}" "${debug}"
3642
else
37-
${script_dir}/install_and_cache_pkgs.sh "${cache_dir}" "${debug}" "${add_repository}" ${packages}
43+
${script_dir}/install_and_cache_pkgs.sh "${cache_dir}" "${debug}" "${no_install_recommends}" "${no_upgrade}" "${add_repository}" ${packages}
3844
fi
3945

4046
log_empty_line

0 commit comments

Comments
 (0)