From 0dcc62650f14846d2149d978f79dcde044ff0a2b Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 29 Dec 2022 13:44:06 +0100 Subject: [PATCH 1/2] test(github-action): refactor command handler (#74) Refactor command handler workflow to use bot name from secrets. refactor(codeowners): updare list of codeowners Actualize list of project codeowners. --- .github/CODEOWNERS | 4 ++-- .github/workflows/commands-handler.yml | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index cc5a5cd8..bf8b13b3 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,3 @@ -* @seba-aln @phairow @MikeDobrzan @marcin-cebo @mohitpubnub -.github/* @parfeon @seba-aln @phairow @MikeDobrzan @marcin-cebo @mohitpubnub +* @seba-aln @MikeDobrzan @marcin-cebo @mohitpubnub +.github/* @parfeon @seba-aln @MikeDobrzan @marcin-cebo @mohitpubnub README.md @techwritermat @kazydek diff --git a/.github/workflows/commands-handler.yml b/.github/workflows/commands-handler.yml index e5196c1b..4e34b04c 100644 --- a/.github/workflows/commands-handler.yml +++ b/.github/workflows/commands-handler.yml @@ -3,25 +3,41 @@ name: Commands processor on: issue_comment: types: [created] +defaults: + run: + shell: bash jobs: process: name: Process command - if: ${{ github.event.issue.pull_request && endsWith(github.repository, '-private') != true && startsWith(github.event.comment.body, '@client-engineering-bot ') }} + if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true runs-on: ubuntu-latest steps: + - name: Check referred user + id: user-check + env: + CLEN_BOT: ${{ secrets.CLEN_BOT }} + run: echo "expected-user=${{ startsWith(github.event.comment.body, format('@{0} ', env.CLEN_BOT)) }}" >> $GITHUB_OUTPUT + - name: Regular comment + if: steps.user-check.outputs.expected-user != 'true' + run: echo -e "\033[38;2;19;181;255mThis is regular commit which should be ignored.\033[0m" - name: Checkout repository - uses: actions/checkout@v2 + if: steps.user-check.outputs.expected-user == 'true' + uses: actions/checkout@v3 + with: + token: ${{ secrets.GH_TOKEN }} - name: Checkout release actions - uses: actions/checkout@v2 + if: steps.user-check.outputs.expected-user == 'true' + uses: actions/checkout@v3 with: repository: pubnub/client-engineering-deployment-tools ref: v1 token: ${{ secrets.GH_TOKEN }} path: .github/.release/actions - name: Process changelog entries + if: steps.user-check.outputs.expected-user == 'true' uses: ./.github/.release/actions/actions/commands with: token: ${{ secrets.GH_TOKEN }} - listener: client-engineering-bot - jira-api-key: ${{ secrets.JIRA_API_KEY }} + listener: ${{ secrets.CLEN_BOT }} + jira-api-key: ${{ secrets.JIRA_API_KEY }} \ No newline at end of file From fa08b85f366669d0b6e1ef7d5ae827485a89e7f2 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 3 Jan 2023 15:02:37 +0100 Subject: [PATCH 2/2] Migrate tests to GitHub Actions (#75) test(github-actions): migrate tests to GitHub Actions Migrate PubNub SDK test suite from Travis to GitHub Actions. test(workflow): add unitying job for status check test(workflow): temporary disable parallel jobs execution --- .github/workflows/release.yml | 8 +- .github/workflows/run-tests.yml | 73 ++++++++++++++++++ .github/workflows/run-validations.yml | 40 ++++++++++ .github/workflows/validate-pubnub-yml.yml | 25 ------ .github/workflows/validate-yml.js | 94 ----------------------- .travis.yml | 42 ---------- 6 files changed, 117 insertions(+), 165 deletions(-) create mode 100644 .github/workflows/run-tests.yml create mode 100644 .github/workflows/run-validations.yml delete mode 100644 .github/workflows/validate-pubnub-yml.yml delete mode 100644 .github/workflows/validate-yml.js delete mode 100644 .travis.yml 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