Skip to content

Commit

Permalink
Add SDK generation and build workflows
Browse files Browse the repository at this point in the history
Also:
- Reformat `yml` files
- Extract XenAPI env setup into composite action
- Create composite action to generate and build SDKs
- Add build of C# SDK

Signed-off-by: Danilo Del Busso <[email protected]>
  • Loading branch information
danilo-delbusso committed Feb 6, 2024
1 parent 510997a commit 127e29e
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 59 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/generate-and-build-sdks/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Genrate and build SDKs
description: Generate and build SDKs (excl. Python). Currently only builds the C# SDK. Ensure you are running this action after setting up a XenAPI environment.

inputs:
xapi_version:
description: "XenAPI version. e.g.: v24.1.0"
required: true
runs:
using: "composite"
steps:
- name : Set env variables
shell : bash
run: echo "XAPI_VERSION=${{inputs.xapi_version}}" >> $XAPI_VERSION

- name: Set up dotnet CLI
uses: actions/setup-dotnet@v3
with:
dotnet-version: "6"

- name: Generate SDKs
shell: bash
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: Build .NET SDK
shell: bash
run: opam exec -- make build-csharp-sdk
71 changes: 16 additions & 55 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 @@ -99,55 +99,21 @@ 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:
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 @@ -162,21 +128,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: Generate and build SDKs
uses: ./.github/workflows/generate-and-build-sdks
with:
xapi_version: ${{ env.XAPI_VERSION }}

- 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

Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/setup-xapi-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Setup XenAPI environment
description: Setup a XenAPI environment for making opam calls.

inputs:
xapi_version:
description: "XenAPI version, pass to configure as --xapi_version=<value>"
required: true
runs:
using: "composite"
steps:
- name: Free space
shell: bash
run: sudo rm -rf /usr/local/lib/android

- name: Pull configuration from xs-opam
shell: bash
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
shell: bash
run: sudo apt-get update

- name: Use disk with more space for TMPDIR and XDG_CACHE_HOME
shell: bash
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
with:
ocaml-compiler: ${{ steps.dotenv.outputs.ocaml_version_full }}
opam-repositories: |
xs-opam: ${{ steps.dotenv.outputs.repository }}
dune-cache: true

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

- name: Configure
shell: bash
run: opam exec -- ./configure --xapi_version="${{ inputs.xapi_version }}"
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ sdk:
sh ocaml/sdk-gen/windows-line-endings.sh $(XAPISDK)/csharp
sh ocaml/sdk-gen/windows-line-endings.sh $(XAPISDK)/powershell

# workaround for no .resx generation, just for compilation testing
sdksanity: sdk
sed -i 's/FriendlyErrorNames.ResourceManager/null/g' ./_build/install/default/xapi/sdk/csharp/src/Failure.cs
cd _build/install/default/xapi/sdk/csharp/src && dotnet add package Newtonsoft.Json && dotnet build -f netstandard2.0
# Cannot pass version number with a "v" prefix
XAPI_VERSION_CLEAN := $(shell echo $(XAPI_VERSION) | sed 's/^v//')

build-csharp-sdk: sdk
cd _build/install/default/xapi/sdk/csharp/src && \
dotnet build \
--disable-build-servers \
--configuration Release \
-p:Version=$(XAPI_VERSION_CLEAN)-prerelease-unsigned \
--verbosity=normal

python:
$(MAKE) -C scripts/examples/python build
Expand Down

0 comments on commit 127e29e

Please sign in to comment.