diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6c9e253e..a331fde6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,15 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - target-framework: [net6.0] grpc-web: [false, true] - include: - - os: windows-latest - target-framework: net462 - grpc-web: false - - os: windows-latest - target-framework: net462 - grpc-web: true runs-on: ${{ matrix.os }} env: MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }} @@ -50,13 +42,10 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build - run: dotnet build ${{ matrix.grpc-web && '-p:DefineConstants=USE_GRPC_WEB' || '' }} + run: make GRPC_WEB=${{ matrix.grpc-web }} build - - name: Unit Test - run: dotnet test --logger "console;verbosity=detailed" -f ${{ matrix.target-framework }} tests/Unit/Momento.Sdk.Tests - - - name: Integration Test - run: dotnet test --logger "console;verbosity=detailed" -f ${{ matrix.target-framework }} tests/Integration/Momento.Sdk.Tests + - name: Test + run: make test build_examples: runs-on: ubuntu-latest diff --git a/.github/workflows/on-push-to-main-branch.yaml b/.github/workflows/on-push-to-main-branch.yaml index cd17e8ee..5f912c6d 100644 --- a/.github/workflows/on-push-to-main-branch.yaml +++ b/.github/workflows/on-push-to-main-branch.yaml @@ -9,15 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - target-framework: [net6.0] grpc-web: [false, true] - include: - - os: windows-latest - target-framework: net462 - grpc-web: false - - os: windows-latest - target-framework: net462 - grpc-web: true runs-on: ${{ matrix.os }} env: MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }} @@ -37,13 +29,10 @@ jobs: dotnet-version: "6.0.x" - name: Build - run: dotnet build ${{ matrix.grpc-web && '-p:DefineConstants=USE_GRPC_WEB' || '' }} + run: make GRPC_WEB=${{ matrix.grpc-web }} build - - name: Unit Test - run: dotnet test -f ${{ matrix.target-framework }} tests/Unit/Momento.Sdk.Tests - - - name: Integration Test - run: dotnet test -f ${{ matrix.target-framework }} tests/Integration/Momento.Sdk.Tests + - name: Test + run: make test generate_readme: runs-on: ubuntu-latest diff --git a/.github/workflows/on-push-to-release-branch.yaml b/.github/workflows/on-push-to-release-branch.yaml index 8288cd3e..48aa9790 100644 --- a/.github/workflows/on-push-to-release-branch.yaml +++ b/.github/workflows/on-push-to-release-branch.yaml @@ -45,7 +45,7 @@ jobs: dotnet-version: "6.0.x" - name: Build - run: dotnet build + run: make build - name: Pack and Publish run: | @@ -57,7 +57,7 @@ jobs: dotnet pack -c Release -p:Version=${VERSION} dotnet nuget push ./bin/Release/Momento.Sdk.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key=${{secrets.NUGET_API_KEY}} popd - + - name: Build for Unity run: | set -x diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 70db0f27..37041266 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,16 +1,23 @@ # Running tests -Unless you are testing older .NET runtimes on Windows, you should run the tests against the newer runtimes as follows: - - https://dotnet.microsoft.com/en-us/download/dotnet/6.0 +## Recommended + +The Makefile target `test` runs against .NET 6.0 and has additional OS-conditional logic to run .NET Framework tests on Windows. Use this target by default. + +## Specifics + +You can explicitly run the tests against the newer runtimes as follows: + +- https://dotnet.microsoft.com/en-us/download/dotnet/6.0 ``` -MOMENTO_API_KEY=$your_momento_token make test-net6 +MOMENTO_API_KEY=$your_momento_token make test-dotnet6 ``` To test against older .NET runtimes run: ``` -MOMENTO_API_KEY=$your_momento_token make test-net-framework +MOMENTO_API_KEY=$your_momento_token make test-dotnet-framework ``` To run specific tests: diff --git a/Makefile b/Makefile index 827d0e62..762e1cf5 100644 --- a/Makefile +++ b/Makefile @@ -1,61 +1,88 @@ -.PHONY: all +.PHONY: all build build-dotnet6 build-dotnet-framework clean clean-build precommit restore test test-dotnet6 test-dotnet-framework run-examples help + +# Determine the operating system +OS := $(shell uname) + +# Set the default .NET version to .NET 6.0 +DOTNET_VERSION := net6.0 +TEST_LOGGER_OPTIONS := --logger "console;verbosity=detailed" + +# Windows-specific settings +# This tests if "NT" is in the OS string, which would indicate Windows. +ifneq (,$(findstring NT,$(OS))) + BUILD_TARGETS := build-dotnet6 build-dotnet-framework + TEST_TARGETS := test-dotnet6 test-dotnet-framework +else + BUILD_TARGETS := build-dotnet6 + TEST_TARGETS := test-dotnet6 +endif + +# Enable gRPC-Web if requested +GRPC_WEB_FLAG := +ifeq ($(GRPC_WEB), true) + GRPC_WEB_FLAG := -p:DefineConstants=USE_GRPC_WEB +endif + ## Generate sync unit tests, format, lint, and test all: precommit -.PHONY: build -## Build project -build: - @dotnet build +## Build the project (conditioned by OS) +build: ${BUILD_TARGETS} + + +## Build the project for .NET 6.0 +build-dotnet6: + @echo "Building the project for .NET 6.0..." + @dotnet build -f ${DOTNET_VERSION} ${GRPC_WEB_FLAG} + +## Build the project on .NET Framework +build-dotnet-framework: + @echo "Building the project for .NET Framework 4.62..." + @dotnet build -f net462 ${GRPC_WEB_FLAG} -.PHONY: clean ## Remove build files clean: + @echo "Cleaning build artifacts..." @dotnet clean -.PHONY: clean-build ## Build project -clean-build: clean restore build +clean-build: clean restore ${BUILD_TARGETS} -.PHONY: precommit ## Run clean-build and test as a step before committing. precommit: clean-build test -.PHONY: restore ## Sync dependencies restore: + @echo "Restoring dependencies..." @dotnet restore -.PHONY: test -## Run unit and integration tests -test: - @dotnet test +## Run unit and integration tests (conditioned by OS) +test: ${TEST_TARGETS} -.PHONY: test-net6 ## Run unit and integration tests on the .NET 6.0 runtime -test-net6: - @dotnet test -f net6.0 +test-dotnet6: + @echo "Running tests on .NET 6.0..." + @dotnet test ${TEST_LOGGER_OPTIONS} -f ${DOTNET_VERSION} -.PHONY: test-net-framework -## Run unit and integration tests on the .NET Framework runtime -test-net-framework: - @dotnet test -f net462 +## Run unit and integration tests on the .NET Framework runtime (Windows only) +test-dotnet-framework: + @echo "Running tests on .NET Framework 4.62 (Windows only)..." + @dotnet test ${TEST_LOGGER_OPTIONS} -f net462 -.PHONY: run-examples ## Run example applications and snippets run-examples: @dotnet run --project examples/MomentoApplication @dotnet run --project examples/DocExampleApis # See for explanation. -.PHONY: help help: @echo "$$(tput bold)Available rules:$$(tput sgr0)";echo;sed -ne"/^## /{h;s/.*//;:d" -e"H;n;s/^## //;td" -e"s/:.*//;G;s/\\n## /---/;s/\\n/ /g;p;}" ${MAKEFILE_LIST}|LC_ALL='C' sort -f|awk -F --- -v n=$$(tput cols) -v i=19 -v a="$$(tput setaf 6)" -v z="$$(tput sgr0)" '{printf"%s%*s%s ",a,-i,$$1,z;m=split($$2,w," ");l=n-i;for(j=1;j<=m;j++){l-=length(w[j])+1;if(l<= 0){l=n-i-length(w[j])-1;printf"\n%*s ",-i," ";}printf"%s ",w[j];}printf"\n";}'|more $(shell test $(shell uname) == Darwin && echo '-Xr')