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

[ASAP] CP-47431: Use un-patched Json.NET in C# SDK and package SDK in releases. Update PS SDK to use NuGet reference to XenServer.NET #5433

Merged
merged 12 commits into from
Mar 6, 2024
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
13 changes: 13 additions & 0 deletions .github/workflows/cleanup-xapi-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Cleanup XenAPI environment
description: Cleanup XenAPI environment created using the setup-xapi-environment composite action

runs:
using: "composite"
steps:
- name: Uninstall unversioned packages and remove pins
shell: bash
# This should purge them from the cache, unversioned package have
# 'master' as its version
run: |
opam list | awk -F " " '$2 == "master" { print $1 }' | xargs opam uninstall
opam pin list | cut -f1 -d "." | xargs opam unpin
211 changes: 211 additions & 0 deletions .github/workflows/generate-and-build-sdks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
name: Generate and Build SDKs

on:
workflow_call:
inputs:
xapi_version:
required: true
type: string

jobs:
generate-sdk-sources:
name: Generate SDK sources
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup XenAPI environment
uses: ./.github/workflows/setup-xapi-environment
with:
xapi_version: ${{ inputs.xapi_version }}

- name: Generate SDKs
shell: bash
run: opam exec -- make sdk

- name: Store C# SDK source
uses: actions/upload-artifact@v3
with:
name: SDK_Source_CSharp
path: _build/install/default/xapi/sdk/csharp/*

- name: Store PowerShell SDK source
uses: actions/upload-artifact@v3
with:
name: SDK_Source_PowerShell
path: _build/install/default/xapi/sdk/powershell/*

- name: Cleanup XenAPI environment
uses: ./.github/workflows/cleanup-xapi-environment

build-csharp-sdk:
name: Build C# SDK
runs-on: windows-2022
needs: generate-sdk-sources
steps:
- name: Strip 'v' prefix from xapi version
shell: pwsh
run: echo "XAPI_VERSION_NUMBER=$("${{ inputs.xapi_version }}".TrimStart('v'))" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Retrieve C# SDK source
uses: actions/download-artifact@v3
with:
name: SDK_Source_CSharp
path: source/

- name: Build C# SDK
shell: pwsh
run: |
dotnet build source/src `
--disable-build-servers `
--configuration Release `
-p:Version=${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned `
--verbosity=normal

- name: Store C# SDK
uses: actions/upload-artifact@v3
with:
name: SDK_Binaries_CSharp
path: source/src/bin/Release/XenServer.NET.${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned.nupkg

build-powershell-5x-sdk:
name: Build PowerShell 5.x SDK (.NET Framework 4.5)
needs: build-csharp-sdk
# PowerShell SDK for PowerShell 5.x needs to run on windows-2019 because
# windows-2022 doesn't contain .NET Framework 4.x dev tools
runs-on: windows-2019
steps:
- name: Strip 'v' prefix from xapi version
shell: pwsh
run: echo "XAPI_VERSION_NUMBER=$("${{ inputs.xapi_version }}".TrimStart('v'))" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Retrieve PowerShell SDK source
uses: actions/download-artifact@v3
with:
name: SDK_Source_PowerShell
path: source/

- name: Retrieve C# SDK binaries
uses: actions/download-artifact@v3
with:
name: SDK_Binaries_CSharp
path: csharp/

# Following needed for restoring packages
# when calling dotnet add package
- name: Set up dotnet CLI (.NET 6.0 and 8.0)
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6
8

- name: Setup project and dotnet CLI
shell: pwsh
run: |
dotnet nuget add source --name local ${{ github.workspace }}\csharp
dotnet add source/src package XenServer.NET --version ${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned

- name: Build PowerShell SDK (.NET Framework 4.5)
shell: pwsh
run: |
dotnet build source/src/XenServerPowerShell.csproj `
--disable-build-servers `
--configuration Release `
-p:Version=${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned `
-p:TargetFramework=net45 `
--verbosity=normal`

- name: Update SDK and PS versions in "XenServerPSModule.psd1"
shell: pwsh
run: |
(Get-Content "source\XenServerPSModule.psd1") -replace "@SDK_VERSION@","${{ env.XAPI_VERSION_NUMBER }}" | Set-Content -Path "source\XenServerPSModule.psd1"
(Get-Content "source\XenServerPSModule.psd1") -replace "@PS_VERSION@","5.0" | Set-Content -Path "source\XenServerPSModule.psd1"

- name: Move binaries to destination folder
shell: pwsh
run: |
New-Item -Path "." -Name "output" -ItemType "directory"
Copy-Item -Verbose "source\README_51.md" -Destination "output" -Force
Copy-Item -Verbose "source\LICENSE" -Destination "output" -Force
Copy-Item -Path "source\src\bin\Release\net45\*" -Include "*.dll" "output\"
Get-ChildItem -Path "source" |`
Where-Object { $_.Extension -eq ".ps1" -or $_.Extension -eq ".ps1xml" -or $_.Extension -eq ".psd1" -or $_.Extension -eq ".txt" } |`
ForEach-Object -Process { Copy-Item -Verbose $_.FullName -Destination "output" }

- name: Store PowerShell SDK (.NET Framework 4.5)
uses: actions/upload-artifact@v3
with:
name: SDK_Binaries_XenServerPowerShell_NET45
path: output/**/*

build-powershell-7x-sdk:
name: Build PowerShell 7.x SDK
strategy:
fail-fast: false
matrix:
dotnet: ["6", "8"]
needs: build-csharp-sdk
runs-on: windows-2022

steps:
- name: Strip 'v' prefix from xapi version
shell: pwsh
run: echo "XAPI_VERSION_NUMBER=$("${{ inputs.xapi_version }}".TrimStart('v'))" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Retrieve PowerShell SDK source
uses: actions/download-artifact@v3
with:
name: SDK_Source_PowerShell
path: source/

- name: Retrieve C# SDK binaries
uses: actions/download-artifact@v3
with:
name: SDK_Binaries_CSharp
path: csharp/

- name: Set up dotnet CLI (.NET ${{ matrix.dotnet }})
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}

- name: Setup project and NuGet source
shell: pwsh
run: |
dotnet nuget add source --name local ${{ github.workspace }}\csharp
dotnet add source/src package XenServer.NET --version ${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned

- name: Build PowerShell SDK (.NET ${{ matrix.dotnet }})
shell: pwsh
run: |
dotnet build source/src/XenServerPowerShell.csproj `
--disable-build-servers `
--configuration Release `
-p:Version=${{ env.XAPI_VERSION_NUMBER }}-prerelease-unsigned `
-p:TargetFramework=net${{ matrix.dotnet }}.0 `
--verbosity=normal`

- name: Update SDK and PS versions in "XenServerPSModule.psd1"
shell: pwsh
run: |
(Get-Content "source\XenServerPSModule.psd1") -replace "@SDK_VERSION@","${{ env.XAPI_VERSION_NUMBER }}" | Set-Content -Path "source\XenServerPSModule.psd1"
(Get-Content "source\XenServerPSModule.psd1") -replace "@PS_VERSION@","7.0" | Set-Content -Path "source\XenServerPSModule.psd1"

- name: Move binaries to destination folder
shell: pwsh
run: |
New-Item -Path "." -Name "output" -ItemType "directory"
Copy-Item -Verbose "source\README.md" -Destination "output" -Force
Copy-Item -Verbose "source\LICENSE" -Destination "output" -Force
Copy-Item -Path "source\src\bin\Release\net${{ matrix.dotnet }}.0\*" -Include "*.dll" "output\"
Get-ChildItem -Path "source" |`
Where-Object { $_.Extension -eq ".ps1" -or $_.Extension -eq ".ps1xml" -or $_.Extension -eq ".psd1" -or $_.Extension -eq ".txt" } |`
ForEach-Object -Process { Copy-Item -Verbose $_.FullName -Destination "output" }

- name: Store PowerShell SDK (.NET ${{ matrix.dotnet }})
uses: actions/upload-artifact@v3
with:
name: SDK_Binaries_XenServerPowerShell_NET${{ matrix.dotnet }}
path: output/**/*
88 changes: 26 additions & 62 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ on:
pull_request:
schedule:
# run daily, this refreshes the cache
- cron: '13 2 * * *'
- cron: "13 2 * * *"

concurrency: # On new push, cancel old workflows from the same PR, branch or tag:
concurrency: # On new push, cancel old workflows from the same PR, branch or tag:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

Expand All @@ -18,21 +18,21 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['2.7', '3.11']
python-version: ["2.7", "3.11"]
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # To check which files changed: origin/master..HEAD
fetch-depth: 0 # To check which files changed: origin/master..HEAD
- uses: LizardByte/setup-python-action@master
with:
python-version: ${{matrix.python-version}}

- uses: actions/cache@v3
name: Setup cache for running pre-commit fast
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}

- run: echo "::add-matcher::.github/workflows/python-warning-matcher.json"
name: "Setup GitHub for reporting Python warnings as annotations in pull request code review"
Expand Down Expand Up @@ -103,55 +103,24 @@ jobs:
# Fails for user workflows without permissions(fork-based pull requests):
continue-on-error: true
with:
message-path: .git/pytype-summary.md # Add the content of it as comment
message-path: .git/pytype-summary.md # Add the content of it as comment

ocaml-test:
name: Ocaml tests
ocaml-tests:
name: Run OCaml tests
runs-on: ubuntu-20.04
env:
# Ensure you also update test-sdk-builds
# when changing this value, to keep builds
# consistent
XAPI_VERSION: "v0.0.0"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Free space
run: sudo rm -rf /usr/local/lib/android

- name: Pull configuration from xs-opam
run: |
curl --fail --silent https://raw.githubusercontent.com/xapi-project/xs-opam/master/tools/xs-opam-ci.env | cut -f2 -d " " > .env

- name: Load environment file
id: dotenv
uses: falti/[email protected]

- name: Update Ubuntu repositories
run: sudo apt-get update

- name: Use disk with more space for TMPDIR and XDG_CACHE_HOME
run: |
df -h || true
export TMPDIR="/mnt/build/tmp"
export XDG_CACHE_HOME="/mnt/build/cache"
sudo mkdir -p "${TMPDIR}" "${XDG_CACHE_HOME}"
sudo chown "$(id -u):$(id -g)" "${TMPDIR}" "${XDG_CACHE_HOME}"
echo "TMPDIR=${TMPDIR}" >>"$GITHUB_ENV"
echo "XDG_CACHE_HOME=${XDG_CACHE_HOME}" >>"$GITHUB_ENV"

- name: Use ocaml
uses: ocaml/setup-ocaml@v2
- name: Setup XenAPI environment
uses: ./.github/workflows/setup-xapi-environment
with:
ocaml-compiler: ${{ steps.dotenv.outputs.ocaml_version_full }}
opam-repositories: |
xs-opam: ${{ steps.dotenv.outputs.repository }}
dune-cache: true

- name: Install dependencies
run: opam install . --deps-only --with-test -v

- name: Configure
run: opam exec -- ./configure --xapi_version="$XAPI_VERSION"
xapi_version: ${{ env.XAPI_VERSION }}

- name: Build
run: opam exec -- make
Expand All @@ -166,30 +135,16 @@ jobs:
run: opam exec -- make stresstest
if: ${{ github.event_name == 'schedule' }}

- name: Build SDK
run: |
mkdir -p /opt/xensource/sm
wget -O /opt/xensource/sm/XE_SR_ERRORCODES.xml https://raw.githubusercontent.com/xapi-project/sm/master/drivers/XE_SR_ERRORCODES.xml
opam exec -- make sdk

- name: Make install smoketest
run: |
opam exec -- make install DESTDIR=$(mktemp -d)
opam exec -- make install DESTDIR=$(mktemp -d) BUILD_PY2=NO

- name: Sanity test SDK
run: |
opam exec -- make sdksanity

- name: Check disk space
run: df -h || true

- name: Uninstall unversioned packages and remove pins
# This should purge them from the cache, unversioned package have
# 'master' as its version
run: |
opam list | awk -F " " '$2 == "master" { print $1 }' | xargs opam uninstall
opam pin list | cut -f1 -d "." | xargs opam unpin
- name: Cleanup XenAPI environment
uses: ./.github/workflows/cleanup-xapi-environment

deprecation-test:
name: Deprecation tests
Expand All @@ -211,3 +166,12 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error

test-sdk-builds:
name: Test SDK builds
uses: ./.github/workflows/generate-and-build-sdks.yml
with:
# Ensure you also update ocaml-tests
# when changing this value, to keep builds
# consistent
xapi_version: "v0.0.0"
Loading
Loading