Skip to content

Commit

Permalink
Warn and exit when no packages are listed in Aptfile
Browse files Browse the repository at this point in the history
  • Loading branch information
colincasey committed Mar 20, 2024
1 parent 7b97984 commit e8b841d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Warn when Aptfile contains no packages ([#126](https://github.com/heroku/heroku-buildpack-apt/pull/126))

## 2024-03-14

- Shell hardening ([#115](https://github.com/heroku/heroku-buildpack-apt/pull/115))
Expand Down
10 changes: 10 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ function indent() {
esac
}

if ! grep --invert-match -e "^\s*#" -e "^\s*$" -e "^:repo:" -q "${BUILD_DIR}/Aptfile"; then
echo "
! You have no packages listed in your Aptfile. If you don't need custom Apt packages,
! delete your Aptfile and remove the buildpack with:
!
! $ heroku buildpacks:remove heroku-community/apt
"
exit 0
fi

# Store which STACK we are running on in the cache to bust the cache if it changes
if [[ -f "$CACHE_DIR/.apt/STACK" ]]; then
CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK")
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/custom-repository-no-packages/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:repo:deb http://us.archive.ubuntu.com/ubuntu/ jammy multiverse
Empty file added test/fixtures/empty/Aptfile
Empty file.
4 changes: 4 additions & 0 deletions test/fixtures/only-comments/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# no packages
# only comments

# and whitespace
45 changes: 45 additions & 0 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,51 @@ testReportCustomRepository() {
assertCapturedSuccess
}

testCompileEmpty() {
compile "empty"
assertCaptured "You have no packages listed in your Aptfile"
assertNotCaptured "Updating apt caches"
assertCapturedSuccess
}

testReportEmpty() {
report "empty"
assertNotCaptured "^packages"
assertNotCaptured "custom_packages"
assertNotCaptured "custom_repositories"
assertCapturedSuccess
}

testCompileOnlyComments() {
compile "only-comments"
assertCaptured "You have no packages listed in your Aptfile"
assertNotCaptured "Updating apt caches"
assertCapturedSuccess
}

testReportOnlyComments() {
report "only-comments"
assertNotCaptured "^packages"
assertNotCaptured "custom_packages"
assertNotCaptured "custom_repositories"
assertCapturedSuccess
}

testCompileCustomRepositoryNoPackages() {
compile "custom-repository-no-packages"
assertCaptured "You have no packages listed in your Aptfile"
assertNotCaptured "Updating apt caches"
assertCapturedSuccess
}

testReportCustomRepositoryNoPackages() {
report "custom-repository-no-packages"
assertNotCaptured "^packages"
assertNotCaptured "custom_packages"
assertCaptured "custom_repositories: \"deb http://us.archive.ubuntu.com/ubuntu/ jammy multiverse\""
assertCapturedSuccess
}

pushd "$(dirname 0)" >/dev/null || exit 1
popd >/dev/null || exit 1

Expand Down

0 comments on commit e8b841d

Please sign in to comment.