diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d7e9b65 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: Glossary CI workflow + +on: + push: + branches: + - master + - develop + - 'hotfix/**' + - 'release/**' + - 'feature/**' + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + +jobs: + ci_remote: + uses: nciocpl/nci.ocpl.api.shared/.github/workflows/common-api-ci.yml@ticket/52-shared-wf + with: + api-project: src/NCI.OCPL.Api.Glossary/NCI.OCPL.Api.Glossary.csproj + artifact-name: glossary diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml deleted file mode 100644 index 819be52..0000000 --- a/.github/workflows/workflow.yml +++ /dev/null @@ -1,183 +0,0 @@ -name: Main workflow -on: - ## This tries to avoid unessesary pushes to forked repo - ## development branches. No sense in a dev building every - ## time they push for a PR and no one should be working on - ## common branches in their fork. - push: - branches: - - master - - develop - - 'hotfix/**' - - 'release/**' - - 'feature/**' - ## Any pull request. Yes the syntax looks weird - pull_request: -env: - DOTNET_NOLOGO: true - NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} - -jobs: - - test_build_release: - name: Test, Build, Publish on OS ${{ matrix.operating-system }} - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - operating-system: [ubuntu-latest, windows-latest, macOS-latest] - - steps: - - name: Check out code - uses: actions/checkout@v3 - - ## using latest LTS releases - also it MUST be the SDK version. - - name: Setup dotnet - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '6.0.*' - source-url: "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" - - - name: Build with dotnet - run: dotnet build --configuration Release /WarnAsError - - - name: Unit Tests (with Coverage) - run: | - if [ "$RUNNER_OS" == "Windows" ]; then - dotnet test - else - dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=../../lcov test/** - fi - shell: bash - - - name: Save Code Coverage Output - uses: actions/upload-artifact@v3 - with: - name: coverage-${{ matrix.operating-system }} - path: lcov.info - if: matrix.operating-system != 'windows-latest' - - - name: Publish - run: | - dotnet publish -c Release -o $GITHUB_WORKSPACE/out src/NCI.OCPL.Api.Glossary/ - - ## directory for build-info.json - mkdir -p $GITHUB_WORKSPACE/out/wwwroot/ - shell: bash - - - name: Record metadata - uses: nciocpl/build-info-action@v1.0.0 - with: - output-name: "${{ github.workspace }}/out/wwwroot/build-info.json" - - - name: Upload Published Artifact - uses: actions/upload-artifact@v3 - with: - name: glossary-api-${{ matrix.operating-system }} - path: out - - - integration_tests: - name: Run Integration Tests (on Linux) - runs-on: ubuntu-latest - needs: test_build_release - services: - elasticsearch: - env: - discovery.type: single-node - ES_JAVA_OPTS: -Xms750m -Xmx750m - image: elasticsearch:7.17.5 - ports: - ## NOTE: This will be exposed as a random port referenced below by job.services.elasticsearch.ports[9200] - - 9200/tcp - options: --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10 - - steps: - - name: Check out code - uses: actions/checkout@v3 - - - name: Download Published Artifact - uses: actions/download-artifact@v3 - with: - name: glossary-api-ubuntu-latest - path: built-api - - ## using latest LTS releases - also it MUST be the SDK version. - - name: Setup dotnet - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '6.0.*' - source-url: "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" - - - name: Load Data into elasticsearch & prepare for tests - env: - ELASTIC_SEARCH_HOST: http://localhost:${{ job.services.elasticsearch.ports[9200] }} - run: | - ## Create test output and API logging location - mkdir -p integration-tests/target - - ## Load the elasticsearch data - ./integration-tests/bin/load-integration-data.sh - - - name: Start API - env: - Elasticsearch__Servers: http://localhost:${{ job.services.elasticsearch.ports[9200] }} - ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true - API_URL: http://localhost:5000 - SLEEP_TIMEOUT: 5 - WAIT_DURATION: 120 - APP_PATH: ./built-api - APP_ASSEMBLY: NCI.OCPL.Api.Glossary.dll - run: | - ## TODO: This should become a GitHub Action. - - ## Start the app and log output - ## NOTE: We must change directory because while you can call `dotnet "${APP_PATH}/${APP_ASSEMBLY}"` - ## it will not find the appsettings.json, so we must cd into the APP_PATH first - cd $APP_PATH && dotnet $APP_ASSEMBLY > ../integration-tests/target/api_log.txt 2>&1 & - - time_waited=1 - echo "Checking status of ${API_URL}." - until $(curl --output /dev/null --silent --fail ${API_URL}); do - echo $? - - if [ $time_waited -ge $WAIT_DURATION ]; then - echo "Waited past duration. Exiting" - cat integration-tests/target/api_log.txt - exit 1 - fi - - sleep $SLEEP_TIMEOUT - time_waited=$((time_waited + SLEEP_TIMEOUT)) - done - - echo "API is up" - - - name: Run Integration Test - ## Normally bash runs with -e which exits the shell upon hitting - ## an error which breaks our capturing of those errors. - shell: bash --noprofile --norc -o pipefail {0} - run: | - ## Run Karate - cd integration-tests && ./bin/karate ./features - - ## Store the exit code off so we can pass this step and - ## capture the test output in the next step, but still - ## fail the entire job - echo "TEST_EXIT_CODE=$?" >> $GITHUB_ENV - exit 0 - - - name: Upload Integration test results - uses: actions/upload-artifact@v3 - with: - name: integration-test-results - path: integration-tests/target - - - name: Fail build on bad tests - run: | - ## Check if we had errors on the test step, and if so, fail the job - if [ $TEST_EXIT_CODE -ne 0 ]; then - echo "Tests Failed -- See Run Integration Test step or integration-test-results artifact for more information" - exit $TEST_EXIT_CODE - else - echo "Tests passed" - fi diff --git a/global.json b/global.json new file mode 100644 index 0000000..b24d44b --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "rollForward": "latestFeature", + "version": "6.0.0" + } +} \ No newline at end of file diff --git a/integration-tests/bin/karate.jar b/integration-tests/bin/karate.jar index 1e6732e..6bb7d9e 100644 Binary files a/integration-tests/bin/karate.jar and b/integration-tests/bin/karate.jar differ diff --git a/integration-tests/bin/start-api.sh b/integration-tests/bin/start-api.sh new file mode 100755 index 0000000..69b56ac --- /dev/null +++ b/integration-tests/bin/start-api.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Used in CI builds to abstract any API-specific start up steps. +dotnet NCI.OCPL.Api.Glossary.dll