Skip to content

Commit

Permalink
Merge pull request #80 from goshippo/github-actions-setup
Browse files Browse the repository at this point in the history
[DVRL-8] GitHub actions setup
  • Loading branch information
vyshakhbabji authored Jun 21, 2022
2 parents 7422af5 + 4428da5 commit d0c4448
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/sdk-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: PHP SDK Test

on:
# Run the tests on every push to the master branch
push:
branches: [ "master" ]

# Run the tests for the default branch [master] every Monday 3:00 pm UTC time (8:00 am PST)
schedule:
- cron: "0 15 * * 1"

permissions:
contents: read

jobs:
build:

runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.0']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- uses: actions/checkout@v3
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Check PHP Version
run: php -v
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- id: tests
name: Run the tests
run: ./vendor/bin/phpunit
- name: Send a Slack notification saying if tests are passing/failing for a given PHP version
shell: bash
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
conclusion=${{ steps.tests.conclusion }}
if [[ "$conclusion" == "success" ]]; then
message="✅ PHP SDK Test succeeded for PHP ${{ matrix.php-versions }}"
else
message="❌ PHP SDK Test failed for PHP ${{ matrix.php-versions }}"
fi
curl -X POST --data-urlencode "payload={\"text\": \"$message\", \"link_names\": 1}" $SLACK_WEBHOOK_URL
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
*.cache
*.cache
.idea
14 changes: 13 additions & 1 deletion test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
// Base class for test cases
class TestCase extends \PHPUnit\Framework\TestCase
{
const SHIPPO_KEY = '<YOUR SHIPPO API KEY>';
const SHIPPO_KEY = 'shippo_test_cf1b6d0655e59fc6316880580765066038ef20d8';
const SHIPPO_API_VERSION = '2018-02-08';

//mock curl client for mocking requests
private $mock;

protected function setUp() : void
{
self::authFromEnv();
self::apiVersionFromEnv();
Shippo_ApiRequestor::setHttpClient(CurlClient::instance());
$this->mock = null;
}
Expand All @@ -27,6 +29,16 @@ protected static function authFromEnv()
Shippo::setApiKey($apiKey);
}

protected static function apiVersionFromEnv()
{
$apiVersion = getenv('SHIPPO_API_VERSION');
if (!$apiVersion) {
$apiVersion = self::SHIPPO_API_VERSION;
}

Shippo::setApiVersion($apiVersion);
}

protected function mockRequest($method, $path, $params = array(),
$return = array(), $rcode = 200)
{
Expand Down

0 comments on commit d0c4448

Please sign in to comment.