diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1f04b47..2cee215 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Release on: push: branches: - - master + - "*" tags: - "*" @@ -24,6 +24,33 @@ jobs: - name: Test run: pytest tests/ + azure_test: + name: Azure Test + runs-on: ubuntu-latest + environment: + name: dev.azure + permissions: + id-token: write + contents: read + steps: + - name: 'Az CLI Login via OIDC' + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - uses: actions/checkout@v3 + - name: Set up Python 3.8 + uses: actions/setup-python@v4 + with: + python-version: 3.8 + - name: Install setuptools and + run: | + python -m pip install --upgrade setuptools wheel + python -m pip install -r requirements-dev.txt + - name: Test + run: pytest azure_tests/ + publish: name: Publish if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') diff --git a/tests/integration_test.py b/azure_tests/integration_test.py similarity index 91% rename from tests/integration_test.py rename to azure_tests/integration_test.py index ac608e2..8cf73c1 100644 --- a/tests/integration_test.py +++ b/azure_tests/integration_test.py @@ -5,7 +5,7 @@ import pytest from azure.mgmt.dns import DnsManagementClient -from azure.identity import ClientSecretCredential +from azure.identity import ClientSecretCredential, AzureCliCredential if TYPE_CHECKING: import pathlib @@ -14,8 +14,8 @@ EMAIL = os.getenv('EMAIL', 'NOT_AN_EMAIL') azure_creds = pytest.mark.skipif( - any(env not in os.environ for env in ['AZURE_SP_ID', 'AZURE_SP_SECRET', 'AZURE_TENANT_ID', 'EMAIL']), - reason="Missing 'AZURE_SP_ID', 'AZURE_SP_SECRET', 'AZURE_TENANT_ID' environment variables" + any(env not in os.environ for env in ['AZURE_CLIENT_ID', 'AZURE_TENANT_ID', 'EMAIL']), + reason="Missing 'AZURE_CLIENT_ID'', 'AZURE_TENANT_ID' environment variables" ) SUBSCRIPTION_ID = '90907259-f568-40c9-be09-768317e458ae' @@ -36,12 +36,15 @@ def get_cert_names(count: int = 1) -> List[str]: @pytest.fixture(scope='session') def azure_dns_client() -> DnsManagementClient: - creds = ClientSecretCredential( - client_id=os.environ['AZURE_SP_ID'], - client_secret=os.environ['AZURE_SP_SECRET'], - tenant_id=os.environ['AZURE_TENANT_ID'], - authority='https://login.microsoftonline.com/' - ) + if 'AZURE_SP_SECRET' in os.environ: + creds = ClientSecretCredential( + client_id=os.environ['AZURE_CLIENT_ID'], + client_secret=os.environ['AZURE_SP_SECRET'], + tenant_id=os.environ['AZURE_TENANT_ID'], + authority='https://login.microsoftonline.com/' + ) + else: + creds = AzureCliCredential(tenant_id=os.environ['AZURE_TENANT_ID']) return DnsManagementClient(creds, SUBSCRIPTION_ID, None, 'https://management.azure.com/', credential_scopes=['https://management.azure.com//.default'])