|
| 1 | +# This workflow will build and test a .NET 6 web API. |
| 2 | +# The tests will be a subset of tests which run quickly while still getting good code coverage. |
| 3 | +name: Shared | Tests | Common Test Workflow |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + #ie Staging, Release |
| 8 | + BUILD_TARGET: |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + #optional test filter (ie. filter on smoke test trait) |
| 12 | + TEST_FILTER: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + #'--filter SmokeTest="true"' |
| 16 | + |
| 17 | +env: |
| 18 | + # set this to the path to your solution file, defaults to the repository root (this is the folder in the git repo) |
| 19 | + SOLUTION_DIRECTORY: './' |
| 20 | + # set this to the path to your web app project, defaults to the repository root (this is the folder in the git repo) |
| 21 | + PROJECT_DIRECTORY: './api/CESMII.ProfileDesigner.Api' |
| 22 | + # Solution file to use |
| 23 | + SOLUTION_FILE: 'CESMII.ProfileDesigner.sln' |
| 24 | + # Project file to use |
| 25 | + PROJECT_NAME: 'CESMII.ProfileDesigner.Api' |
| 26 | + # set this to the .NET core version to use |
| 27 | + NETCORE_VERSION: "6.0.x" |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + name: Build and Test .NET6 Web API |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + #dynamically set up env variables based on inputs |
| 35 | + - name: Dynamically set test filter based on input filter |
| 36 | + run: | |
| 37 | + if [ ${{inputs.TEST_FILTER}} != "" ]; then |
| 38 | + echo "Test uses filter..." |
| 39 | + echo "TEST_LABEL=Filter=${{inputs.TEST_FILTER}}" >> $GITHUB_ENV |
| 40 | + echo "TEST_FILTER=--filter ${{inputs.TEST_FILTER}}" >> $GITHUB_ENV |
| 41 | + else |
| 42 | + echo "Test does not use filter..." |
| 43 | + echo "TEST_LABEL=" >> $GITHUB_ENV |
| 44 | + echo "TEST_FILTER=" >> $GITHUB_ENV |
| 45 | + fi |
| 46 | + |
| 47 | + - uses: actions/checkout@v2 |
| 48 | + with: |
| 49 | + submodules: true |
| 50 | + - name: Set up dotnet Core ${{ env.NETCORE_VERSION }} |
| 51 | + uses: actions/setup-dotnet@v1 |
| 52 | + with: |
| 53 | + dotnet-version: ${{ env.NETCORE_VERSION }} |
| 54 | + |
| 55 | + - name: Start PostgreSQL on Ubuntu for use by integration tests |
| 56 | + run: | |
| 57 | + sudo systemctl start postgresql.service |
| 58 | + pg_isready |
| 59 | + - name: Create additional user |
| 60 | + run: | |
| 61 | + sudo -u postgres psql --command="CREATE USER profiledesigner SUPERUSER PASSWORD 'cesmii'" --command="\du" |
| 62 | + - name: List existing databases |
| 63 | + run: | |
| 64 | + sudo -u postgres psql -l |
| 65 | + - name: Create database |
| 66 | + run: | |
| 67 | + sudo -u postgres psql --command="CREATE DATABASE profile_designer_local_test WITH OWNER = profiledesigner TABLESPACE = pg_default CONNECTION LIMIT = -1;" |
| 68 | + - name: Create schema |
| 69 | + run: | |
| 70 | + ls -l ./sql |
| 71 | + head -5 ./sql/CESMII.ProfileDesigner.DB.sql |
| 72 | + sudo -u postgres psql -d profile_designer_local_test < ./sql/CESMII.ProfileDesigner.DB.sql |
| 73 | + #sudo -u postgres psql -d profile_designer_local_test --file ./sql/CESMII.ProfileDesigner.DB.sql |
| 74 | + - name: List existing databases |
| 75 | + run: | |
| 76 | + sudo -u postgres psql -l |
| 77 | +
|
| 78 | + - name: Restore dependencies (${{env.SOLUTION_FILE}}) |
| 79 | + run: dotnet restore ${{env.SOLUTION_FILE}} |
| 80 | + working-directory: ${{env.SOLUTION_DIRECTORY}} |
| 81 | + - name: Build (${{env.SOLUTION_FILE}}) |
| 82 | + run: dotnet build ${{env.SOLUTION_FILE}} --configuration ${{inputs.BUILD_TARGET}} --no-restore |
| 83 | + working-directory: ${{env.SOLUTION_DIRECTORY}} |
| 84 | + |
| 85 | + - name: Test (${{env.SOLUTION_FILE}}) ${{env.TEST_LABEL}} |
| 86 | + run: dotnet test ${{env.SOLUTION_FILE}} ${{env.TEST_FILTER}} --configuration ${{ inputs.BUILD_TARGET }} --no-build --verbosity normal -l:"console;verbosity=normal" |
| 87 | + working-directory: ${{env.SOLUTION_DIRECTORY}} |
0 commit comments