Commit 3052f281 authored by shRabbit's avatar shRabbit
Browse files

Add configurable runtime and NativeAOT support to publish job

parent 1646b3fe
Loading
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -36,6 +36,14 @@ spec:
    # Output folder for the publish job.
    publish_output:
      default: publish
    # Target runtime for the publish job (e.g. linux-x64, win-x64).
    # Leave empty for a framework-dependent (JIT) publish.
    runtime:
      default: ""
    # Set to "true" to publish with NativeAOT. Requires a target `runtime`
    # (defaults to linux-x64 when empty) and installs the AOT toolchain.
    aot_enabled:
      default: false
    # Pipeline stage all the generated jobs run in.
    stage:
      default: build
@@ -49,6 +57,8 @@ variables:
  RUN_TESTS: "$[[ inputs.tests_enabled ]]"
  ENABLE_PUBLISH: "$[[ inputs.publish_enabled ]]"
  PUBLISH_OUTPUT: "$[[ inputs.publish_output ]]"
  PUBLISH_RUNTIME: "$[[ inputs.runtime ]]"
  AOT_ENABLED: "$[[ inputs.aot_enabled ]]"
  # Keep the NuGet package cache inside the project dir so jobs share it.
  NUGET_PACKAGES: "$CI_PROJECT_DIR/.nuget/packages"

@@ -102,14 +112,21 @@ dotnet-test:
    - when: always

# Produce a deployable output (enabled via the `publish_enabled` input).
# Defaults to a framework-dependent (JIT) publish; set `runtime` to publish a
# self-contained build and `aot_enabled` to compile with NativeAOT.
dotnet-publish:
  image: "mcr.microsoft.com/dotnet/sdk:$DOTNET_VERSION"
  stage: $[[ inputs.stage ]]
  variables:
    DOTNET_PUBLISH_ARGS: "$[[ inputs.solution_path ]]"
  before_script:
    - if [ "$AOT_ENABLED" = "true" ]; then apt-get update && apt-get install -y --no-install-recommends clang zlib1g-dev; fi
  script:
    - if [ -z "$DOTNET_PUBLISH_ARGS" ]; then echo "No solution/project specified, skipping publish." && exit 0; fi
    - dotnet publish "$DOTNET_PUBLISH_ARGS" -p:Configuration="$BUILD_CONFIGURATION" --output "$PUBLISH_OUTPUT"
    - PUBLISH_EXTRA="-p:PublishAot=false"
    - if [ "$AOT_ENABLED" = "true" ]; then PUBLISH_EXTRA="-p:PublishAot=true"; if [ -z "$PUBLISH_RUNTIME" ]; then PUBLISH_RUNTIME="linux-x64"; fi; fi
    - if [ -n "$PUBLISH_RUNTIME" ]; then PUBLISH_EXTRA="$PUBLISH_EXTRA -r $PUBLISH_RUNTIME"; fi
    - dotnet publish "$DOTNET_PUBLISH_ARGS" -p:Configuration="$BUILD_CONFIGURATION" $PUBLISH_EXTRA --output "$PUBLISH_OUTPUT"
  artifacts:
    paths:
      - "$PUBLISH_OUTPUT/**"