Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn and exit when no packages are listed in Aptfile #126

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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