Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run End-To-End tests in our CI #274

Merged
merged 25 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
452b935
Allow using pre-built artifacts
EduardGomezEscandell Sep 13, 2023
12126c4
Go mod tidy
EduardGomezEscandell Sep 15, 2023
bd42840
Improvements in local build scripts
EduardGomezEscandell Sep 15, 2023
4fc72bc
Create qa-azure workflow
EduardGomezEscandell Sep 26, 2023
a2b28e6
Good old DEBIAN_FRONTEND=noninteractive
EduardGomezEscandell Sep 22, 2023
80645cf
Move artifact build to QA-azure
EduardGomezEscandell Sep 22, 2023
5eec63b
Change wiki article on where to find artifacts
EduardGomezEscandell Sep 22, 2023
f22cd7c
Don't remove artifacts after running
EduardGomezEscandell Sep 26, 2023
3dbaebb
Kill agent after every subtest
EduardGomezEscandell Sep 26, 2023
98f8845
Log agent's log after every test
EduardGomezEscandell Sep 26, 2023
43c5bc8
Stop the agent build from breaking rsync
EduardGomezEscandell Sep 26, 2023
ccf1ee9
Add trailing endline to wapprojj
EduardGomezEscandell Sep 26, 2023
d52895c
TestOrganizationProvidedToken: Use Eventually instead of Sleep
EduardGomezEscandell Sep 26, 2023
6221264
Don't log "agent started" when it failed to start
EduardGomezEscandell Sep 27, 2023
6e72d78
Don't make assertions outside of main goroutine
EduardGomezEscandell Sep 27, 2023
9959588
Increase timeouts
EduardGomezEscandell Sep 26, 2023
352d9b4
More explanation as to why we ignore winget's output
EduardGomezEscandell Sep 28, 2023
cf0edd3
Add flags to winget to ensure it is non-interactive
EduardGomezEscandell Sep 28, 2023
c79543b
Uninstall certificate during cleanup
EduardGomezEscandell Sep 28, 2023
c5ba8fb
Clarify why we don't specify name: in artifact download
EduardGomezEscandell Sep 28, 2023
0749296
Use wildcards in Appx package upload
EduardGomezEscandell Sep 28, 2023
e644653
Improve workflow title and description
EduardGomezEscandell Sep 28, 2023
7d9608b
Clarify that startAgent may stop the tests
EduardGomezEscandell Sep 28, 2023
02beb14
Simplify ensureProjectIsBuilt
EduardGomezEscandell Sep 28, 2023
22c05a6
Increase timeout for agent startup
EduardGomezEscandell Sep 28, 2023
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
181 changes: 181 additions & 0 deletions .github/workflows/qa-azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: QA on Azure
# QA checks on Azure, allowing the use of a real WSL back-en
didrocks marked this conversation as resolved.
Show resolved Hide resolved

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
didrocks marked this conversation as resolved.
Show resolved Hide resolved

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_1.0.0.0_x64.cer
msix/UbuntuProForWindows/AppPackages/UbuntuProForWindows_*/UbuntuProForWindows_1.0.0.0_x64.msixbundle
didrocks marked this conversation as resolved.
Show resolved Hide resolved

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
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
shell: powershell
run: |
winget install GoLang.Go
Exit(0)
didrocks marked this conversation as resolved.
Show resolved Hide resolved
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ci-artifacts
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
- 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
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved

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

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:
didrocks marked this conversation as resolved.
Show resolved Hide resolved
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
didrocks marked this conversation as resolved.
Show resolved Hide resolved
```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
53 changes: 46 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,10 @@ func TestMain(m *testing.M) {
log.Fatalf("Setup: %v\n", err)
}

wslProServiceDebPath, err := buildProject(ctx)
wslProServiceDebPath, err := ensureProjectIsBuilt(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 +91,40 @@ 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 ensureProjectIsBuilt(ctx context.Context) (debPath string, err error) {
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
buildPath := os.Getenv(prebuiltPath)
if buildPath == "" {
return buildProject(ctx)
}

// 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 +357,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
Loading