Skip to content

Commit

Permalink
Run End-To-End tests in our CI (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell authored Sep 29, 2023
2 parents 73355ea + 22c05a6 commit 315f9ed
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 120 deletions.
191 changes: 191 additions & 0 deletions .github/workflows/qa-azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: Build and run end-to-end tests
# Builds the project, and runs end-to-end tests using the generated artifacts.

concurrency: azure-vm

on:
pull_request:
workflow_dispatch:
push:
branches: [main]

env:
az_name: wsl-ci-3
az_resource_group: wsl
flutter-version: 3.13.x

jobs:
build-wsl-pro-service:
name: Build wsl-pro-service debian package
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Build debian package
uses: canonical/desktop-engineering/gh-actions/common/build-debian@main
with:
source-dir: wsl-pro-service
token: ${{ secrets.GITHUB_TOKEN }}
docker-image: ubuntu:devel
env:
UP4W_SKIP_INTERNAL_DEPENDENCY_UPDATE: "1"

build-ubuntu-pro-for-windows:
name: Build Windows Agent Appx
runs-on: windows-latest
steps:
- name: Set up git
uses: canonical/ubuntu-pro-for-windows/.github/actions/setup-git@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check out repository
uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: go.work
- uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: ${{ env.flutter-version }}
- name: Setup MSBuild (PATH)
uses: microsoft/[email protected]
- name: Install certificate
shell: powershell
run: |
New-Item -ItemType directory -Path certificate
Set-Content -Path certificate\certificate.txt -Value '${{ secrets.CERTIFICATE }}'
certutil -decode certificate\certificate.txt certificate\certificate.pfx
$pwd = ConvertTo-SecureString '${{ secrets.CERTIFICATE_PASSWORD }}' -AsPlainText -Force
Import-PfxCertificate -Password $pwd -CertStoreLocation Cert:LocalMachine\Trust -FilePath certificate\certificate.pfx
Import-PfxCertificate -Password $pwd -CertStoreLocation Cert:CurrentUser\My -FilePath certificate\certificate.pfx
- name: Build Bundle
run: |
msbuild `
.\msix\msix.sln `
-target:Build `
-maxCpuCount `
-nodeReuse:false `
-property:Configuration=Release `
-property:AppxBundle=Always `
-property:AppxBundlePlatforms=x64 `
-property:UapAppxPackageBuildMode=SideloadOnly `
-property:Version=0.0.1+${{ github.sha }} `
-nologo `
-verbosity:normal
- name: Upload sideload artifact
uses: actions/upload-artifact@v3
with:
name: UbuntuProForWindows+${{ github.sha }}
path: |
msix/UbuntuProForWindows/AppPackages/UbuntuProForWindows_*/UbuntuProForWindows_*_x64.cer
msix/UbuntuProForWindows/AppPackages/UbuntuProForWindows_*/UbuntuProForWindows_*_x64.msixbundle
vm-setup:
name: Set up Azure VM
runs-on: ubuntu-latest
steps:
- name: Azure login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_VM_CREDS }}
- name: Start the Runner
shell: bash
run: |
az vm start --name ${{ env.az_name }} --resource-group ${{ env.az_resource_group }}
qa:
name: Run end-to-end tests on the Azure VM
runs-on: [self-hosted, Windows]
needs: [vm-setup, build-wsl-pro-service, build-ubuntu-pro-for-windows]
steps:
- name: Set up git
uses: canonical/ubuntu-pro-for-windows/.github/actions/setup-git@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Ubuntu
uses: Ubuntu/WSL/.github/actions/wsl-install@main
with:
distro: "Ubuntu"
- name: Set up Go
# actions/setup-go is broken
shell: powershell
run: |
winget install GoLang.Go --accept-source-agreements --accept-package-agreements --silent --verbose
# Cannot check for error: there is no way to distinguish the two:
# - Legitimate error
# - Error because no updates found (Golang.Go is already up to date)
#
# We can check that Go works, though.
go version
- name: Download artifacts
uses: actions/download-artifact@v3
with:
# name: is left blank so that all artifacts are downloaded
path: ci-artifacts
- name: Set up artifacts
shell: powershell
working-directory: ci-artifacts
run: |
Write-Output "::group::Set up AppxPackage"
Get-AppxPackage -Name "CanonicalGroupLimited.UbuntuProForWindows" | Remove-AppxPackage -ErrorAction Ignore
New-Item -Name "windows-agent" -ItemType Directory
Move-Item -Path "UbuntuProForWindows+*/UbuntuProForWindows_*/*.msixbundle" -Destination "windows-agent/"
Move-Item -Path "UbuntuProForWindows+*/UbuntuProForWindows_*/*.cer" -Destination "windows-agent/"
Remove-Item -Recurse "UbuntuProForWindows+*/"
$cert = "$(Get-ChildItem windows-agent/UbuntuProForWindows_*.cer)"
Import-Certificate -FilePath "${cert}" -CertStoreLocation Cert:LocalMachine\TrustedPeople
Write-Output "::endgroup::"
Write-Output "::group::Set up WSL Pro Service"
New-Item -Name "wsl-pro-service" -ItemType Directory
Move-Item -Path "wsl-pro-service_*/wsl-pro-service_*.deb" -Destination "wsl-pro-service/"
Remove-Item -Recurse "wsl-pro-service_*/"
Write-Output "::endgroup::"
- name: Test
shell: powershell
env:
GIT_TERMINAL_PROMPT: "0"
UP4W_TEST_OVERRIDE_DESTRUCTIVE_CHECKS: "1"
UP4W_TEST_BUILD_PATH: "../ci-artifacts"
UP4W_TEST_PRO_TOKEN: "${{ secrets.UBUNTU_PRO_TOKEN }}"
run: |
go env -w "GOPRIVATE=github.com/${{ github.repository }}"
go test .\end-to-end -shuffle=on -timeout 20m
if ( "$LastExitCode" -ne "0" ) { Exit(1) }
- name: Clean up
if: always()
shell: powershell
run: |
# Clean up artifacts
# Remove .gitconfig so that the github URL overrides do not stack
Remove-Item -Recurse -Path "${HOME}\.gitconfig" -ErrorAction Ignore
# Uninstall Appx
Get-AppxPackage -Name "CanonicalGroupLimited.UbuntuProForWindows" | Remove-AppxPackage -ErrorAction Ignore
# Uninstall certificate
$thumbprint = (Get-PfxCertificate -FilePath "ci-artifacts\windows-agent\UbuntuProForWindows_*.cer").Thumbprint
Remove-Item -Path "Cert:LocalMachine\TrustedPeople\${thumbprint}"
stop-vm:
name: Clean up the Azure VM
runs-on: ubuntu-latest
needs: [vm-setup, qa]
if: always()
steps:
- name: Azure login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_VM_CREDS }}
- name: Deallocate the Runner
shell: bash
run: |
az vm deallocate --name ${{ env.az_name }} --resource-group ${{ env.az_resource_group }}
66 changes: 0 additions & 66 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,69 +256,3 @@ jobs:
uses: ./.github/actions/check-diff
with:
files-to-validate: '${{ matrix.subproject }}/{.,**}/*.{dart,go}'

build-wsl-pro-service:
name: Build wsl-pro-service debian package
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Build debian package
uses: canonical/desktop-engineering/gh-actions/common/build-debian@main
with:
source-dir: wsl-pro-service
token: ${{ secrets.GITHUB_TOKEN }}
docker-image: ubuntu:devel
env:
UP4W_SKIP_INTERNAL_DEPENDENCY_UPDATE: "1"

build-ubuntu-pro-for-windows:
name: Build Windows Agent Appx
runs-on: windows-latest
steps:
- name: Set up git
uses: canonical/ubuntu-pro-for-windows/.github/actions/setup-git@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check out repository
uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: go.work
- uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: ${{ env.flutter-version }}
- name: Setup MSBuild (PATH)
uses: microsoft/[email protected]
- name: Install certificate
shell: powershell
run: |
New-Item -ItemType directory -Path certificate
Set-Content -Path certificate\certificate.txt -Value '${{ secrets.CERTIFICATE }}'
certutil -decode certificate\certificate.txt certificate\certificate.pfx
$pwd = ConvertTo-SecureString '${{ secrets.CERTIFICATE_PASSWORD }}' -AsPlainText -Force
Import-PfxCertificate -Password $pwd -CertStoreLocation Cert:LocalMachine\Trust -FilePath certificate\certificate.pfx
Import-PfxCertificate -Password $pwd -CertStoreLocation Cert:CurrentUser\My -FilePath certificate\certificate.pfx
- name: Build Bundle
run: |
msbuild `
.\msix\msix.sln `
-target:Build `
-maxCpuCount `
-nodeReuse:false `
-property:Configuration=Release `
-property:AppxBundle=Always `
-property:AppxBundlePlatforms=x64 `
-property:UapAppxPackageBuildMode=SideloadOnly `
-property:Version=0.0.1+${{ github.sha }} `
-nologo `
-verbosity:normal
- name: Upload sideload artifact
uses: actions/upload-artifact@v3
with:
name: UbuntuProForWindows+${{ github.sha }}
path: |
msix/UbuntuProForWindows/AppPackages/UbuntuProForWindows_*/UbuntuProForWindows_1.0.0.0_x64.cer
msix/UbuntuProForWindows/AppPackages/UbuntuProForWindows_*/UbuntuProForWindows_1.0.0.0_x64.msixbundle
6 changes: 3 additions & 3 deletions doc/02.-Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This guide will show you how to install Ubuntu Pro For Windows for local develop

### Download
<!-- TODO: Update when we cange were artifcats are hosted -->
1. Go to the [repository actions page](https://github.com/canonical/ubuntu-pro-for-windows/actions/workflows/qa.yaml?query=branch%3Amain+).
1. Go to the [repository actions page](https://github.com/canonical/ubuntu-pro-for-windows/actions/workflows/qa-azure.yaml?query=branch%3Amain+).
2. Click the latest successful workflow run.
3. Scroll down past any warnings or errors, until you reach the Artifacts section.
4. Download:
Expand All @@ -27,7 +27,7 @@ This is the Windows-side agent that manages the distros.
2. Follow the download steps to download UbuntuProForWindows
3. Unzip the artifact
4. Find the certificate inside. Install it into `Local Machine/Trusted people`.
5. Open Powershell in this directory and run
5. Open Powershell in this directory and run
```powershell
Add-AppxPackage .\UbuntuProForWindows_*_x64.msixbundle
```
Expand Down Expand Up @@ -91,7 +91,7 @@ You can use a private Landscape instance (different from [landscape.canonical.co
4. Click on "Click to restart it".
9. Stop the distro you installed WSL-Pro-Service in:
```powershell
wsl --terminate DISTRO_NAME
wsl --terminate DISTRO_NAME
```
10. Start the distro you installed WSL-Pro-Service in.
11. You should see a new "pending computer authorisation" in you Landscape dashboard.
1 change: 1 addition & 0 deletions end-to-end/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/ubuntu/decorate v0.0.0-20230905131025-e968fa48a85c h1:jO41xNLddTDkrfz4w4RCMWCmX8Y+ZHz5jSbJWNLDvqU=
github.com/ubuntu/decorate v0.0.0-20230905131025-e968fa48a85c/go.mod h1:edGgz97NOqS2oqzbKrZqO9YU9neosRrkEZbVJVQynAA=
github.com/ubuntu/gowsl v0.0.0-20230710120903-fcfd527a92e4 h1:fci3jnfZQxfb92PRQwJHXR7Mxj5OiIWXVxkkpiXrkQI=
github.com/ubuntu/gowsl v0.0.0-20230710120903-fcfd527a92e4/go.mod h1:PBcZk1oAKQn1fwC9d9G2Vu25Ypxab9+UZMaPiPNjDy8=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
55 changes: 48 additions & 7 deletions end-to-end/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ const (
// overrideSafety is an env variable that, if set, allows the tests to perform potentially destructive actions.
overrideSafety = "UP4W_TEST_OVERRIDE_DESTRUCTIVE_CHECKS"

// prebuiltPath is an env variable that, if set, uses a build at a certain path instead of building the project anew.
// The structure is expected to be:
// └──${prebuiltPath}
// ├───wsl-pro-service
// │ └──wsl-pro-service_*.deb
// └───windows-agent
// └──UbuntuProForWindows_*.msixbundle
//
prebuiltPath = "UP4W_TEST_BUILD_PATH"

// referenceDistro is the WSL distro that will be used to generate the test image.
referenceDistro = "Ubuntu"

Expand All @@ -60,15 +70,15 @@ func TestMain(m *testing.M) {
log.Fatalf("Setup: %v\n", err)
}

wslProServiceDebPath, err := buildProject(ctx)
f := buildProject
if buildPath := os.Getenv(prebuiltPath); buildPath != "" {
f = usePrebuiltProject
}

wslProServiceDebPath, err := f(ctx)
if err != nil {
log.Fatalf("Setup: %v\n", err)
}
defer func() {
if err := os.RemoveAll(wslProServiceDebPath); err != nil {
log.Printf("could not remove debian artifacts at %q: %v", wslProServiceDebPath, err)
}
}()

if err := assertAppxInstalled(ctx, "CanonicalGroupLimited.UbuntuProForWindows"); err != nil {
log.Fatalf("Setup: %v\n", err)
Expand All @@ -86,6 +96,37 @@ func TestMain(m *testing.M) {
if err := cleanupRegistry(); err != nil {
log.Printf("Cleanup: registry: %v\n", err)
}

cmd := powershellf(ctx, "Get-AppxPackage -Name CanonicalGroupLimited.UbuntuProForWindows | Remove-AppxPackage")
if out, err := cmd.CombinedOutput(); err != nil {
log.Printf("Cleanup: could not remove Appx: %v: %s", err, out)
}
}

func usePrebuiltProject(ctx context.Context) (debPath string, err error) {
buildPath := os.Getenv(prebuiltPath)

// Remove Appx before installing
cmd := powershellf(ctx, "Get-AppxPackage CanonicalGroupLimited.UbuntuProForWindows | Remove-AppxPackage")
if out, err := cmd.CombinedOutput(); err != nil {
// (Probably because it was not installed)
log.Printf("Could not remove old AppxPackage: %v. %s", err, out)
}

// Install Appx anew
cmd = powershellf(ctx, "Add-AppxPackage %q", filepath.Join(buildPath, "windows-agent", "UbuntuProForWindows_*.msixbundle"))
if out, err := cmd.CombinedOutput(); err != nil {
return "", fmt.Errorf("could not install pre-built AppxPackage: %v. %s", err, out)
}

// Locate WSL-Pro-Service (it'll be installed later into the distros)
debPath = filepath.Join(buildPath, "wsl-pro-service")
_, err = locateWslProServiceDeb(ctx, debPath)
if err != nil {
return "", fmt.Errorf("could not localte pre-built WSL-Pro-Service: %v", err)
}

return debPath, err
}

func buildProject(ctx context.Context) (debPath string, err error) {
Expand Down Expand Up @@ -318,7 +359,7 @@ func generateTestImage(ctx context.Context, sourceDistro, wslProServiceDebPath s
return "", nil, err
}

out, err = d.Command(ctx, fmt.Sprintf("apt install $(wslpath -ua '%s')", debPath)).CombinedOutput()
out, err = d.Command(ctx, fmt.Sprintf("DEBIAN_FRONTEND=noninteractive apt install -y $(wslpath -ua '%s')", debPath)).CombinedOutput()
if err != nil {
defer cleanup()
return "", nil, fmt.Errorf("could not install wsl-pro-service: %v. %s", err, out)
Expand Down
Loading

0 comments on commit 315f9ed

Please sign in to comment.