Skip to content

Commit

Permalink
Feature/26429 Convert the timeseries python sdk to Github actions (#40)
Browse files Browse the repository at this point in the history
convert to github actions
  • Loading branch information
TorgeirWaagbo authored Nov 22, 2023
1 parent 8a21174 commit 1b6b16b
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 236 deletions.
25 changes: 18 additions & 7 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.
## Failure Information (for bugs)
A clear and concise description of what the bug is. If it is not a bug, please remove the rest of this template.

**To Reproduce**
Steps to reproduce the behavior:
**Mandatory**:
* Trace Id:

**Expected behavior**
## To Reproduce
Please provide detailed steps for reproducing the issue.

## Expected behavior
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.
## Additional context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

* Environment:
* API Version:
* Code Language:

## Failure Logs

Please include any relevant log snippets or files here.
126 changes: 126 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Deploy App

on:
push:
branches:
- develop
- main
- 'feature/**'
tags:
- v**

permissions:
id-token: write
contents: write
checks: write
issues: read
packages: read
pull-requests: write

jobs:
detectenv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Detecting environment
id: get_env
run: |
echo "Running on ${{ github.ref }}"
echo "env_isFeature=false" >> $GITHUB_OUTPUT
if [ "${{ github.ref_type }}" = "tag" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
echo "env_suffix=p" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
echo "env_suffix=p" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" = "refs/heads/develop" ]; then
echo "env_name=development" >> $GITHUB_OUTPUT
echo "env_suffix=d" >> $GITHUB_OUTPUT
else
echo "env_name=development" >> $GITHUB_OUTPUT
echo "env_suffix=d" >> $GITHUB_OUTPUT
echo "env_isFeature=true" >> $GITHUB_OUTPUT
fi
outputs:
env_name: ${{ steps.get_env.outputs.env_name }}
env_suffix: ${{ steps.get_env.outputs.env_suffix }}
env_isFeature: ${{ steps.get_env.outputs.env_isFeature }}

snyk:
needs: [detectenv]
runs-on: ubuntu-latest
environment:
name: ${{ needs.detectenv.outputs.env_name }}
steps:
- uses: actions/checkout@v4
- uses: snyk/actions/setup@master

- name: Setup python
uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml' # Read python version from a file pyproject.toml
cache: 'pip'

- name: Pip install
run: |
pip install --upgrade pip
pip install -e .
poetry install
- name: Run snyk tests
run: |
snyk auth ${{ secrets.SNYK_TOKEN }}
snyk test --all-projects --severity-threshold=high
snyk code test --all-projects --severity-threshold=high
if [ "${{ needs.detectenv.outputs.env_isFeature }}" = "false" ]; then
snyk monitor --all-projects --severity-threshold=high --project-tags=application=TIMESERIESSDK
fi
run-tests:
name: Run tests
needs: [detectenv, snyk]
runs-on: ubuntu-latest
environment:
name: ${{ needs.detectenv.outputs.env_name }}
steps:
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'
cache: 'pip'

- name: Run tests
run: |
pip install --upgrade pip
pip install -e .
python -m pytest
build:
needs: [detectenv, run-tests]
runs-on: ubuntu-latest
if: startsWith(github.ref_type, 'tag')
environment:
name: ${{ needs.detectenv.outputs.env_name }}
steps:
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v4
with:
python-version-file: 'pyproject.toml'
cache: 'pip'

- name: Build SDK
run: |
pip install --upgrade pip
pip install -e .
python -m build
- name: Release
uses: ncipollo/release-action@v1
with:
artifacts: ./dist/*
generateReleaseNotes: true
allowUpdates: true
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ the flow, execution will proceed.
#### With default credentials (azure cli, MSI and so on)

```python
from omnia_timeseries import TimeseriesEnvironment, TimeseriesAPI
from omnia_timeseries_api import TimeseriesEnvironment, TimeseriesAPI
from azure.identity import DefaultAzureCredential
cred = DefaultAzureCredential()
api = TimeseriesAPI(cred, TimeseriesEnvironment.Prod())
Expand All @@ -72,7 +72,7 @@ api.get_timeseries(limit=1)
### Getting latest datapoint for timeseries within the Test environment

```python
from omnia_timeseries import TimeseriesAPI, TimeseriesEnvironment
from omnia_timeseries_api import TimeseriesAPI, TimeseriesEnvironment
api = TimeseriesAPI(
azure_credential=credential,
environment=TimeseriesEnvironment.Test()
Expand Down Expand Up @@ -102,4 +102,4 @@ api = TimeseriesAPI(

### Other use cases

Please consult the [API Reference](https://api.equinor.com/docs/services/Timeseries-api-v1-6) for a full overview of the API endpoints.
Please consult the [API Reference](https://api.equinor.com/docs/services/Timeseries-api-v1-7) for a full overview of the API endpoints.
57 changes: 0 additions & 57 deletions azure-pipeline.yaml

This file was deleted.

56 changes: 32 additions & 24 deletions examples/client_secret_auth.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,83 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Client secret credentials example\n",
"\n",
"This notebook shows how to use the Timeseries API with client secret credentials"
],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import the required libraries. The `azure.identity` package will handle the actual authentication to the API"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from omnia_timeseries.api import TimeseriesAPI, TimeseriesEnvironment\n",
"from omnia_timeseries_api.api import TimeseriesAPI, TimeseriesEnvironment\n",
"from azure.identity import ClientSecretCredential\n",
"import os"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set up the API with the desired environment"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"credentials = ClientSecretCredential(\n",
" client_id=os.environ[\"AZURE_CLIENT_ID\"], \n",
" client_secret=os.environ['AZURE_CLIENT_SECRET'], \n",
" tenant_id=os.environ[\"AZURE_TENANT_ID\"])\n",
"api = TimeseriesAPI(azure_credential=credentials, environment=TimeseriesEnvironment.Beta())"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n",
"api.get_latest_datapoint(id=timeseries_id)"
],
"outputs": [],
"metadata": {}
]
}
],
"metadata": {
"language_info": {
"name": "python",
"version": "3.9.6"
"interpreter": {
"hash": "c4733b2b9ae9b4529117b1eacf27fa8f502034d92f5f116530d195fc65f7cce0"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.9.6 64-bit ('.venv': venv)"
"display_name": "Python 3.9.6 64-bit ('.venv': venv)",
"name": "python3"
},
"interpreter": {
"hash": "c4733b2b9ae9b4529117b1eacf27fa8f502034d92f5f116530d195fc65f7cce0"
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Loading

0 comments on commit 1b6b16b

Please sign in to comment.