diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..e4077af2 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,15 @@ +############################################################################### +# GitHub Code-owner Configuration for Navigator Backend +# +# Each line is a file pattern followed by one or more owners. See this link: +# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#example-of-a-codeowners-file +# for more information on configuring GitHub code owners, including examples. +############################################################################### + +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, members +# of @climatepolicyradar/tech-devs will be requested for +# review when someone opens a pull request. Teams should +# be identified in the format @org/team-name. Teams must have +# explicit write access to the repository. +* @climatepolicyradar/tech-devs diff --git a/.github/funcs.sh b/.github/funcs.sh deleted file mode 100644 index 0c3a332e..00000000 --- a/.github/funcs.sh +++ /dev/null @@ -1,70 +0,0 @@ -# -# This is the core functionality taken out so it can be tested -# - -clean_string() { - echo "$1" | tr -d '\n' | tr -d ' ' -} - -is_tagged_version() { - if [[ "$1" =~ refs/tags/v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) ]] - then - return 0 - else - return 1 - fi -} - - -get_major() { - echo "${1}" | cut -d'.' -f1 -} - -get_minor() { - echo "${1}" | cut -d'.' -f2 -} - -get_patch() { - if [[ ${1} == *"-"* ]]; then - echo "${1}" | cut -d'.' -f3 | cut -d'-' -f1 - else - echo "${1}" | cut -d'.' -f3 - fi -} - -get_maturity() { - if [[ ${1} == *"-"* ]]; then - echo "${1}" | cut -d'.' -f3 | cut -d'-' -f2 - else - echo "" - fi -} - -get_docker_tags() { - # Arguments: - # - Name reference for the array - # - Name of the docker image - # - The semver we are using to create the tags - - local -n arr=$1 # use nameref to create values - name=$2 - semver=$3 - - major=$(get_major "${semver}") - minor=$(get_minor "${semver}") - patch=$(get_patch "${semver}") - maturity=$(get_maturity "${semver}") - - if [ -z ${maturity} ] ; then - echo "Detected Version: ${major} . ${minor} . ${patch}" - full_tag="${name}:${major}.${minor}.${patch}" - minor_tag="${name}:${major}.${minor}" - major_tag="${name}:${major}" - else - echo "Detected Version: ${major} . ${minor} . ${patch} [${maturity}]" - full_tag="${name}:${major}.${minor}.${patch}-${maturity}" - minor_tag="${name}:${major}.${minor}-${maturity}" - major_tag="${name}:${major}-${maturity}" - fi - arr=($full_tag $minor_tag $major_tag) -} diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index fa9d25ed..46ac5afb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,6 +7,28 @@ Please include: - any additional relevant motivation and context - details of any dependency updates that are required for this change +## Proposed version + +Please select the option below that is most relevant from the list below. This +will be used to generate the next tag version name during auto-tagging. + +- [ ] Skip auto-tagging +- [ ] Patch +- [ ] Minor version +- [ ] Major version + +Visit the [Semver website](https://semver.org/#summary) to understand the +difference between `MAJOR`, `MINOR`, and `PATCH` versions. + +Notes: + +- If none of these options are selected, auto-tagging will fail +- Where multiple options are selected, the most senior option ticked will be + used -- e.g. Major > Minor > Patch +- If you are selecting the version in the list above using the textbox, make + sure your selected option is marked `[x]` with no spaces in between the + brackets and the `x` + ## Type of change Please select the option(s) below that are most relevant: diff --git a/.github/retag-and-push.sh b/.github/retag-and-push.sh deleted file mode 100755 index a74b4e5a..00000000 --- a/.github/retag-and-push.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash -set -e - -script_folder=$(dirname "${BASH_SOURCE[0]}") -source $script_folder/funcs.sh - -if [ "$#" -ne 2 ]; then - echo "Pushes a container image to ECR with tags" - echo - echo "Usage: $0 project input_tag" - echo "Example: $0 container-name 6cd9d7ebad4f16ef7273a7a831d79d5d5caf4164" - echo "Relies on the following environment variables:" - echo "- GITHUB_HEAD_REF, GITHUB_REF, GITHUB_SHA (GH Action default)" - echo "- DOCKER_REGISTRY" - exit 1 -fi - -[ "${DOCKER_REGISTRY}" == "" ] && (echo "DOCKER_REGISTRY is not set" ; exit 1) - -project="$1" -image_tag="$2" - -# login -# This should now be performed as a GA -# See: https://docs.docker.com/build/ci/github-actions/#step-three-define-the-workflow-steps - -name=$(clean_string "${DOCKER_REGISTRY}/${project}") -input_image="${project}:${image_tag}" - -echo "-------------" -echo "Input : ${project}:${image_tag}" -echo "Output : ${name}" -echo "GitRef : ${GITHUB_REF}" -echo "GitHeadRef : ${GITHUB_HEAD_REF}" -echo "Branch : ${GITHUB_REF/refs\/heads\//}" -echo "Repo Tag : ${name}" -echo "-------------" - -docker_tag() { - echo "Re-tagging $1 -> $2" - docker tag $1 $2 -} - -process_tagged_version() { - local tag_array - semver=$1 - get_docker_tags tag_array ${name} ${semver} - - for tag in "${tag_array[@]}" ; do - docker_tag "${input_image}" ${tag} - docker push "${tag}" - done -} - -timestamp=$(date --utc -Iseconds | cut -c1-19 | tr -c '[0-9]T\n' '-') -short_sha=${GITHUB_SHA:0:8} - -if [[ "${GITHUB_REF}" == "refs/heads"* ]]; then - # push `branch-sha` tagged image - - # NOTE: Looks like the behaviour has changed for GITHHUB_REF - # See: https://github.com/semantic-release/env-ci/issues/157 - # ... branches will no longer be handled here but in the 'else' statement below. - - branch="${GITHUB_REF/refs\/heads\//}" - echo "Detected Branch: ${branch}" - - - # Only update latest if on main - if [[ "${branch}" = "main" ]]; then - # push `latest` tag - docker_tag "${input_image}" "${name}:latest" - docker push "${name}:latest" - # Also tag for any versioning that might get done - docker_tag "${input_image}" "${name}:${branch}-${timestamp}-${short_sha}" - docker push "${name}:${branch}-${timestamp}-${short_sha}" - # Also tag for any versioning that might get done - docker_tag "${input_image}" "${name}:${branch}-${short_sha}" - docker push "${name}:${branch}-${short_sha}" - fi -elif is_tagged_version ${GITHUB_REF} ; then - # push `semver` tagged image - semver="${GITHUB_REF/refs\/tags\/v/}" - echo "Detected Tag: ${semver}" - process_tagged_version ${semver} -else - echo "${GITHUB_REF} is neither a branch head nor valid semver tag" - echo "Assuming '${GITHUB_HEAD_REF}' is a branch" - if [[ -n "${GITHUB_HEAD_REF}" ]]; then - branch="$(echo ${GITHUB_HEAD_REF}| tr -c '[0-9,A-Z,a-z]' '-')" - docker_tag "${input_image}" "${name}:${branch}-${timestamp}-${short_sha}" - docker push "${name}:${branch}-${timestamp}-${short_sha}" - else - echo "No branch found, not a PR so not publishing." - fi -fi diff --git a/.github/tests/test_retag_and_push.bats b/.github/tests/test_retag_and_push.bats deleted file mode 100644 index efe3a30b..00000000 --- a/.github/tests/test_retag_and_push.bats +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env bats -load '/opt/bats-test-helpers/bats-support/load.bash' -load '/opt/bats-test-helpers/bats-assert/load.bash' -load '/opt/bats-test-helpers/lox-bats-mock/stub.bash' - -# ------ - -@test "clean_string removes CR" { - source /code/funcs.sh - str=$(printf " test \n ") - run clean_string $str - [ "$status" -eq 0 ] - assert_output "test" -} - -@test "clean_string removes all white spaces" { - source /code/funcs.sh - run clean_string " test " - [ "$status" -eq 0 ] - assert_output "test" -} - -# ------ - -@test "is_tagged_version succeeds for typical version" { - source /code/funcs.sh - run is_tagged_version "refs/tags/v0.1.2-alpha" - [ "$status" -eq 0 ] -} - -@test "is_tagged_version fails for missing patch " { - source /code/funcs.sh - run is_tagged_version "refs/tags/v0.1-alpha" - [ "$status" -eq 1 ] -} - -@test "is_tagged_version fails for other tags " { - source /code/funcs.sh - run is_tagged_version "refs/tags/vimto" - [ "$status" -eq 1 ] -} - -# ------ - -@test "get_major returns major version" { - source /code/funcs.sh - run get_major "8.9.7-alpha" - [ "$status" -eq 0 ] - [ "$output" == "8" ] -} - -# ------ - -@test "get_minor returns minor version" { - source /code/funcs.sh - run get_minor "8.9.7-alpha" - [ "$status" -eq 0 ] - [ "$output" == "9" ] -} - -# ------ - -@test "get_patch returns patch version" { - source /code/funcs.sh - run get_patch "8.9.7-alpha" - [ "$status" -eq 0 ] - [ "$output" == "7" ] -} - -# ------ - -@test "get_maturity returns maturity version" { - source /code/funcs.sh - run get_maturity "8.9.7-alpha" - [ "$status" -eq 0 ] - [ "$output" == "alpha" ] -} - -# ------ - -@test "get_maturity returns empty " { - source /code/funcs.sh - run get_maturity "8.9.7" - [ "$status" -eq 0 ] - [ "$output" == "" ] -} - -# ------ - -@test "regression with missing maturity" { - source /code/funcs.sh - semver="8.9.7" - - run get_major $semver - [ "$status" -eq 0 ] - [ "$output" == "8" ] - run get_minor $semver - [ "$status" -eq 0 ] - [ "$output" == "9" ] - run get_patch $semver - [ "$status" -eq 0 ] - [ "$output" == "7" ] - run get_maturity $semver - [ "$status" -eq 0 ] - [ "$output" == "" ] -} - -# ------ - -@test "get_docker_tags returns correctly with maturity " { - source /code/funcs.sh - run get_docker_tags tag_array "test" "8.9.7-alpha" - [ "$status" -eq 0 ] - - # Note the above "run" command does something unholy - so just execute without it - local tag_array - get_docker_tags tag_array "test" "8.9.7-alpha" - - # Test we have 3 tags - [ ${#tag_array[@]} -eq 3 ] - - [ "${tag_array[0]}" == "test:8.9.7-alpha" ] - [ "${tag_array[1]}" == "test:8.9-alpha" ] - [ "${tag_array[2]}" == "test:8-alpha" ] -} - -# ------ - -@test "get_docker_tags returns correctly without maturity " { - source /code/funcs.sh - run get_docker_tags tag_array "test" "8.9.7" - [ "$status" -eq 0 ] - - # Note the above "run" command does something unholy - so just execute without it - local tag_array - get_docker_tags tag_array "test" "8.9.7" - - # Test we have 3 tags - [ ${#tag_array[@]} -eq 3 ] - - [ "${tag_array[0]}" == "test:8.9.7" ] - [ "${tag_array[1]}" == "test:8.9" ] - [ "${tag_array[2]}" == "test:8" ] -} diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 00000000..3bc4f7af --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,213 @@ +name: CI/CD + +on: + push: + tags: [v*] + branches: + - main + pull_request: + # By default, a workflow only runs when a pull_request event's activity type is opened, + # synchronize, or reopened. + types: [opened, synchronize, reopened, edited] + branches: + - main + +permissions: read-all + +jobs: + check-auto-tagging-will-work: + if: | + github.event_name == 'pull_request' && + (! startsWith(github.ref, 'refs/tags') && ! startsWith(github.ref, 'refs/heads/main')) + uses: climatepolicyradar/reusable-workflows/.github/workflows/check-auto-tagging-will-work.yml@v3 + + non-search-tests: + if: | + always() && + (needs.check-auto-tagging-will-work.result == 'skipped' || needs.check-auto-tagging-will-work.result == 'success') && + ! startsWith(github.ref, 'refs/tags') + needs: + - check-auto-tagging-will-work + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Use .env.example + run: cp .env.example .env + + - name: Get python Container + run: docker pull python:3.9 + + - name: Build + run: | + docker compose build + docker images + + - name: Build docker-compose stack + run: make start_without_vespa_setup + + - name: Wait for backend to open port + run: ./scripts/wait_for_port.sh localhost 8888 60 + + - name: Run backend tests + run: make test_non_search + + - name: Docker debug + run: | + docker compose logs + docker compose ps + docker ps -a + ls -la + + - name: Log Dump + if: always() + run: docker compose logs + + search-tests: + if: | + always() && + (needs.check-auto-tagging-will-work.result == 'skipped' || needs.check-auto-tagging-will-work.result == 'success') && + ! startsWith(github.ref, 'refs/tags') + needs: + - check-auto-tagging-will-work + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Use .env.example + run: cp .env.example .env + + - name: Get python Container + run: docker pull python:3.9 + + - name: Install latest Vespa CLI + env: + VESPA_CLI_VERSION: "8.250.43" + run: | + mkdir scripts/vespa-cli + curl -fsSL https://github.com/vespa-engine/vespa/releases/download/v${VESPA_CLI_VERSION}/vespa-cli_${VESPA_CLI_VERSION}_linux_amd64.tar.gz | \ + tar -zxf - -C scripts/vespa-cli --strip-component=1 + echo "scripts/vespa-cli/bin" >> $GITHUB_PATH + + - name: Build + run: | + docker compose build + docker images + + - name: Build docker-compose stack + run: make start + + - name: Setup vespa for search + run: make vespa_setup + + - name: Run backend search tests for vespa + run: make test_search + + - name: Log Dump + if: always() + run: docker compose logs + + integration-tests: + if: | + always() && + (needs.check-auto-tagging-will-work.result == 'skipped' || needs.check-auto-tagging-will-work.result == 'success') && + ! startsWith(github.ref, 'refs/tags') + needs: + - check-auto-tagging-will-work + runs-on: ubuntu-latest + steps: + - name: Run Integration Tests + run: echo TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO + + build: + if: | + always() && + (needs.non-search-tests.result == 'success' && + needs.search-tests.result == 'success' && + needs.integration-tests.result == 'success') && + ! startsWith(github.ref, 'refs/tags') + runs-on: ubuntu-latest + needs: + - non-search-tests + - search-tests + - integration-tests + steps: + - uses: actions/checkout@v4 + + - name: Use .env.example + run: cp .env.example .env + + - name: Get python Container + run: docker pull python:3.9 + + - name: Build + run: | + docker compose build + docker images + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1.6.1 + + - name: Publish initial image based on branch to ECR + env: + DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + shell: bash + run: | + if [[ "${GITHUB_REF}" == "refs/heads"* ]]; then + branch="${GITHUB_REF/refs\/heads\//}" + if [[ "${branch}" = "main" ]]; then + docker_tag=latest + docker tag navigator-backend "$ECR_REGISTRY/navigator-backend:${docker_tag}" + docker push "$ECR_REGISTRY/navigator-backend:${docker_tag}" + fi + elif [[ "${GITHUB_REF}" != "refs/tags"* ]]; then + echo "Assuming '${GITHUB_HEAD_REF}' is a branch" + if [[ -n "${GITHUB_HEAD_REF}" ]]; then + branch="$(echo ${GITHUB_HEAD_REF}| tr -c '[0-9,A-Z,a-z]' '-')" + timestamp=$(date --utc -Iseconds | cut -c1-19 | tr -c '[0-9]T\n' '-') + short_sha=${GITHUB_SHA:0:8} + docker_tag="${branch}-${timestamp}-${short_sha}" + docker tag navigator-backend "$ECR_REGISTRY/navigator-backend:${docker_tag}" + docker push "$ECR_REGISTRY/navigator-backend:${docker_tag}" + fi + fi + + manual-semver: + if: ${{ always() && startsWith(github.ref, 'refs/tags') }} + uses: climatepolicyradar/reusable-workflows/.github/workflows/semver.yml@v3 + secrets: inherit + with: + repo-name: navigator-backend + semver-tag: main-${GITHUB_SHA::8} + + tag: + if: ${{ always() && (needs.build.result == 'success')}} + needs: build + permissions: + contents: write + uses: climatepolicyradar/reusable-workflows/.github/workflows/tag.yml@v3 + with: + repo-name: navigator-backend + semver-tag: main-${GITHUB_SHA::8} + secrets: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} + + release: + if: ${{ always() && (needs.tag.result == 'success' && needs.tag.outputs.new_tag != 'Skip')}} + needs: tag + permissions: + contents: write + uses: climatepolicyradar/reusable-workflows/.github/workflows/release.yml@v3 + with: + new_tag: ${{ needs.tag.outputs.new_tag }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 71841d17..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,137 +0,0 @@ -name: CI - -on: - push: - branches: - - main - pull_request: - branches: - - main - -# https://github.com/marketplace/actions/docker-layer-caching -jobs: - test-bash: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Run tests - run: make test_bashscripts - - non-search-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Use .env.example - run: cp .env.example .env - - - name: Get python Container - run: docker pull python:3.9 - - - name: Build - run: | - docker-compose build - docker images - - - name: Build docker-compose stack - run: make start_without_vespa_setup - - - name: Wait for backend to open port - run: ./scripts/wait_for_port.sh localhost 8888 60 - - - name: Run backend tests - run: make test_non_search - - - name: docker - run: | - docker-compose logs - docker-compose ps - docker ps -a - ls -la - - - name: Log Dump - if: always() - run: docker-compose logs - - search-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Use .env.example - run: cp .env.example .env - - - name: Get python Container - run: docker pull python:3.9 - - - name: Install latest Vespa CLI - env: - VESPA_CLI_VERSION: "8.250.43" - run: | - mkdir scripts/vespa-cli - curl -fsSL https://github.com/vespa-engine/vespa/releases/download/v${VESPA_CLI_VERSION}/vespa-cli_${VESPA_CLI_VERSION}_linux_amd64.tar.gz | \ - tar -zxf - -C scripts/vespa-cli --strip-component=1 - echo "scripts/vespa-cli/bin" >> $GITHUB_PATH - - - name: Build - run: | - docker-compose build - docker images - - - name: Build docker-compose stack - run: make start - - - name: Setup vespa for search - run: make vespa_setup - - - name: Run backend search tests for vespa - run: make test_search - - - name: Log Dump - if: always() - run: docker-compose logs - - integration-tests: - runs-on: ubuntu-latest - steps: - - name: Run Integration Tests - run: echo TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO-TODO - - build: - runs-on: ubuntu-latest - needs: - - test-bash - - non-search-tests - - search-tests - - integration-tests - steps: - - uses: actions/checkout@v4 - - - name: Use .env.example - run: cp .env.example .env - - - name: Get python Container - run: docker pull python:3.9 - - - name: Build - run: | - docker-compose build - docker images - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: eu-west-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1.6.1 - - - name: Push Images to ECR - run: | - .github/retag-and-push.sh navigator-backend latest - env: - DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} diff --git a/.github/workflows/main-push-checks.yml b/.github/workflows/main-push-checks.yml deleted file mode 100644 index 38940faa..00000000 --- a/.github/workflows/main-push-checks.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: main push checks - -on: - push: - branches: - - main - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Check code contains no FIXME's - run: | - git grep -r --no-color ${case_sensitive} --line-number -e "FIXME" :^.github - if [[ $? -eq 0 ]]; then - # if we found any FIXME entries in checked in files, fail on main - exit 1 - else - exit 0 - fi - shell: bash {0} diff --git a/.github/workflows/semver.yml b/.github/workflows/semver.yml deleted file mode 100644 index 4910aa34..00000000 --- a/.github/workflows/semver.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Semver Tagging - -on: - push: - tags: - - v* - -env: - DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - -jobs: - tag-main-with-semver: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: eu-west-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1.6.1 - - - name: Docker pull, retag and push - run: | - docker pull ${DOCKER_REGISTRY}/navigator-backend:main-${GITHUB_SHA::8} - docker tag ${DOCKER_REGISTRY}/navigator-backend:main-${GITHUB_SHA::8} navigator-backend:main-${GITHUB_SHA::8} - .github/retag-and-push.sh navigator-backend main-${GITHUB_SHA::8} diff --git a/LICENSE.md b/LICENSE.md index 109f0551..261eeb9e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,29 +1,201 @@ -BSD 3-Clause License - -Copyright (c) 2022, Climate Policy Radar CIC -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License.