diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 089bf0b4..4c698e9f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: check-release: name: Check release required runs-on: ubuntu-latest - if: ${{ github.event.pull_request.merged && endsWith(github.repository, '-private') != true }} + if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true outputs: release: ${{ steps.check.outputs.ready }} steps: @@ -30,15 +30,15 @@ jobs: name: Publish package runs-on: ubuntu-latest needs: check-release - if: ${{ needs.check-release.outputs.release == 'true' }} + if: needs.check-release.outputs.release == 'true' steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: # This should be the same as the one specified for on.pull_request.branches ref: master - name: Checkout actions - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: pubnub/client-engineering-deployment-tools ref: v1 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 00000000..24c7fdc4 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,73 @@ +name: Tests + +on: + push: + workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +defaults: + run: + shell: bash + +jobs: + tests: + name: Integration and Unit tests + runs-on: ubuntu-latest + strategy: + max-parallel: 1 + fail-fast: true + matrix: + php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4] + env: + PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }} + SUBSCRIBE_KEY: ${{ secrets.SUBSCRIBE_KEY }} + SECRET_KEY: ${{ secrets.SECRET_KEY }} + PUBLISH_PAM_KEY: ${{ secrets.PUBLISH_PAM_KEY }} + SUBSCRIBE_PAM_KEY: ${{ secrets.SUBSCRIBE_PAM_KEY }} + SECRET_PAM_KEY: ${{ secrets.SECRET_PAM_KEY }} + UUID_MOCK: "test-user" + steps: + - name: Checkout project + uses: actions/checkout@v3 + - name: Checkout actions + uses: actions/checkout@v3 + with: + repository: pubnub/client-engineering-deployment-tools + ref: v1 + token: ${{ secrets.GH_TOKEN }} + path: .github/.release/actions + - name: Determine composer cache directory + id: composer-cache-dir + run: echo "dir=$(composer config cache-dir)" >> $GITHUB_OUTPUT + - name: Cache Composer + uses: actions/cache@v3 + with: + path: | + "${{ steps.composer-cache-dir.outputs.dir }}" + ${{ github.workspace }}/vendor + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.json') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: phpunit + coverage: none + - name: Setup dependencies + run: | + composer self-update && composer --version + composer install --prefer-dist + - name: Run unit tests + run: vendor/bin/phpunit --verbose + - name: Cancel workflow runs for commit on error + if: failure() + uses: ./.github/.release/actions/actions/utils/fast-jobs-failure + all-tests: + name: Tests + runs-on: ubuntu-latest + needs: [tests] + steps: + - name: Tests summary + run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed" \ No newline at end of file diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml new file mode 100644 index 00000000..3ade808d --- /dev/null +++ b/.github/workflows/run-validations.yml @@ -0,0 +1,40 @@ +name: Validations + +on: + push: + workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +defaults: + run: + shell: bash + +jobs: + pubnub-yml: + name: "Validate .pubnub.yml" + runs-on: ubuntu-latest + steps: + - name: Checkout project + uses: actions/checkout@v3 + - name: Checkout validator action + uses: actions/checkout@v3 + with: + repository: pubnub/client-engineering-deployment-tools + ref: v1 + token: ${{ secrets.GH_TOKEN }} + path: .github/.release/actions + - name: "Run '.pubnub.yml' file validation" + uses: ./.github/.release/actions/actions/validators/pubnub-yml + with: + token: ${{ secrets.GH_TOKEN }} + - name: Cancel workflow runs for commit on error + if: failure() + uses: ./.github/.release/actions/actions/utils/fast-jobs-failure + all-validations: + name: Validations + runs-on: ubuntu-latest + needs: [pubnub-yml] + steps: + - name: Validations summary + run: echo -e "\033[38;2;95;215;0m\033[1mAll validations passed" \ No newline at end of file diff --git a/.github/workflows/validate-pubnub-yml.yml b/.github/workflows/validate-pubnub-yml.yml deleted file mode 100644 index 4afa4089..00000000 --- a/.github/workflows/validate-pubnub-yml.yml +++ /dev/null @@ -1,25 +0,0 @@ - -name: validate-pubnub-yml - -# Controls when the action will run. Workflow runs when manually triggered using the UI -# or API. -on: [push] - -jobs: - build: - name: Validate PubNub yml - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '12.x' - - name: Install dependencies - run: | - npm install ajv@6.12.6 - npm install yaml@1.10.0 - npm install node-fetch@2.6.1 - npm install chalk@2.4.2 - - name: Validate - run: GITHUB_TOKEN=${{ secrets.GH_TOKEN }} node ./.github/workflows/validate-yml.js \ No newline at end of file diff --git a/.github/workflows/validate-yml.js b/.github/workflows/validate-yml.js deleted file mode 100644 index 4cdbf7b0..00000000 --- a/.github/workflows/validate-yml.js +++ /dev/null @@ -1,94 +0,0 @@ -const YAML = require('yaml') -const Ajv = require('ajv'); -const fetch = require('node-fetch'); -const fs = require('fs'); -const chalk = require('chalk'); - -const ghToken = process.env.GITHUB_TOKEN; -const ghHeaders = {'User-Agent': 'sdk-bot', 'Authorization': 'token ' + ghToken,'Accept': 'application/vnd.github.v3.raw'}; - -const sdkReposJSONBranch = "develop"; -let sdkReposJSONPath = "http://api.github.com/repos/pubnub/documentation-resources/contents/website-common/tools/build/sdk-repos.json?ref=" + sdkReposJSONBranch; -startExecution(sdkReposJSONPath); - -async function startExecution(sdkReposJSONPath){ - var sdkRepos = await requestGetFromGithub(sdkReposJSONPath); - var sdkReposAndFeatureMappingArray = parseReposAndFeatureMapping(sdkRepos); - var schemaText = await requestGetFromGithub(sdkReposAndFeatureMappingArray[2]); - - schema = JSON.parse(schemaText); - var yaml = fs.readFileSync(".pubnub.yml", 'utf8'); - - if(yaml != null){ - yml = YAML.parse(yaml); - var ajv = new Ajv({schemaId: 'id', "verbose":true, "allErrors": true}); - const validate = ajv.compile(schema); - const valid = validate(yml); - if (validate.errors!= null) { - console.log(chalk.cyan("===================================")); - console.log(chalk.red(yml["version"] + " validation errors...")); - console.log(chalk.cyan("===================================")); - console.log(validate.errors); - console.log(chalk.cyan("===================================")); - var result = {code:1, repo: yml["version"], msg: "validation errors"}; - printResult(result); - process.exit(1); - } - else { - var result = {code: 0, repo: yml["version"], msg: "validation pass"}; - printResult(result); - } - } else { - var result = {code:1, repo: "yml null", msg: "validation errors"}; - printResult(result); - process.exit(1); - } -} - -function printResult(result){ - var str = result.repo + ", " + result.msg; - if(result.code === 0){ - console.log(chalk.green(str) + ", Code: " + result.code); - } else { - console.log(chalk.red(str) + ", Code: " + result.code); - } -} - -async function requestGetFromGithub(url){ - try { - const response = await fetch(url, { - headers: ghHeaders, - method: 'get', - }); - if(response.status == 200){ - const json = await response.text(); - return json; - } else { - console.error(chalk.red("res.status: " + response.status + "\n URL: " + url)); - return null; - } - - } catch (error) { - console.error(chalk.red("requestGetFromGithub: " + error + "\n URL: " + url)); - return null; - } -} - -function parseReposAndFeatureMapping(body){ - if(body != null){ - var sdkRepos = JSON.parse(body); - var locations = sdkRepos["locations"]; - if(locations!=null){ - var sdkURLs = locations["sdks"]; - var featureMappingURL = locations["featureMapping"]; - var pubnubYAMLSchemaURL = locations["pubnubYAMLSchema"]; - return [sdkURLs, featureMappingURL, pubnubYAMLSchemaURL]; - } else { - console.log(chalk.red("response locations null")); - return null; - } - } else { - console.log(chalk.red("response body null")); - return null; - } -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b910137b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -language: php -dist: xenial -os: linux - -install: - - composer self-update && composer --version - - composer install --prefer-dist - - -stages: - - name: "test" - if: | - type != pull_request \ - AND tag IS blank - - name: "code coverage" - if: | - type == pull_request - -jobs: - include: - - stage: "test" - name: 'PHP 5.6' - php: '5.6' - script: vendor/bin/phpunit --verbose - - name: 'PHP 7.0' - php: '7.0' - script: vendor/bin/phpunit --verbose - - name: 'PHP 7.1' - php: '7.1' - script: vendor/bin/phpunit --verbose - - name: 'PHP 7.2' - php: '7.2' - script: vendor/bin/phpunit --verbose - - name: 'PHP 7.3' - php: '7.3' - script: vendor/bin/phpunit --verbose - - stage: "code coverage" - name: 'Test & Code coverage' - php: '7.3' - script: vendor/bin/phpunit --verbose --coverage-clover=coverage.xml - after_success: - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file