Skip to content

Commit e8b841d

Browse files
committed
Warn and exit when no packages are listed in Aptfile
1 parent 7b97984 commit e8b841d

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Warn when Aptfile contains no packages ([#126](https://github.com/heroku/heroku-buildpack-apt/pull/126))
6+
57
## 2024-03-14
68

79
- Shell hardening ([#115](https://github.com/heroku/heroku-buildpack-apt/pull/115))

bin/compile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ function indent() {
2929
esac
3030
}
3131

32+
if ! grep --invert-match -e "^\s*#" -e "^\s*$" -e "^:repo:" -q "${BUILD_DIR}/Aptfile"; then
33+
echo "
34+
! You have no packages listed in your Aptfile. If you don't need custom Apt packages,
35+
! delete your Aptfile and remove the buildpack with:
36+
!
37+
! $ heroku buildpacks:remove heroku-community/apt
38+
"
39+
exit 0
40+
fi
41+
3242
# Store which STACK we are running on in the cache to bust the cache if it changes
3343
if [[ -f "$CACHE_DIR/.apt/STACK" ]]; then
3444
CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:repo:deb http://us.archive.ubuntu.com/ubuntu/ jammy multiverse

test/fixtures/empty/Aptfile

Whitespace-only changes.

test/fixtures/only-comments/Aptfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# no packages
2+
# only comments
3+
4+
# and whitespace

test/run

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,51 @@ testReportCustomRepository() {
7878
assertCapturedSuccess
7979
}
8080

81+
testCompileEmpty() {
82+
compile "empty"
83+
assertCaptured "You have no packages listed in your Aptfile"
84+
assertNotCaptured "Updating apt caches"
85+
assertCapturedSuccess
86+
}
87+
88+
testReportEmpty() {
89+
report "empty"
90+
assertNotCaptured "^packages"
91+
assertNotCaptured "custom_packages"
92+
assertNotCaptured "custom_repositories"
93+
assertCapturedSuccess
94+
}
95+
96+
testCompileOnlyComments() {
97+
compile "only-comments"
98+
assertCaptured "You have no packages listed in your Aptfile"
99+
assertNotCaptured "Updating apt caches"
100+
assertCapturedSuccess
101+
}
102+
103+
testReportOnlyComments() {
104+
report "only-comments"
105+
assertNotCaptured "^packages"
106+
assertNotCaptured "custom_packages"
107+
assertNotCaptured "custom_repositories"
108+
assertCapturedSuccess
109+
}
110+
111+
testCompileCustomRepositoryNoPackages() {
112+
compile "custom-repository-no-packages"
113+
assertCaptured "You have no packages listed in your Aptfile"
114+
assertNotCaptured "Updating apt caches"
115+
assertCapturedSuccess
116+
}
117+
118+
testReportCustomRepositoryNoPackages() {
119+
report "custom-repository-no-packages"
120+
assertNotCaptured "^packages"
121+
assertNotCaptured "custom_packages"
122+
assertCaptured "custom_repositories: \"deb http://us.archive.ubuntu.com/ubuntu/ jammy multiverse\""
123+
assertCapturedSuccess
124+
}
125+
81126
pushd "$(dirname 0)" >/dev/null || exit 1
82127
popd >/dev/null || exit 1
83128

0 commit comments

Comments
 (0)