ci(gh-actions): Migrate actions to desktop engineering's #145
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |