Skip to content

Tests: Exchange API Key and Secret for OAuth Tokens #266

Tests: Exchange API Key and Secret for OAuth Tokens

Tests: Exchange API Key and Secret for OAuth Tokens #266

Workflow file for this run

name: Run Tests
# When to run tests.
on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- master
jobs:
tests:
# Name.
name: PHP ${{ matrix.php-versions }}
# Virtual Environment to use.
# @see: https://github.com/actions/virtual-environments
runs-on: ubuntu-latest
# Defines PHP Versions matrix to run tests on
strategy:
fail-fast: false
matrix:
php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4' ]
# Steps to install, configure and run tests
steps:
# Checkout (copy) this repository's Plugin to this VM.
- name: Checkout Code
uses: actions/checkout@v4
# Install PHP version
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
# Exchange API Keys and Secrets for OAuth Tokens.
- name: Exchange API Key and Secret for OAuth Tokens
id: get-oauth-tokens
run: |
response=$(curl -s -X POST "${{ secrets.CONVERTKIT_EXCHANGE_API_KEYS_ENDPOINT }}?api_key=${{ secrets.CONVERTKIT_V3_API_KEY }}&api_secret=${{ secrets.CONVERTKIT_V3_API_SECRET }}&client_id=${{ secrets.CONVERTKIT_OAUTH_CLIENT_ID }}&redirect_uri=${{ secrets.CONVERTKIT_OAUTH_REDIRECT_URI }}&tenant_name=github-actions-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }}")
access_token=$(echo "$response" | jq -r '.oauth.access_token')
refresh_token=$(echo "$response" | jq -r '.oauth.refresh_token')
echo "KIT_OAUTH_ACCESS_TOKEN=$access_token" >> $GITHUB_ENV
echo "KIT_OAUTH_REFRESH_TOKEN=$refresh_token" >> $GITHUB_ENV
response=$(curl -s -X POST "${{ secrets.CONVERTKIT_EXCHANGE_API_KEYS_ENDPOINT }}?api_key=${{ secrets.CONVERTKIT_V3_API_KEY_NO_DATA }}&api_secret=${{ secrets.CONVERTKIT_V3_API_SECRET_NO_DATA }}&client_id=${{ secrets.CONVERTKIT_OAUTH_CLIENT_ID }}&redirect_uri=${{ secrets.CONVERTKIT_OAUTH_REDIRECT_URI }}&tenant_name=github-actions-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }}")
access_token=$(echo "$response" | jq -r '.oauth.access_token')
refresh_token=$(echo "$response" | jq -r '.oauth.refresh_token')
echo "KIT_OAUTH_ACCESS_TOKEN_NO_DATA=$access_token" >> $GITHUB_ENV
echo "KIT_OAUTH_REFRESH_TOKEN_NO_DATA=$refresh_token" >> $GITHUB_ENV
# Write any secrets, such as API keys, to the .env.dist.testing file now.
# Make sure your committed .env.dist.testing file ends with a newline.
# The formatting of the contents to include a blank newline is deliberate.
- name: Define GitHub Secrets in .env.dist.testing
uses: DamianReeves/[email protected]
with:
path: .env.dist.testing
contents: |
CONVERTKIT_OAUTH_ACCESS_TOKEN=${{ env.KIT_OAUTH_ACCESS_TOKEN }}
CONVERTKIT_OAUTH_REFRESH_TOKEN=${{ env.KIT_OAUTH_REFRESH_TOKEN }}
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=${{ env.KIT_OAUTH_ACCESS_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=${{ env.KIT_OAUTH_REFRESH_TOKEN_NO_DATA }}
CONVERTKIT_V4_API_KEY=${{ secrets.CONVERTKIT_V4_API_KEY }}
CONVERTKIT_OAUTH_CLIENT_ID=${{ secrets.CONVERTKIT_OAUTH_CLIENT_ID }}
CONVERTKIT_OAUTH_CLIENT_SECRET=${{ secrets.CONVERTKIT_OAUTH_CLIENT_SECRET }}
CONVERTKIT_OAUTH_REDIRECT_URI=${{ secrets.CONVERTKIT_OAUTH_REDIRECT_URI }}
write-mode: append
# Rename .env.dist.testing to .env, so PHPUnit reads it for tests.
- name: Rename .env.dist.testing to .env
run: mv .env.dist.testing .env
# Installs PHPUnit, PHP CodeSniffer and anything else needed to run tests.
- name: Run Composer
run: composer update
# Generate autoloader
- name: Build PHP Autoloader
run: composer dump-autoload
# Run PHPStan for static analysis.
- name: Run PHPStan Static Analysis
run: php vendor/bin/phpstan analyse --memory-limit=1250M
# Run Coding Standards.
- name: Run Coding Standards
run: php vendor/bin/phpcs --standard=phpcs.xml
# Run Coding Standards on Tests.
- name: Run Coding Standards on Tests
run: php vendor/bin/phpcs --standard=phpcs.tests.xml
# Run PHPUnit Tests.
- name: Run PHPUnit Tests
run: vendor/bin/phpunit --verbose --stop-on-failure