Skip to content

Commit

Permalink
sbt Buildpack Refactor (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malax authored May 10, 2023
1 parent 53fc0e2 commit 617f68d
Show file tree
Hide file tree
Showing 26 changed files with 403 additions and 355 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ jobs:
fail-fast: false
matrix:
buildpack-directory: ${{ fromJson(needs.gather-repo-metadata.outputs.buildpack_dirs) }}
env:
INTEGRATION_TEST_CNB_BUILDER: "heroku/builder:22"
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions buildpacks/jvm-function-invoker/tests/integration/smoke.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use base64::Engine;
use buildpacks_jvm_shared_test::DEFAULT_INTEGRATION_TEST_BUILDER;
use buildpacks_jvm_shared_test::{
ADDRESS_FOR_PORT_EXPECT_MESSAGE, DEFAULT_INTEGRATION_TEST_BUILDER,
UREQ_RESPONSE_AS_STRING_EXPECT_MESSAGE, UREQ_RESPONSE_RESULT_EXPECT_MESSAGE,
};
use libcnb_test::{BuildConfig, BuildpackReference, ContainerConfig, TestRunner};
use std::time::Duration;

Expand All @@ -24,7 +27,7 @@ fn smoke_test_simple_function() {
let request_payload = "\"All those moments will be lost in time, like tears in rain...\"";

// Absolute minimum request that can be served by the function runtime.
let response_payload = ureq::post(&format!("http://{}", container.address_for_port(PORT).expect("couldn't get container address")))
let response_payload = ureq::post(&format!("http://{}", container.address_for_port(PORT).expect(ADDRESS_FOR_PORT_EXPECT_MESSAGE)))
.set("Content-Type", "application/json")
.set("Authorization", "")
.set("ce-id", "function")
Expand All @@ -35,9 +38,9 @@ fn smoke_test_simple_function() {
.set("ce-sfcontext", &base64::engine::general_purpose::STANDARD.encode(r#"{ "apiVersion": "", "payloadVersion": "", "userContext": { "orgId": "", "userId": "", "username": "", "orgDomainUrl": "", "onBehalfOfUserId": null, "salesforceBaseUrl": "" } }"#))
.set("ce-sffncontext", &base64::engine::general_purpose::STANDARD.encode(r#"{ "resource": "", "requestId": "", "accessToken": "", "apexClassId": null, "apexClassFQN": null, "functionName": "", "functionInvocationId": null }"#))
.send_string(request_payload)
.unwrap()
.expect(UREQ_RESPONSE_RESULT_EXPECT_MESSAGE)
.into_string()
.expect("response read error");
.expect(UREQ_RESPONSE_AS_STRING_EXPECT_MESSAGE);

assert_eq!(response_payload, request_payload.chars().rev().collect::<String>());
},
Expand Down
1 change: 1 addition & 0 deletions buildpacks/sbt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ buildpacks-jvm-shared.workspace = true
[dev-dependencies]
libcnb-test.workspace = true
buildpacks-jvm-shared-test.workspace = true
ureq = "2.6.2"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sbt._
import Keys._
import sbt.Keys._

object HerokuBuildpackPlugin extends Plugin {
override def settings = Seq(
Expand Down
50 changes: 0 additions & 50 deletions buildpacks/sbt/src/cleanup.rs

This file was deleted.

30 changes: 6 additions & 24 deletions buildpacks/sbt/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::configuration::ReadSbtBuildpackConfigurationError;
use crate::layers::sbt_extras::SbtExtrasLayerError;
use crate::layers::sbt_global::SbtGlobalLayerError;
use crate::sbt_version::ReadSbtVersionError;
use crate::sbt::output::SbtError;
use crate::sbt::version::ReadSbtVersionError;
use buildpacks_jvm_shared::log::log_please_try_again_error;
use buildpacks_jvm_shared::system_properties::ReadSystemPropertiesError;
use indoc::formatdoc;
Expand All @@ -19,9 +20,7 @@ pub(crate) enum SbtBuildpackError {
UnsupportedSbtVersion(Version),
DetectPhaseIoError(std::io::Error),
SbtBuildIoError(std::io::Error),
SbtBuildUnexpectedExitCode(ExitStatus),
MissingStageTask,
AlreadyDefinedAsObject,
SbtBuildUnexpectedExitStatus(ExitStatus, Option<SbtError>),
ReadSbtBuildpackConfigurationError(ReadSbtBuildpackConfigurationError),
ReadSystemPropertiesError(ReadSystemPropertiesError),
}
Expand Down Expand Up @@ -153,7 +152,7 @@ pub(crate) fn log_user_errors(error: SbtBuildpackError) {
" },
),

SbtBuildpackError::SbtBuildUnexpectedExitCode(exit_status) => log_error(
SbtBuildpackError::SbtBuildUnexpectedExitStatus(exit_status, None) => log_error(
"Running sbt failed",
formatdoc! { "
We're sorry this build is failing! If you can't find the issue in application code,
Expand All @@ -163,33 +162,16 @@ pub(crate) fn log_user_errors(error: SbtBuildpackError) {
", exit_code = exit_code_string(exit_status) },
),

SbtBuildpackError::MissingStageTask => log_error(
SbtBuildpackError::SbtBuildUnexpectedExitStatus(_, Some(SbtError::MissingTask(task_name))) => log_error(
"Failed to run sbt!",
formatdoc! {"
It looks like your build.sbt does not have a valid 'stage' task. Please reference our Dev Center article for
It looks like your build.sbt does not have a valid '{task_name}' task. Please reference our Dev Center article for
information on how to create one:
https://devcenter.heroku.com/articles/scala-support#build-behavior
"},
),

SbtBuildpackError::AlreadyDefinedAsObject => log_error(
"Failed to run sbt!",
formatdoc! {"
We're sorry this build is failing. It looks like you may need to run a clean build to remove any
stale SBT caches. You can do this by setting a configuration variable like this:
$ heroku config:set SBT_CLEAN=true
Then deploy you application with 'git push' again. If the build succeeds you can remove the variable by running this command:
$ heroku config:unset SBT_CLEAN
If this does not resolve the problem, please submit a ticket so we can help:
https://help.heroku.com
"},
),

SbtBuildpackError::DetectPhaseIoError(error) => log_please_try_again_error(
"Unexpected I/O error",
"An unexpected error occurred during the detect phase.",
Expand Down
4 changes: 2 additions & 2 deletions buildpacks/sbt/src/layers/sbt_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ fn get_layer_env_scope(available_at_launch: bool) -> Scope {
fn heroku_sbt_plugin_for_version(version: &semver::Version) -> Option<&'static [u8]> {
match version {
semver::Version { major: 0, .. } => Some(include_bytes!(
"../../assets/heroku_buildpack_plugin_sbt_v0.scala"
"../../sbt-plugins/buildpack-plugin-0.x.scala"
)),
semver::Version { major: 1, .. } => Some(include_bytes!(
"../../assets/heroku_buildpack_plugin_sbt_v1.scala"
"../../sbt-plugins/buildpack-plugin-1.x.scala"
)),
_ => None,
}
Expand Down
Loading

0 comments on commit 617f68d

Please sign in to comment.