Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make validator GitHub Action #191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deps_eager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
# python-version: [3.6, 3.7, 3.8]

# steps:
# - uses: actions/checkout@v1
# - uses: actions/checkout@v2

# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v1
Expand Down
40 changes: 18 additions & 22 deletions .github/workflows/deps_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v1
Expand All @@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v1
Expand All @@ -59,7 +59,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v1
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Build the Docker images
run: docker-compose build
Expand All @@ -105,30 +105,26 @@ jobs:
.github/workflows/wait_for_it.sh localhost:3213 -t 120
sleep 15

- name: Test server
run: docker exec optimade-python-tools_optimade_1 optimade_validator http://localhost:5000/optimade/v0

- name: Test server - OPTIONAL base URL; vMAJOR.MINOR
run: docker exec optimade-python-tools_optimade_1 optimade_validator http://localhost:5000/optimade/v0.10

- name: Test server - OPTIONAL base URL; vMAJOR.MINOR.PATCH
run: docker exec optimade-python-tools_optimade_1 optimade_validator http://localhost:5000/optimade/v0.10.1
- name: Test server with OPTIONAL base URLs
uses: ./
with:
port: 3213
path: /optimade
all versioned paths: yes

- name: Start Docker image - index server
run: |
docker-compose up optimade-index &
.github/workflows/wait_for_it.sh localhost:3214 -t 120
sleep 15

- name: Test index server
run: docker exec optimade-python-tools_optimade-index_1 optimade_validator http://localhost:5001/optimade/v0 --index

- name: Test index server - OPTIONAL base URL; vMAJOR.MINOR
run: docker exec optimade-python-tools_optimade-index_1 optimade_validator http://localhost:5001/optimade/v0.10 --index

- name: Test index server - OPTIONAL base URL; vMAJOR.MINOR.PATCH
run: docker exec optimade-python-tools_optimade-index_1 optimade_validator http://localhost:5001/optimade/v0.10.1 --index

- name: Test index server with OPTIONAL base URLs
uses: ./
with:
port: 3214
path: /optimade
all versioned paths: yes
index: yes

deps_static:
runs-on: ubuntu-latest
Expand All @@ -140,7 +136,7 @@ jobs:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-on-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v1
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/validator_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Test optimade_validator GitHub Action

on:
pull_request:
push:
branches:
- master

jobs:

validator_regular:
runs-on: ubuntu-latest
name: Regular server

steps:
- uses: actions/checkout@v2

- name: Set up and run regular server
run: |
docker-compose up optimade &
.github/workflows/wait_for_it.sh localhost:3213 -t 120
sleep 15

- name: Run action
uses: ./
with:
port: 3213
path: /optimade/v0

validator_index:
runs-on: ubuntu-latest
name: Index server

steps:
- uses: actions/checkout@v2

- name: Set up and run index server
run: |
docker-compose up optimade-index &
.github/workflows/wait_for_it.sh localhost:3214 -t 120
sleep 15

- name: Run action
uses: ./
with:
port: 3214
path: /optimade/v0
index: yes

all_versioned_paths:
runs-on: ubuntu-latest
name: All versioned paths for regular server

steps:
- uses: actions/checkout@v2

- name: Set up and run regular server (which includes all versioned base URLs)
run: |
docker-compose up optimade &
.github/workflows/wait_for_it.sh localhost:3213 -t 120
sleep 15

- name: Run action
uses: ./
with:
port: 3213
path: /optimade
all versioned paths: yes
86 changes: 80 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The aim of OPTiMaDe is to develop a common API, compliant with the [JSON API 1.0
This is to enable interoperability among databases that contain calculated properties of existing and hypothetical materials.

This repository contains a library of tools for implementing and consuming [OPTiMaDe](https://www.optimade.org) APIs using Python.
It also contains a server validator tool, which may be called from the shell or used as a GitHub Action.

## Status

Expand All @@ -23,11 +24,84 @@ Installation instructions, for both the index meta-database, and for the main AP

Contribution guidelines and tips can be found in [CONTRIBUTING.md](CONTRIBUTING.md).

## GitHub Action - OPTiMaDe validator

This action runs `optimade_validator` from this repository on a running server.

### Example usage

To run `optimade_validator` for an index meta-database at `http://gh_actions_host:5001/optimade/v0` do the following:
Within the same job, first, start a server, e.g., using the `docker-compose.yml` setup from this repository, and then add the step

```yml
uses: Materials-Consortia/optimade-python-tools@master
with:
port: 5001
path: /optimade/v0
index: yes
```

To run `optimade_validator` for a regular OPTiMaDe _deployed_ implementation, testing all possible versioned base URLs:

- `https://example.org:443/optimade/example/v0`
- `https://example.org:443/optimade/example/v0.10`
- `https://example.org:443/optimade/example/v0.10.1`

```yml
uses: Materials-Consortia/optimade-python-tools@master
with:
protocol: https
domain: example.org
port: 443
path: /optimade/example
all versioned paths: True
```

### Inputs

#### `protocol`

**Optional** Protocol for the OPTiMaDe URL.
**Default**: `http`

#### `domain`

**Optional** Domain for the OPTiMaDe URL (defaults to the GitHub Actions runner host).
**Default**: `gh_actions_host`

#### `port`

**Optional** Port for the OPTiMaDe URL.
**Default**: `5000`

#### `path`

**Optional** Path for the OPTiMaDe (versioned) base URL - MUST start with `/`
_Note_: If `all versioned paths` is `true`, this MUST be un-versioned, e.g., `/optimade`, otherwise it MUST be versioned, e.g., the default value.
**Default**: `/optimade/v0`

#### `all versioned paths`

**Optional** Whether to test all possible versioned base URLs:

- /vMAJOR
- /vMAJOR.MINOR
- /vMAJOR.MINOR.PATCH

If this is `'true'`, the input `'path'` MUST exempt the version part (e.g., `'/optimade'` instead of `'/optimade/v0'`).
If this is `'false'`, the input `'path'` MUST include the version part (e.g., `'/optimade/v0'` instead of `'/optimade'`).
**Default**: `false`

#### `index`

**Optional** Whether or not this is an index meta-database.
**Default**: `false`

## Links

* [OPTiMaDe Specification](https://github.com/Materials-Consortia/OPTiMaDe/blob/develop/optimade.rst), the human-readable specification that this library is based on.
* [OpenAPI](https://github.com/OAI/OpenAPI-Specification), the machine-readable format used to specify the OPTiMaDe API in [`openapi.json`](openapi.json).
* [Interactive documentation](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/Materials-Consortia/optimade-python-tools/master/openapi.json) generated from [`openapi.json`](openapi.json) (see also [interactive JSON editor](https://editor.swagger.io/?url=https://raw.githubusercontent.com/Materials-Consortia/optimade-python-tools/master/openapi.json)).
* [pydantic](https://pydantic-docs.helpmanual.io/), the library used for generating the OpenAPI schema from [Python models](optimade/models).
* [FastAPI](https://fastapi.tiangolo.com/), the framework used for generating the reference implementation from the [`openapi.json`](openapi.json) specification.
* [lark](https://github.com/lark-parser/lark), the library used to parse the filter language in OPTiMaDe queries.
- [OPTiMaDe Specification](https://github.com/Materials-Consortia/OPTiMaDe/blob/develop/optimade.rst), the human-readable specification that this library is based on.
- [OpenAPI](https://github.com/OAI/OpenAPI-Specification), the machine-readable format used to specify the OPTiMaDe API in [`openapi.json`](openapi.json).
- [Interactive documentation](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/Materials-Consortia/optimade-python-tools/master/openapi.json) generated from [`openapi.json`](openapi.json) (see also [interactive JSON editor](https://editor.swagger.io/?url=https://raw.githubusercontent.com/Materials-Consortia/optimade-python-tools/master/openapi.json)).
- [pydantic](https://pydantic-docs.helpmanual.io/), the library used for generating the OpenAPI schema from [Python models](optimade/models).
- [FastAPI](https://fastapi.tiangolo.com/), the framework used for generating the reference implementation from the [`openapi.json`](openapi.json) specification.
- [lark](https://github.com/lark-parser/lark), the library used to parse the filter language in OPTiMaDe queries.
38 changes: 38 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: OPTiMaDe validator
description: Validate your OPTiMaDe server using the optimade-python-tools validator
author: Casper Welzel Andersen, Matthew Evans
branding:
icon: server
color: green

inputs:
protocol:
description: Protocol for the OPTiMaDe URL
required: false
default: http
domain:
description: Domain for the OPTiMaDe URL (defaults to the GH Actions runner host)
required: false
default: gh_actions_host
port:
description: Port for the OPTiMaDe URL
required: false
path:
description: Path of the OPTiMaDe (versioned) base URL - MUST start with '/'
required: false
default: /optimade/v0
all versioned paths:
description: >
Whether to test all possible versioned base URLs:
/vMAJOR; /vMAJOR.MINOR; /vMAJOR.MINOR.PATCH
If this is 'true', the input 'path' MUST exempt the version part (e.g., '/optimade' instead of '/optimade/v0').
If this is 'false', the input 'path' MUST include the version part (e.g., '/optimade/v0' instead of '/optimade').
required: false
default: false
index:
description: Whether or not this is an index meta-database
required: false
default: false
runs:
using: 'docker'
image: 'optimade/validator/github_action/Dockerfile'
10 changes: 10 additions & 0 deletions optimade/validator/github_action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.7

RUN pip install -U pip setuptools wheel \
&& git clone https://github.com/Materials-Consortia/optimade-python-tools \
&& pip install -U -e ./optimade-python-tools

RUN echo $(ip route | awk '{print $3}') > /docker_host_ip

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
43 changes: 43 additions & 0 deletions optimade/validator/github_action/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

# Retrieve and add GitHub Actions host runner IP to known hosts
DOCKER_HOST_IP=$(cat /docker_host_ip)
echo $DOCKER_HOST_IP gh_actions_host >> /etc/hosts

run_validator="optimade_validator"

if [ ! -z "$INPUT_PORT" ]; then
BASE_URL="$INPUT_PROTOCOL://$INPUT_DOMAIN:$INPUT_PORT"
else
BASE_URL="$INPUT_PROTOCOL://$INPUT_DOMAIN"
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
fi
run_validator="$run_validator $BASE_URL"

index=""
case $INPUT_INDEX in
y | Y | yes | Yes | YES | true | True | TRUE | on | On | ON)
index=" --index"
;;
n | N | no | No | NO | false | False | FALSE | off | Off | OFF)
;;
*)
echo "Non-valid input for 'index': $INPUT_INDEX. Will use default (false)."
;;
esac

case $INPUT_ALL_VERSIONED_PATHS in
y | Y | yes | Yes | YES | true | True | TRUE | on | On | ON)
for version in '0' '0.10' '0.10.1'; do
sh -c "$run_validator$INPUT_PATH/v$version$index"
done
;;
n | N | no | No | NO | false | False | FALSE | off | Off | OFF)
run_validator="$run_validator$INPUT_PATH$index"
sh -c "$run_validator"
;;
*)
echo "Non-valid input for 'all versioned paths': $INPUT_ALL_VERSIONED_PATHS. Will use default (false)."
run_validator="$run_validator$INPUT_PATH$index"
sh -c "$run_validator"
;;
esac