Skip to content
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
34 changes: 34 additions & 0 deletions .github/workflows/build-cli-e2e-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ env:
CLI_E2E_POLYGLOT_IMAGE_TAG: aspire-cli-e2e-polyglot:prebuilt
CLI_E2E_POLYGLOT_JAVA_IMAGE_ARTIFACT: cli-e2e-polyglot-java-image
CLI_E2E_POLYGLOT_JAVA_IMAGE_TAG: aspire-cli-e2e-polyglot-java:prebuilt
CLI_E2E_POLYGLOT_GO_IMAGE_ARTIFACT: cli-e2e-polyglot-go-image
CLI_E2E_POLYGLOT_GO_IMAGE_TAG: aspire-cli-e2e-polyglot-go:prebuilt
CLI_E2E_POLYGLOT_BASE_IMAGE_TAG: aspire-e2e-polyglot-base:latest
CLI_E2E_POLYGLOT_BASE_IMAGE_CACHE_SCOPE: cli-e2e-polyglot-base
CLI_E2E_INCLUDE_POLYGLOT_IMAGES: ${{ inputs.includePolyglotImages }}
Expand Down Expand Up @@ -104,6 +106,24 @@ jobs:
.
}

build_go_image() {
local mirror="$1"
local -a build_args=()

if [[ -n "$mirror" ]]; then
echo "Building Go polyglot image with Ubuntu apt mirror: $mirror"
build_args+=(--build-arg "UBUNTU_APT_MIRROR=$mirror")
else
echo "Building Go polyglot image with the default Ubuntu apt sources"
fi

DOCKER_BUILDKIT=1 docker build \
"${build_args[@]}" \
-f tests/Shared/Docker/Dockerfile.e2e-polyglot-go \
-t "$CLI_E2E_POLYGLOT_GO_IMAGE_TAG" \
.
}

build_with_mirror_retry() {
local display_name="$1"
local dockerfile="$2"
Expand All @@ -126,6 +146,11 @@ jobs:
echo "Java polyglot image build failed with the Azure Ubuntu apt mirror; retrying with default Ubuntu apt sources"
build_java_image ""
fi

if ! build_go_image "http://azure.archive.ubuntu.com/ubuntu/"; then
echo "Go polyglot image build failed with the Azure Ubuntu apt mirror; retrying with default Ubuntu apt sources"
build_go_image ""
fi
fi

- name: Save CLI E2E Docker image tarballs
Expand All @@ -139,6 +164,7 @@ jobs:
if [[ "$CLI_E2E_INCLUDE_POLYGLOT_IMAGES" == "true" ]]; then
docker save "$CLI_E2E_POLYGLOT_IMAGE_TAG" | gzip > artifacts/cli-e2e-image/aspire-cli-e2e-polyglot.tar.gz
docker save "$CLI_E2E_POLYGLOT_JAVA_IMAGE_TAG" | gzip > artifacts/cli-e2e-image/aspire-cli-e2e-polyglot-java.tar.gz
docker save "$CLI_E2E_POLYGLOT_GO_IMAGE_TAG" | gzip > artifacts/cli-e2e-image/aspire-cli-e2e-polyglot-go.tar.gz
fi

- name: Upload CLI E2E .NET Docker image
Expand All @@ -164,3 +190,11 @@ jobs:
name: ${{ env.CLI_E2E_POLYGLOT_JAVA_IMAGE_ARTIFACT }}
path: artifacts/cli-e2e-image/aspire-cli-e2e-polyglot-java.tar.gz
retention-days: 1

- name: Upload CLI E2E Go Docker image
if: ${{ inputs.uploadImageArtifacts && inputs.includePolyglotImages }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ env.CLI_E2E_POLYGLOT_GO_IMAGE_ARTIFACT }}
path: artifacts/cli-e2e-image/aspire-cli-e2e-polyglot-go.tar.gz
retention-days: 1
10 changes: 9 additions & 1 deletion .github/workflows/reproduce-flaky-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ jobs:
name: cli-e2e-polyglot-java-image
path: ${{ github.workspace }}/cli-e2e-image

- name: Download prebuilt CLI E2E Go Docker image
if: ${{ needs.setup.outputs.is_cli_e2e == 'true' && runner.os == 'Linux' }}
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: cli-e2e-polyglot-go-image
path: ${{ github.workspace }}/cli-e2e-image

- name: Download prebuilt CLI E2E polyglot Docker image
if: ${{ needs.setup.outputs.is_cli_e2e == 'true' && runner.os == 'Linux' }}
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
Expand All @@ -213,7 +220,8 @@ jobs:
--image-dir "${{ github.workspace }}/cli-e2e-image" \
--require-dotnet true \
--require-polyglot true \
--require-java true
--require-java true \
--require-go true

- name: Unlock macOS keychain
if: runner.os == 'macOS'
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ jobs:
name: cli-e2e-polyglot-java-image
path: ${{ github.workspace }}/cli-e2e-image

# Go CLI E2E classes are named Go*, so '-Go' matches the class suffix of the split job name
# (Cli.EndToEnd-GoStarterTemplateTests) without matching names that merely contain "go" (MongoDB, Config).
- name: Download prebuilt CLI E2E Go Docker image
if: ${{ fromJson(inputs.properties).requiresCliArchive == true && runner.os == 'Linux' && contains(inputs.testShortName, '-Go') }}
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: cli-e2e-polyglot-go-image
path: ${{ github.workspace }}/cli-e2e-image

- name: Load prebuilt CLI E2E Docker images
if: ${{ fromJson(inputs.properties).requiresCliArchive == true && runner.os == 'Linux' }}
shell: bash
Expand All @@ -171,7 +180,8 @@ jobs:
--image-dir "${{ github.workspace }}/cli-e2e-image" \
--require-dotnet true \
--require-polyglot true \
--require-java "${{ contains(inputs.testShortName, 'Java') }}"
--require-java "${{ contains(inputs.testShortName, 'Java') }}" \
--require-go "${{ contains(inputs.testShortName, '-Go') }}"

- name: Download built nugets
if: ${{ fromJson(inputs.properties).requiresNugets == true }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/warm-cli-e2e-image-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- 'eng/scripts/get-aspire-cli-pr.sh'
- 'tests/Shared/Docker/Dockerfile.e2e'
- 'tests/Shared/Docker/Dockerfile.e2e-polyglot-base'
- 'tests/Shared/Docker/Dockerfile.e2e-polyglot-go'
- 'tests/Shared/Docker/Dockerfile.e2e-polyglot-java'
- 'tests/Shared/Docker/NuGet.DotnetTool.config'
- 'tests/Shared/Docker/configure-ubuntu-apt-mirror.sh'
Expand Down
7 changes: 4 additions & 3 deletions docs/ci/cli-e2e-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The reusable `.github/workflows/build-cli-e2e-image.yml` workflow produces these
| DotNet | `tests/Shared/Docker/Dockerfile.e2e` | `cli-e2e-dotnet-image` | `aspire-cli-e2e-dotnet:prebuilt` | `ASPIRE_E2E_DOTNET_IMAGE` | `ASPIRE_E2E_REQUIRE_DOTNET_IMAGE` |
| Polyglot | `tests/Shared/Docker/Dockerfile.e2e-polyglot-base` | `cli-e2e-polyglot-image` | `aspire-cli-e2e-polyglot:prebuilt` | `ASPIRE_E2E_POLYGLOT_IMAGE` | `ASPIRE_E2E_REQUIRE_POLYGLOT_IMAGE` |
| Polyglot Java | `tests/Shared/Docker/Dockerfile.e2e-polyglot-java` | `cli-e2e-polyglot-java-image` | `aspire-cli-e2e-polyglot-java:prebuilt` | `ASPIRE_E2E_POLYGLOT_JAVA_IMAGE` | `ASPIRE_E2E_REQUIRE_POLYGLOT_JAVA_IMAGE` |
| Polyglot Go | `tests/Shared/Docker/Dockerfile.e2e-polyglot-go` | `cli-e2e-polyglot-go-image` | `aspire-cli-e2e-polyglot-go:prebuilt` | `ASPIRE_E2E_POLYGLOT_GO_IMAGE` | `ASPIRE_E2E_REQUIRE_POLYGLOT_GO_IMAGE` |

`Dockerfile.e2e-podman` is not part of this contract because it uses a separate privileged Podman-in-Docker runtime path.

Expand All @@ -22,9 +23,9 @@ This preserves the local development path while making opted-in CI jobs fail ear

## Workflow behavior

The image build workflow has an `includePolyglotImages` input. It defaults to `true` and builds all three shared images. Daily CLI smoke tests set it to `false` because they only need the DotNet image.
The image build workflow has an `includePolyglotImages` input. It defaults to `true` and builds all four shared images. Daily CLI smoke tests set it to `false` because they only need the DotNet image.

Consumer workflows download image artifacts into `${{ github.workspace }}/cli-e2e-image` and call `eng/scripts/load-cli-e2e-images.sh` to load the images and export the matching environment variables. Regular split CLI E2E jobs always require DotNet and Polyglot images. Java image download and loading is conditional on Java test jobs to avoid transferring the larger Java tarball to every split job.
Consumer workflows download image artifacts into `${{ github.workspace }}/cli-e2e-image` and call `eng/scripts/load-cli-e2e-images.sh` to load the images and export the matching environment variables. Regular split CLI E2E jobs always require DotNet and Polyglot images. Java and Go image download and loading is conditional on the split job name to avoid transferring the larger tarballs to every split job: Java jobs match `Java` and Go jobs match `-Go`, so Go CLI E2E test classes must be named `Go*` (for example `Cli.EndToEnd-GoStarterTemplateTests`). Specialized quarantine and outerloop runs are named after the test project, so a Go or Java class that is quarantined or marked outerloop does not receive its prebuilt image.

The reusable image build workflow also has an `uploadImageArtifacts` input. It defaults to `true` for test workflows because each isolated test job needs the image tarballs. Cache-warming workflows set it to `false` so they only build the images and export BuildKit cache layers.

Expand All @@ -39,7 +40,7 @@ The image build workflow exports BuildKit layers to the GitHub Actions cache wit

GitHub Actions does not let one pull request restore cache entries written by a sibling pull request. Pull request runs can restore cache entries from the current PR ref and from the base/default branch. The `.github/workflows/warm-cli-e2e-image-cache.yml` workflow runs on `main` by schedule, manual dispatch, and relevant `main` pushes so new PRs can restore layers seeded from `main`.

The Java image is built from the local polyglot base image and does not use a separate shared BuildKit cache scope.
The Java and Go images are built from the local polyglot base image and do not use a separate shared BuildKit cache scope.

## Adding another variant

Expand Down
2 changes: 2 additions & 0 deletions eng/github-ci/test-trigger-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,14 @@ affected_project_rules:
- Aspire.Hosting
- Aspire.Hosting.AppHost
- Aspire.Hosting.Blazor
- Aspire.Hosting.CodeGeneration.Go
- Aspire.Hosting.CodeGeneration.Java
- Aspire.Hosting.CodeGeneration.TypeScript
- Aspire.Hosting.Docker
- Aspire.Hosting.Dotnet
- Aspire.Hosting.EntityFrameworkCore
- Aspire.Hosting.Garnet
- Aspire.Hosting.Go
- Aspire.Hosting.Java
- Aspire.Hosting.JavaScript
- Aspire.Hosting.Kubernetes
Expand Down
16 changes: 16 additions & 0 deletions eng/scripts/load-cli-e2e-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ github_env="${GITHUB_ENV:-}"
require_dotnet="false"
require_polyglot="false"
require_java="false"
require_go="false"

usage() {
cat <<'EOF'
Expand All @@ -21,6 +22,7 @@ Options:
--require-dotnet <mode> true, false, or auto. Defaults to false.
--require-polyglot <mode> true, false, or auto. Defaults to false.
--require-java <mode> true, false, or auto. Defaults to false.
--require-go <mode> true, false, or auto. Defaults to false.

Mode behavior:
true The tarball must exist. Load it, export IMAGE and REQUIRE=true.
Expand Down Expand Up @@ -105,6 +107,14 @@ while [[ $# -gt 0 ]]; do
require_java="$(normalize_mode "--require-java" "${1#*=}")"
shift
;;
--require-go)
require_go="$(normalize_mode "$1" "$(read_value_arg "$1" "${2:-}")")"
shift 2
;;
--require-go=*)
require_go="$(normalize_mode "--require-go" "${1#*=}")"
shift
;;
-h|--help)
usage
exit 0
Expand Down Expand Up @@ -184,3 +194,9 @@ load_image "Java polyglot" "$require_java" \
"aspire-cli-e2e-polyglot-java:prebuilt" \
"ASPIRE_E2E_POLYGLOT_JAVA_IMAGE" \
"ASPIRE_E2E_REQUIRE_POLYGLOT_JAVA_IMAGE"

load_image "Go polyglot" "$require_go" \
"aspire-cli-e2e-polyglot-go.tar.gz" \
"aspire-cli-e2e-polyglot-go:prebuilt" \
"ASPIRE_E2E_POLYGLOT_GO_IMAGE" \
"ASPIRE_E2E_REQUIRE_POLYGLOT_GO_IMAGE"
84 changes: 84 additions & 0 deletions tests/Aspire.Cli.EndToEnd.Tests/GoCodegenValidationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Cli.EndToEnd.Tests.Helpers;
using Hex1b.Automation;
using Xunit;

namespace Aspire.Cli.EndToEnd.Tests;

/// <summary>
/// End-to-end tests that validate <c>aspire restore</c> for Go AppHosts by creating a
/// Go AppHost with multiple integrations and verifying the generated Go SDK files.
/// </summary>
public sealed class GoCodegenValidationTests(ITestOutputHelper output)
{
[Fact]
[CaptureWorkspaceOnFailure]
public async Task RestoreGeneratesSdkFiles()
{
var repoRoot = CliE2ETestHelpers.GetRepoRoot();
var strategy = CliInstallStrategy.Detect(output.WriteLine);
using var workspace = TemporaryWorkspace.Create(output);

using var terminal = CliE2ETestHelpers.CreateDockerTestTerminal(repoRoot, strategy, output, variant: CliE2ETestHelpers.DockerfileVariant.PolyglotGo, workspace: workspace);
var counter = new SequenceCounter();
var auto = new Hex1bTerminalAutomator(terminal, defaultTimeout: TimeSpan.FromSeconds(500));
await using var terminalRun = CliE2ETestHelpers.StartRun(terminal, workspace, auto, counter, output, TestContext.Current.CancellationToken);

await auto.PrepareDockerEnvironmentAsync(counter, workspace);
await auto.InstallAspireCliAsync(strategy, counter);
await auto.EnableExperimentalGoSupportAsync(counter);

await auto.AspireInitGoAppHostAsync(counter);

await auto.AspireAddPackageAsync("Aspire.Hosting.Redis", counter);
await auto.RunCommandAsync("aspire restore --non-interactive", counter, TimeSpan.FromMinutes(3));

var modulesDir = Path.Combine(workspace.WorkspaceRoot.FullName, ".aspire", "modules");
Assert.True(Directory.Exists(modulesDir), $".aspire/modules directory was not created at {modulesDir}");

// aspire.go is the whole generated SDK in one file, so assert on substrings and keep it out of failure messages.
var sdkPath = Path.Combine(modulesDir, "aspire.go");
var codegenHashPath = Path.Combine(modulesDir, ".codegen-hash");
Assert.True(File.Exists(sdkPath), $"Expected generated file not found: {sdkPath}");
Assert.True(File.Exists(codegenHashPath), $"Expected generated file not found: {codegenHashPath}");
Assert.False(
File.ReadAllText(sdkPath).Contains("AddSqlServer", StringComparison.Ordinal),
"Baseline SDK already exposes AddSqlServer; test cannot verify refresh behavior after adding Aspire.Hosting.SqlServer.");
var initialCodegenHash = File.ReadAllText(codegenHashPath);

// `aspire add` regenerates the SDK itself, so once it returns aspire.go already exposes AddSqlServer and
// .codegen-hash has already changed, and the restore below would have nothing left to prove. Putting the
// baseline copies back leaves a stale SDK next to an aspire.config.json that lists SqlServer, which is
// the state a restore has to refresh. The copies run inside the container: the workspace is bind-mounted
// and its files belong to the container's root user, so a write from the host can fail on Linux.
await auto.RunCommandAsync("mkdir -p ~/sdk-baseline && cp .aspire/modules/aspire.go .aspire/modules/.codegen-hash ~/sdk-baseline/", counter);
await auto.AspireAddPackageAsync("Aspire.Hosting.SqlServer", counter);
await auto.RunCommandAsync("cp ~/sdk-baseline/aspire.go ~/sdk-baseline/.codegen-hash .aspire/modules/", counter);

Assert.False(
File.ReadAllText(sdkPath).Contains("AddSqlServer", StringComparison.Ordinal),
"The baseline SDK was not put back after aspire add, so restore would have nothing to refresh.");
Assert.Equal(initialCodegenHash, File.ReadAllText(codegenHashPath));

await auto.RunCommandAsync("aspire restore --non-interactive", counter, TimeSpan.FromMinutes(3));

var expectedFiles = new[] { "aspire.go", "base.go", "transport.go", "go.mod" };

foreach (var file in expectedFiles)
{
var filePath = Path.Combine(modulesDir, file);
Assert.True(File.Exists(filePath), $"Expected generated file not found: {filePath}");
Assert.False(string.IsNullOrWhiteSpace(File.ReadAllText(filePath)), $"Generated file is empty: {filePath}");
}

var sdk = File.ReadAllText(sdkPath);
Assert.True(sdk.Contains("AddRedis", StringComparison.Ordinal), "aspire.go does not contain AddRedis from Aspire.Hosting.Redis");
Assert.True(
sdk.Contains("AddSqlServer", StringComparison.Ordinal),
"aspire.go does not contain AddSqlServer from Aspire.Hosting.SqlServer; restore did not refresh an already-populated .aspire/modules");

Assert.NotEqual(initialCodegenHash, File.ReadAllText(codegenHashPath));
}
}
Loading
Loading