Skip to content

Commit

Permalink
Merge 98107a0 into 3e6420f
Browse files Browse the repository at this point in the history
  • Loading branch information
Smolevich committed Nov 20, 2019
2 parents 3e6420f + 98107a0 commit 975878f
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/blank.yml
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches:
tags:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php: [5.6, 7.0, 7.1, 7.2, 7.3]
steps:
- uses: actions/checkout@v1
- name: Debug if needed
run: |
export DEBUG=${DEBUG:-false}
if [[ "$DEBUG" == "true" ]]; then
env
fi
env:
DEBUG: ${{secrets.DEBUG}}
- name: Setup php
uses: shivammathur/setup-php@1.5.2
with:
php-version: ${{ matrix.php }}
extension-csv: dom, mbstring
coverage: xdebug
- name: Show php version
run: php${{ matrix.php }} -v && composer -V
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install
29 changes: 29 additions & 0 deletions src/Bundle/CoverallsBundle/Collector/CiEnvVarsCollector.php
Expand Up @@ -64,6 +64,7 @@ public function collect(array $env)
->fillAppVeyor()
->fillJenkins()
->fillLocal()
->fillGithubActions()
->fillRepoToken();

return $this->env;
Expand Down Expand Up @@ -110,6 +111,34 @@ protected function fillTravisCi()
return $this;
}

/**
* Fill Github Actions environment variables.
*
* @return $this
*/
protected function fillGithubActions()
{
if (isset($this->env['GITHUB_ACTIONS'])) {
$this->env['CI_NAME'] = 'github-actions';

$this->env['CI_JOB_ID'] = $this->env['GITHUB_ACTIONS'];
$githubRef = $this->env['GITHUB_REF'];

if (strpos($githubRef, 'refs/heads/') !== false) {
$githubRef = str_replace('refs/heads/', '', $githubRef);
} elseif (strpos($githubRef, 'refs/tags/') !== false) {
$githubRef = str_replace('refs/tags/', '', $githubRef);
}
$this->env['CI_BRANCH'] = $githubRef;

$this->readEnv['GITHUB_ACTIONS'] = $this->env['GITHUB_ACTIONS'];
$this->readEnv['GITHUB_REF'] = $this->env['GITHUB_REF'];
$this->readEnv['CI_NAME'] = $this->env['CI_NAME'];
}

return $this;
}

/**
* Fill CircleCI environment variables.
*
Expand Down
48 changes: 48 additions & 0 deletions tests/Bundle/CoverallsBundle/Collector/CiEnvVarsCollectorTest.php
Expand Up @@ -134,6 +134,37 @@ public function shouldCollectJenkinsEnvVars()
return $object;
}

/**
* @test
*/
public function shouldCollectGithubActionsEnvVars()
{
$serviceName = 'github-actions';
$jobId = '123';
$refName = 'refs/heads/master';
$branchName = 'master';

$env = [];
$env['COVERALLS_REPO_TOKEN'] = 'token';
$env['GITHUB_ACTIONS'] = $jobId;
$env['GITHUB_REF'] = 'refs/heads/master';

$object = $this->createCiEnvVarsCollector();

$actual = $object->collect($env);

$this->assertArrayHasKey('CI_NAME', $actual);
$this->assertSame($serviceName, $actual['CI_NAME']);

$this->assertArrayHasKey('CI_JOB_ID', $actual);
$this->assertSame($jobId, $actual['CI_JOB_ID']);

$this->assertArrayHasKey('CI_BRANCH', $actual);
$this->assertSame($branchName, $actual['CI_BRANCH']);

return $object;
}

/**
* @test
*/
Expand Down Expand Up @@ -232,6 +263,23 @@ public function shouldHaveReadEnvAfterCollectTravisCiEnvVars(CiEnvVarsCollector
$this->assertArrayHasKey('CI_NAME', $readEnv);
}

/**
* @test
* @depends shouldCollectGithubActionsEnvVars
*
* @param CiEnvVarsCollector $object
*/
public function shouldHaveReadEnvAfterCollectGithubActionsEnvVars(CiEnvVarsCollector $object)
{
$readEnv = $object->getReadEnv();

$this->assertCount(4, $readEnv);
$this->assertArrayHasKey('GITHUB_REF', $readEnv);
$this->assertArrayHasKey('CI_NAME', $readEnv);
$this->assertArrayHasKey('GITHUB_ACTIONS', $readEnv);
$this->assertArrayHasKey('COVERALLS_REPO_TOKEN', $readEnv);
}

/**
* @test
* @depends shouldCollectTravisProEnvVars
Expand Down

0 comments on commit 975878f

Please sign in to comment.