Skip to content

Commit

Permalink
Fix issue 489 - trace level messages get evaluated to send to Pulumi …
Browse files Browse the repository at this point in the history
…engine (#492)
  • Loading branch information
lbialy authored May 23, 2024
1 parent 7161a94 commit 1314110
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
build:
if: "! github.event.pull_request.head.repo.fork"
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v1
Expand Down
82 changes: 42 additions & 40 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

besom-version := `cat version.txt`
is-snapshot := if "{{besom-version}}" =~ '.*-SNAPSHOT' { "true" } else { "false" }
no-bloop-ci := if env_var_or_default('CI', "") == "true" { "--server=false" } else { "" }

language-plugin-output-dir := justfile_directory() + "/.out/language-plugin"
codegen-output-dir := justfile_directory() + "/.out/codegen"
Expand Down Expand Up @@ -58,37 +59,37 @@ before-commit: compile-all test-all

# Compiles core besom SDK
compile-core: publish-local-json
scala-cli --power compile core --suppress-experimental-feature-warning
scala-cli --power compile {{no-bloop-ci}} core --suppress-experimental-feature-warning

# Compiles besom cats-effect extension
compile-cats: publish-local-core
scala-cli --power compile besom-cats --suppress-experimental-feature-warning
scala-cli --power compile {{no-bloop-ci}} besom-cats --suppress-experimental-feature-warning

# Compiles besom zio extension
compile-zio: publish-local-core
scala-cli --power compile besom-zio --suppress-experimental-feature-warning
scala-cli --power compile {{no-bloop-ci}} besom-zio --suppress-experimental-feature-warning

# Compiles all SDK modules
compile-sdk: compile-core compile-cats compile-zio compile-compiler-plugin

# Compiles besom compiler plugin
compile-compiler-plugin:
scala-cli --power compile compiler-plugin --suppress-experimental-feature-warning
scala-cli --power compile {{no-bloop-ci}} compiler-plugin --suppress-experimental-feature-warning

# Runs tests for core besom SDK
test-core: compile-core
@if [ {{ coverage }} = "true" ]; then mkdir -p {{coverage-output-dir-core}}; fi
scala-cli --power test core {{ scala-cli-test-options-core }} --suppress-experimental-feature-warning
scala-cli --power test {{no-bloop-ci}} core {{ scala-cli-test-options-core }} --suppress-experimental-feature-warning

# Runs tests for besom cats-effect extension
test-cats: publish-local-core
@if [ {{ coverage }} = "true" ]; then mkdir -p {{coverage-output-dir-cats}}; fi
scala-cli --power test besom-cats {{ scala-cli-test-options-cats }} --suppress-experimental-feature-warning
scala-cli --power test {{no-bloop-ci}} besom-cats {{ scala-cli-test-options-cats }} --suppress-experimental-feature-warning

# Runs tests for besom zio extension
test-zio: publish-local-core
@if [ {{ coverage }} = "true" ]; then mkdir -p {{coverage-output-dir-zio}}; fi
scala-cli --power test besom-zio {{ scala-cli-test-options-zio }} --suppress-experimental-feature-warning
scala-cli --power test {{no-bloop-ci}} besom-zio {{ scala-cli-test-options-zio }} --suppress-experimental-feature-warning

# Runs all tests
test-sdk: test-core test-cats test-zio
Expand All @@ -101,35 +102,35 @@ publish-maven-sdk: publish-maven-core publish-maven-cats publish-maven-zio publi

# Publishes locally core besom SDK
publish-local-core: publish-local-json
scala-cli --power publish local core --project-version {{besom-version}} --suppress-experimental-feature-warning
scala-cli --power publish local {{no-bloop-ci}} core --project-version {{besom-version}} --suppress-experimental-feature-warning

# Publishes locally besom cats-effect extension
publish-local-cats: publish-local-core
scala-cli --power publish local besom-cats --project-version {{besom-version}} --suppress-experimental-feature-warning
scala-cli --power publish local {{no-bloop-ci}} besom-cats --project-version {{besom-version}} --suppress-experimental-feature-warning

# Publishes locally besom zio extension
publish-local-zio: publish-local-core
scala-cli --power publish local besom-zio --project-version {{besom-version}} --suppress-experimental-feature-warning
scala-cli --power publish local {{no-bloop-ci}} besom-zio --project-version {{besom-version}} --suppress-experimental-feature-warning

# Publishes locally besom compiler plugin
publish-local-compiler-plugin:
scala-cli --power publish local compiler-plugin --project-version {{besom-version}} --suppress-experimental-feature-warning
scala-cli --power publish local {{no-bloop-ci}} compiler-plugin --project-version {{besom-version}} --suppress-experimental-feature-warning

# Publishes core besom SDK to Maven
publish-maven-core:
scala-cli --power publish core --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning
scala-cli --power publish {{no-bloop-ci}} core --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning

# Publishes besom cats-effect extension to Maven
publish-maven-cats:
scala-cli --power publish besom-cats --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning
scala-cli --power publish {{no-bloop-ci}} besom-cats --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning

# Publishes besom zio extension to Maven
publish-maven-zio:
scala-cli --power publish besom-zio --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning
scala-cli --power publish {{no-bloop-ci}} besom-zio --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning

# Publishes besom compiler plugin to Maven
publish-maven-compiler-plugin:
scala-cli --power publish compiler-plugin --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning
scala-cli --power publish {{no-bloop-ci}} compiler-plugin --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning

# Cleans core build
clean-core:
Expand Down Expand Up @@ -164,23 +165,23 @@ clean-coverage: clean-sdk

# Compiles json module
compile-json:
scala-cli --power compile besom-json --suppress-experimental-feature-warning
scala-cli --power compile {{no-bloop-ci}} besom-json --suppress-experimental-feature-warning

# Runs tests for json module
test-json:
scala-cli --power test besom-json --suppress-experimental-feature-warning
scala-cli --power test {{no-bloop-ci}} besom-json --suppress-experimental-feature-warning

# Cleans json module
clean-json:
scala-cli --power clean besom-json

# Publishes locally json module
publish-local-json:
scala-cli --power publish local besom-json --project-version {{besom-version}} --suppress-experimental-feature-warning
scala-cli --power publish local {{no-bloop-ci}} besom-json --project-version {{besom-version}} --suppress-experimental-feature-warning

# Publishes json module to Maven
publish-maven-json:
scala-cli --power publish besom-json --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning
scala-cli --power publish {{no-bloop-ci}} besom-json --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning


####################
Expand All @@ -207,6 +208,7 @@ publish-local-auto: test-auto
publish-maven-auto: test-auto
scala-cli --power publish auto --project-version {{besom-version}} {{publish-maven-auth-options}}


####################
# Language plugin
####################
Expand All @@ -219,7 +221,7 @@ tidy-language-plugin:
# Packages .jar file with language plugin bootstrap library
package-language-plugin-bootstrap:
mkdir -p {{language-plugin-output-dir}} && \
scala-cli --power package language-plugin/bootstrap --suppress-experimental-feature-warning --assembly -o {{language-plugin-output-dir}}/bootstrap.jar -f
scala-cli --power package {{no-bloop-ci}} language-plugin/bootstrap --suppress-experimental-feature-warning --assembly -o {{language-plugin-output-dir}}/bootstrap.jar -f

# Builds pulumi-language-scala binary
build-language-plugin $GOOS="" $GOARCH="":
Expand Down Expand Up @@ -284,66 +286,66 @@ publish-language-plugins-all: package-language-plugins-all

# Compiles Besom codegen module
compile-codegen:
scala-cli --power compile codegen --suppress-experimental-feature-warning
scala-cli --power compile {{no-bloop-ci}} codegen --suppress-experimental-feature-warning

# Runs tests for Besom codegen
test-codegen:
scala-cli --power test codegen --suppress-experimental-feature-warning
scala-cli --power test {{no-bloop-ci}} codegen --suppress-experimental-feature-warning

# Cleans codegen build
clean-codegen:
scala-cli clean codegen

# Publishes locally Besom codegen
publish-local-codegen: test-codegen
scala-cli --power publish local codegen --project-version {{besom-version}} --suppress-experimental-feature-warning
scala-cli --power publish local {{no-bloop-ci}} codegen --project-version {{besom-version}} --suppress-experimental-feature-warning

# Publishes Besom codegen
publish-maven-codegen: test-codegen
scala-cli --power publish codegen --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning
scala-cli --power publish {{no-bloop-ci}} codegen --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning

####################
# Integration testing
####################

# Runs all integration tests
test-integration: test-integration-core test-integration-compiler-plugin test-integration-codegen test-integration-language-plugin
scala-cli --power test integration-tests
scala-cli --power test {{no-bloop-ci}} integration-tests

# Cleans after integration tests
clean-test-integration: clean-test-integration-codegen
scala-cli --power clean integration-tests

# Runs integration tests for core
test-integration-core: publish-local-codegen publish-local-sdk install-language-plugin publish-local-compiler-plugin
scala-cli --power test integration-tests --test-only 'besom.integration.core*'
scala-cli --power test {{no-bloop-ci}} integration-tests --test-only 'besom.integration.core*'

# Runs integration tests for compiler plugin
test-integration-compiler-plugin: publish-local-codegen publish-local-core install-language-plugin publish-local-compiler-plugin
scala-cli --power test integration-tests --test-only 'besom.integration.compilerplugin*'
scala-cli --power test {{no-bloop-ci}} integration-tests --test-only 'besom.integration.compilerplugin*'

# Runs integration tests for language plugin
test-integration-language-plugin: publish-local-codegen publish-local-core install-language-plugin publish-local-compiler-plugin
export GITHUB_TOKEN=$(gh auth token); \
scala-cli --power test integration-tests --test-only 'besom.integration.languageplugin*'
scala-cli --power test {{no-bloop-ci}} integration-tests --test-only 'besom.integration.languageplugin*'

# Runs fast integration tests for codegen
test-integration-codegen: publish-local-core publish-local-codegen
export GITHUB_TOKEN=$(gh auth token); \
scala-cli --power test integration-tests --test-only 'besom.integration.codegen*'
scala-cli --power test {{no-bloop-ci}} integration-tests --test-only 'besom.integration.codegen*'

# Runs fast&slow integration tests for codegen
test-integration-codegen-slow: publish-local-core publish-local-codegen
export GITHUB_TOKEN=$(gh auth token); \
scala-cli --power test integration-tests --test-only 'besom.integration.codegen*' -- --include-categories=Slow
scala-cli --power test {{no-bloop-ci}} integration-tests --test-only 'besom.integration.codegen*' -- --include-categories=Slow

# Cleans after the codegen integration tests
clean-test-integration-codegen:
rm -rf integration-tests/resources/testdata/*/codegen

# Copies test schemas from pulumi repo to the testdata directory
copy-test-schemas:
scala-cli run --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning scripts -- schemas all
scala-cli run {{no-bloop-ci}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning scripts -- schemas all

####################
# Templates and examples
Expand All @@ -354,7 +356,7 @@ test-template template-name:
@echo "----------------------------------------"
@echo "Testing template {{template-name}}"
pulumi --non-interactive --logtostderr --color=never --emoji=false new -y --force --generate-only --dir target/test/{{template-name}} -n templates-test-{{template-name}} --stack templates-test-{{template-name}} ../../../templates/{{template-name}}/
scala-cli compile target/test/{{template-name}} {{ci-opts}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning
scala-cli compile {{no-bloop-ci}} target/test/{{template-name}} {{ci-opts}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning

# Cleans after a template test
clean-test-template template-name:
Expand All @@ -377,7 +379,7 @@ clean-test-templates:
test-example example-name:
@echo "----------------------------------------"
@echo "Testing example {{example-name}}"
scala-cli compile examples/{{example-name}} {{ci-opts}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning
scala-cli compile {{no-bloop-ci}} examples/{{example-name}} {{ci-opts}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning

# Cleans after an example test
clean-test-example example-name:
Expand Down Expand Up @@ -413,27 +415,27 @@ clean-test-markdown:

# Compiles Besom scripts module
compile-scripts: publish-local-codegen
scala-cli --power compile scripts --suppress-experimental-feature-warning
scala-cli --power compile {{no-bloop-ci}} scripts --suppress-experimental-feature-warning

# Clean Besom scripts module
clean-scripts:
scala-cli --power clean scripts

# Runs tests for Besom scripts
test-scripts:
scala-cli --power test scripts --suppress-experimental-feature-warning
scala-cli --power test {{no-bloop-ci}} scripts --suppress-experimental-feature-warning

# Publishes locally Besom scripts module
publish-local-scripts: test-scripts
scala-cli --power publish local scripts --project-version {{besom-version}} --suppress-experimental-feature-warning
scala-cli --power publish local {{no-bloop-ci}} scripts --project-version {{besom-version}} --suppress-experimental-feature-warning

# Publishes Besom scripts module
publish-maven-scripts: test-scripts
scala-cli --power publish scripts --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning
scala-cli --power publish {{no-bloop-ci}} scripts --project-version {{besom-version}} {{publish-maven-auth-options}} --suppress-experimental-feature-warning

# Use Besom scripts directly
cli *ARGS:
scala-cli run scripts {{ci-opts}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning scripts -- {{ARGS}}
scala-cli run {{no-bloop-ci}} scripts {{ci-opts}} --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning scripts -- {{ARGS}}

# Create or Update GitHub release
upsert-gh-release:
Expand Down Expand Up @@ -497,8 +499,8 @@ clean-slate-liftoff: clean-sdk
#!/usr/bin/env sh
just publish-local-core
just publish-local-compiler-plugin
scala-cli run codegen -- named kubernetes 4.2.0
scala-cli --power publish local .out/codegen/kubernetes/4.2.0/ --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning
scala-cli run {{no-bloop-ci}} codegen -- named kubernetes 4.2.0
scala-cli --power publish local {{no-bloop-ci}} .out/codegen/kubernetes/4.2.0/ --suppress-experimental-feature-warning --suppress-directives-in-multiple-files-warning
just clean-liftoff
just liftoff
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/besom/internal/logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ object logging:
private val queue: Queue[LogRequest | Queue.Stop],
private val fib: Fiber[Unit]
) extends BesomLogger:

def close(): Result[Unit] = queue.offer(Queue.Stop) *> fib.join

override def log(record: LogRecord): Result[Unit] = Result(Logger(record.className).log(record))

override def log(record: LogRecord, urn: URN, streamId: Int, ephemeral: Boolean): Result[Unit] =
for
_ <- log(record) // direct logging
_ <- queue.offer(makeLogRequest(record, urn, streamId, ephemeral)) // logging via RPC (async via queue)
// logging via RPC (async via queue)
_ <- queue.offer(makeLogRequest(record, urn, streamId, ephemeral)) // this unfortunately evaluates all lazy log messages
yield ()

object BesomLogger:
Expand Down
23 changes: 20 additions & 3 deletions core/src/main/scala/besom/util/printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ package besom.util
import besom.internal.Output
import pprint.*

private def escapeSpecialCharacters(input: String): String =
input.flatMap {
case '\n' => "\\n"
case '\t' => "\\t"
case '\r' => "\\r"
case '\b' => "\\b"
case '\f' => "\\f"
case '\u001B' => "\\x1b"
case ch if ch.isControl => "\\u%04x".format(ch.toInt) // other control characters
case ch => ch.toString
}

object printer
extends PPrinter(
defaultWidth = 140,
defaultHeight = Int.MaxValue,
defaultIndent = 2,
additionalHandlers = { case o: Output[?] =>
Tree.Literal("Output(?)")
additionalHandlers = {
case o: Output[?] => Tree.Literal("Output(?)")
case s: String if s.nonEmpty => Tree.Literal(s"\"${escapeSpecialCharacters(s)}\"")
}
):

Expand All @@ -33,6 +46,10 @@ object printer
height: Int = defaultHeight,
indent: Int = defaultIndent,
initialOffset: Int = 0
): fansi.Str = this.apply(x, width, height, indent, initialOffset)
): fansi.Str =
try this.apply(x, width, height, indent, initialOffset)
catch
case e: Exception =>
fansi.Color.Red("Error rendering: ") ++ fansi.Str(e.toString) ++ fansi.Str("\n") ++ fansi.Str(e.getStackTrace.mkString("\n"))

end printer

0 comments on commit 1314110

Please sign in to comment.