diff --git a/.github/actions/notify-slack/action.yml b/.github/actions/notify-slack/action.yml new file mode 100644 index 00000000..add9673f --- /dev/null +++ b/.github/actions/notify-slack/action.yml @@ -0,0 +1,103 @@ +name: slack-alert-action +description: "Action to send slack payload to public-sdk-events channel" + +inputs: + heading_text: + required: true + description: "Heading of the slack payload" + alert_type: + required: true + description: "type of the slack alert" + job_status: + required: true + description: "status of the job" + XERO_SLACK_WEBHOOK_URL: + required: true + description: "webhook url for channel - public-sdk-events" + job_url: + required: true + description: "job run id link" + button_type: + required: true + description: "color for the check logs button" + package_version: + required: true + description: "released package version" + repo_link: + required: true + description: "link of the repo" + + +runs: + using: "composite" + + steps: + + - name: Send slack notification + id: slack + uses: slackapi/slack-github-action@v1.27.0 + env: + SLACK_WEBHOOK_URL: ${{inputs.XERO_SLACK_WEBHOOK_URL}} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + with: + payload: | + { + "blocks": [ + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "${{inputs.heading_text}} ", + "style": { + "bold": true + } + }, + { + "type": "emoji", + "name": "${{inputs.alert_type}}" + } + ] + } + ] + }, + { + "type": "divider" + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Repository:* \n ${{inputs.repo_link}}" + }, + { + "type": "mrkdwn", + "text": "*Status:*\n ${{inputs.job_status}}" + }, + { + "type": "mrkdwn", + "text": "*Package Version:*\n ${{inputs.package_version}}" + } + ] + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Check the logs", + "emoji": true + }, + "style": "${{inputs.button_type}}", + "url": "${{inputs.job_url}}" + } + ] + } + ] + } diff --git a/.github/workflows/build-lint-test.yml b/.github/workflows/build-lint-test.yml index 817ae935..6a0fe576 100644 --- a/.github/workflows/build-lint-test.yml +++ b/.github/workflows/build-lint-test.yml @@ -27,6 +27,14 @@ jobs: run: composer install working-directory: xero-php-oauth2 + - name: Check for Vulnerabilities + run: composer audit + working-directory: xero-php-oauth2 + + - name: Check for Outdated Packages + run: composer outdated + working-directory: xero-php-oauth2 + - name: Validate PHP Syntax run: find . -path ./vendor -prune -o -name "*.php" -exec php -l {} \; > /dev/null || exit 1 working-directory: xero-php-oauth2 \ No newline at end of file diff --git a/.github/workflows/check-publish.yml b/.github/workflows/check-publish.yml new file mode 100644 index 00000000..3ad66dde --- /dev/null +++ b/.github/workflows/check-publish.yml @@ -0,0 +1,78 @@ +name: Check Packagist Publish + +on: + release: + types: [published] + +jobs: + check-publish: + runs-on: ubuntu-latest + + steps: + + - name: Checkout repo + uses: actions/checkout@v4 + with: + repository: XeroAPI/xero-php-oauth2 + path: xero-php-oauth2 + + - name: Fetch Latest release number + id: get_latest_release_number + run: | + latest_version=$(gh release view --json tagName --jq '.tagName') + echo "Latest release version is - $latest_version" + echo "php_version=${latest_version}" >> $GITHUB_ENV + working-directory: xero-php-oauth2 + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - name: Get latest version from packgist + id: get_packagist_version + run: | + RESPONSE=$(curl -s https://repo.packagist.org/p2/xeroapi/xero-php-oauth2.json) + LATEST_VERSION=$(echo $RESPONSE | jq -r '.packages["xeroapi/xero-php-oauth2"][0].version') + echo "latest packagist version: $LATEST_VERSION" + echo "latest_packagist_version=${LATEST_VERSION}" >> $GITHUB_ENV + + - name: Compare versions + id: compare_versions + run: | + if [ "${{env.php_version}}" == "${{env.latest_packagist_version}}" ]; then + echo "Packagist is up-to-date" + echo "packagist_status=success" >> $GITHUB_ENV + else + echo "Packagist is not updated yet" + echo "packagist_status=failure" >> $GITHUB_ENV + fi + + - name: Send slack Notification on Success + if: ${{ env.packagist_status == 'success' }} + uses: ./xero-php-oauth2/.github/actions/notify-slack + with: + heading_text: "Publish job has succeeded !" + alert_type: "thumbsup" + job_status: "Success" + XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} + job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" + button_type: "primary" + package_version: ${{env.php_version}} + repo_link: ${{github.server_url}}/${{github.repository}} + + - name: Send slack Notification on Failure + if: ${{ env.packagist_status == 'failure' }} + uses: ./xero-php-oauth2/.github/actions/notify-slack + with: + heading_text: "Publish job has failed !" + alert_type: "alert" + job_status: "Failed" + XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} + job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" + button_type: "danger" + package_version: ${{env.php_version}} + repo_link: ${{github.server_url}}/${{github.repository}} + + - name: Fail job if status is Failure + if: ${{env.packagist_status == 'failure'}} + run: | + echo "Job failed because packagist is not updated" + exit 1 diff --git a/README.md b/README.md index cc9c2c3c..e73b6551 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Sample apps can get you started quickly with simple auth flows and advanced usag # Installation To install this SDK in your project we recommend using [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos) (For OSX we recommend using [Homebrew](https://formulae.brew.sh/formula/composer)). -All third party libraries dependencies managed with Composer and the SDK requires `PHP 5.6` and later. +All third party libraries dependencies managed with Composer and the SDK requires `PHP 8.1` and later. To install the bindings via [Composer](http://getcomposer.org/), and add the xero-php-oauth2 sdk to your `composer.json` and navigate to where your composer.json file is and run the command: ``` diff --git a/composer.json b/composer.json index d9c292ee..f8e230eb 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": ">=5.6", + "php": ">=8.1", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", @@ -27,9 +27,8 @@ "firebase/php-jwt": "^6.0" }, "require-dev": { - "phpunit/phpunit": "^4.8", - "squizlabs/php_codesniffer": "~2.6", - "friendsofphp/php-cs-fixer": "~2.12" + "squizlabs/php_codesniffer": "^3.10", + "friendsofphp/php-cs-fixer": "^3.60" }, "autoload": { "psr-4": { "XeroAPI\\XeroPHP\\" : "lib/" } diff --git a/test/Api/AccountingApiTest.php b/test/Api/AccountingApiTest.php deleted file mode 100644 index 7382c2e8..00000000 --- a/test/Api/AccountingApiTest.php +++ /dev/null @@ -1,1973 +0,0 @@ -