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

change tests to run on PR instead of release #93

Merged
merged 1 commit into from
Jun 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 1 addition & 57 deletions .github/workflows/python-sdk-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
contents: write # 'write' access to repository contents
pull-requests: write # 'write' access to pull requests
steps:

- name: Checkout code
uses: actions/checkout@v4

Expand All @@ -27,63 +28,6 @@ jobs:
with:
python-version: '3.11.8'

- name: Install Docker
uses: docker-practice/actions-setup-docker@master

- name: Creation env ${{ env.ENV_NAME }} under 'Permit.io Tests' workspace
run: |
response=$(curl -X POST \
https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d '{
"key": "${{ env.ENV_NAME }}",
"name": "${{ env.ENV_NAME }}"
}')

# Extract the new env id
echo "ENV_ID=$(echo "$response" | jq -r '.id')" >> $GITHUB_ENV

echo "New env ID: $ENV_ID"

- name: Fetch API_KEY of ${{ env.ENV_NAME }}
run: |
response=$(curl -X GET \
https://api.permit.io/v2/api-key/${{ env.PROJECT_ID }}/${{ env.ENV_ID }} \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}')

# Extract the secret from the response which is the API_KEY of the new env
echo "ENV_API_KEY=$(echo "$response" | jq -r '.secret')" >> $GITHUB_ENV

echo "New env api key: $ENV_API_KEY"

- name: local PDP runnning
env:
PDP_API_KEY: ${{ env.ENV_API_KEY }}
PERMIT_API_KEY: ${{ env.ENV_API_KEY }}
run: docker run -d -p 7766:7000 --env PDP_API_KEY=${{ env.ENV_API_KEY }} --env PDP_DEBUG=true permitio/pdp-v2:latest

- name: Test with pytest
env:
PDP_URL: http://localhost:7766
API_TIER: prod
ORG_PDP_API_KEY: ${{ env.ENV_API_KEY }}
PROJECT_PDP_API_KEY: ${{ env.ENV_API_KEY }}
PDP_API_KEY: ${{ env.ENV_API_KEY }}
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pytest -s --cache-clear tests/

- name: Delete env ${{ env.ENV_NAME }}
if: always()
run: |
curl -X DELETE \
https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs/${{ env.ENV_ID }} \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}'

- name: Bump version and commit changes
run: |
sed -i "s/version=\"[0-9.]*\"/version=\"${{ github.event.release.tag_name }}\"/" setup.py
Expand Down
84 changes: 67 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,76 @@ on:
- main
- master

env:
PROJECT_ID: 7f55831d77c642739bc17733ab0af138 #github actions project id (under 'Permit.io Tests' workspace)
ENV_NAME: python-sdk-ci

jobs:
pytest:
runs-on: ubuntu-latest
name: pytest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install dependencies
run: >-
pip install
-r requirements.txt
-r requirements-dev.txt
-e .

- name: Run pytest
run: coverage run -m pytest

- name: Upload coverage to Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v2
- name: Checkout code
uses: actions/checkout@v4

- name: Python setup
uses: actions/setup-python@v5
with:
token: "27df8597-0a9e-453d-8104-7333a64628d7"
fail_ci_if_error: false
python-version: '3.11.8'

- name: Install Docker
uses: docker-practice/actions-setup-docker@master

- name: Creation env ${{ env.ENV_NAME }} under 'Permit.io Tests' workspace
run: |
response=$(curl -X POST \
https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d '{
"key": "${{ env.ENV_NAME }}",
"name": "${{ env.ENV_NAME }}"
}')

# Extract the new env id
echo "ENV_ID=$(echo "$response" | jq -r '.id')" >> $GITHUB_ENV

echo "New env ID: $ENV_ID"

- name: Fetch API_KEY of ${{ env.ENV_NAME }}
run: |
response=$(curl -X GET \
https://api.permit.io/v2/api-key/${{ env.PROJECT_ID }}/${{ env.ENV_ID }} \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}')

# Extract the secret from the response which is the API_KEY of the new env
echo "ENV_API_KEY=$(echo "$response" | jq -r '.secret')" >> $GITHUB_ENV

echo "New env api key: $ENV_API_KEY"

- name: local PDP runnning
env:
PDP_API_KEY: ${{ env.ENV_API_KEY }}
PERMIT_API_KEY: ${{ env.ENV_API_KEY }}
run: docker run -d -p 7766:7000 --env PDP_API_KEY=${{ env.ENV_API_KEY }} --env PDP_DEBUG=true permitio/pdp-v2:latest

- name: Test with pytest
env:
PDP_URL: http://localhost:7766
API_TIER: prod
ORG_PDP_API_KEY: ${{ env.ENV_API_KEY }}
PROJECT_PDP_API_KEY: ${{ env.ENV_API_KEY }}
PDP_API_KEY: ${{ env.ENV_API_KEY }}
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pytest -s --cache-clear tests/

- name: Delete env ${{ env.ENV_NAME }}
if: always()
run: |
curl -X DELETE \
https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs/${{ env.ENV_ID }} \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_readme() -> str:

setup(
name="permit",
version="2.3.0",
version="2.6.0",
packages=find_packages(),
author="Asaf Cohen",
author_email="asaf@permit.io",
Expand Down
Loading