New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Github Actions #275
Changes from all commits
367798f
452ce4e
e605806
f2fbd9e
ac9dbc1
bb38e5d
16fed6b
da77b94
98107a0
ff5ced5
b9c9d4c
cde6a12
3cfbf08
f188c9e
39ed46b
dadbc8b
26e4c81
34dc99b
7b9bea1
6eef3ee
42b8068
895f08e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
tags: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [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.7.0 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extension-csv: dom, mbstring | ||
coverage: xdebug | ||
- 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 | ||
- name: Run composer script | ||
run: | | ||
composer install-dev-tools; | ||
composer sca |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -63,6 +63,7 @@ public function collect(array $env) | |||||
->fillCircleCi() | ||||||
->fillAppVeyor() | ||||||
->fillJenkins() | ||||||
->fillGithubActions() | ||||||
->fillLocal() | ||||||
->fillRepoToken(); | ||||||
|
||||||
|
@@ -110,6 +111,48 @@ protected function fillTravisCi() | |||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Fill Github Actions environment variables. | ||||||
* | ||||||
* @return $this | ||||||
*/ | ||||||
protected function fillGithubActions() | ||||||
{ | ||||||
if (!isset($this->env['GITHUB_ACTIONS'])) { | ||||||
return $this; | ||||||
} | ||||||
$this->env['CI_NAME'] = 'github'; | ||||||
|
||||||
$githubEventName = $this->env['GITHUB_EVENT_NAME']; | ||||||
$githubSha = $this->env['GITHUB_SHA']; | ||||||
$githubRef = $this->env['GITHUB_REF']; | ||||||
|
||||||
if (strpos($githubRef, 'refs/heads/') !== false) { | ||||||
$githubRef = str_replace('refs/heads/', '', $githubRef); | ||||||
$jobId = $githubSha; | ||||||
} elseif ($githubEventName === 'pull_request') { | ||||||
$refParts = explode('/', $githubRef); | ||||||
$prNumber = $refParts[2]; | ||||||
$this->env['CI_PULL_REQUEST'] = $prNumber; | ||||||
$this->readEnv['CI_PULL_REQUEST'] = $this->env['CI_PULL_REQUEST']; | ||||||
$jobId = sprintf('%s-PR-%s', $githubSha, $prNumber); | ||||||
} elseif (strpos($githubRef, 'refs/tags/') !== false) { | ||||||
$githubRef = str_replace('refs/tags/', '', $githubRef); | ||||||
$jobId = $githubRef; | ||||||
} | ||||||
|
||||||
$this->env['CI_JOB_ID'] = $jobId; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OndraM maybe, but seems like maintainers ignore this PR and communication with community is broken |
||||||
$this->env['CI_BRANCH'] = $githubRef; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referential implementation did not send this if I remember correctly. Currently I'm using it without setting branch. The problem is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that itsn't principal moment |
||||||
|
||||||
$this->readEnv['GITHUB_ACTIONS'] = $this->env['GITHUB_ACTIONS']; | ||||||
$this->readEnv['GITHUB_REF'] = $this->env['GITHUB_REF']; | ||||||
$this->readEnv['CI_NAME'] = $this->env['CI_NAME']; | ||||||
$this->readEnv['CI_JOB_ID'] = $this->env['CI_JOB_ID']; | ||||||
$this->readEnv['CI_BRANCH'] = $this->env['CI_BRANCH']; | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Fill CircleCI environment variables. | ||||||
* | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,9 +74,9 @@ protected function collectBranch() | |
|
||
foreach ($branchesResult as $result) { | ||
if (strpos($result, '* ') === 0) { | ||
$exploded = explode('* ', $result, 2); | ||
preg_match('~^\* (?:\(HEAD detached at )?([\w/]+)\)?~', $result, $matches); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks for branches which have hyphens ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Smolevich I'll fix this and send you PR, k? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My branch has hyphen and this code don't break There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (edit: fixed the code of the test) Here's a test which replicates the problem (feel free to use it in this PR): /**
* @test
*/
public function shouldParseCaseInsensitive()
{
$branches = [
' TEST-123',
'* TEST-456',
' TEST-789',
];
$gitCommand = $this->createGitCommandStubWith($branches, $this->getHeadCommitValue, $this->getRemotesValue);
$object = new GitInfoCollector($gitCommand);
$result =$object->collect();
$this->assertEquals('TEST-456', $result->getBranch());
} I've seen that github actions checks out the code in detached HEAD There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also broke prod release :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also recovered support for hyphens |
||
|
||
return $exploded[1]; | ||
return $matches[1]; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -72,6 +72,11 @@ public function getHelpMessage() | |||
- APPVEYOR | ||||
- APPVEYOR_BUILD_NUMBER | ||||
|
||||
For Githib Actions users: | ||||
- GITHUB_REF | ||||
- GITHUB_SHA | ||||
- GITHUB_ACTIONS | ||||
Comment on lines
+76
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See php-coveralls/src/Bundle/CoverallsBundle/Entity/Exception/RequirementsNotSatisfiedException.php Line 56 in 2ecb7c1
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I'm using it without those variables explicitly set so I'm not sure we should require users to do so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand you, but it's linked with #275 (review), if maintainer @keradus answer on my question about required variable for GA There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @simPod i add new function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Users don't set variables like |
||||
|
||||
From local environment: | ||||
|
||||
- COVERALLS_RUN_LOCALLY | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,66 @@ public function shouldCollectJenkinsEnvVars() | |
return $object; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldCollectGithubActionsEnvVars() | ||
{ | ||
$serviceName = 'github'; | ||
$jobId = '3fd27e3b7c1ae6a0931d3b637b742440f5eb5011'; | ||
$gitTag = 'v0.1.1'; | ||
|
||
$env = []; | ||
$env['COVERALLS_REPO_TOKEN'] = 'token'; | ||
$env['GITHUB_ACTIONS'] = true; | ||
$env['GITHUB_EVENT_NAME'] = 'push'; | ||
$env['GITHUB_REF'] = 'refs/heads/master'; | ||
$env['GITHUB_SHA'] = $jobId; | ||
|
||
$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']); | ||
|
||
$env['GITHUB_REF'] = 'refs/tags/' . $gitTag; | ||
$actual = $object->collect($env); | ||
$this->assertSame($gitTag, $actual['CI_JOB_ID']); | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldCollectGithubActionsEnvVarsForPullRequest() | ||
{ | ||
$serviceName = 'github'; | ||
|
||
$env = []; | ||
$env['COVERALLS_REPO_TOKEN'] = 'token'; | ||
$env['GITHUB_ACTIONS'] = true; | ||
$env['GITHUB_EVENT_NAME'] = 'pull_request'; | ||
$env['GITHUB_REF'] = 'refs/pull/1/merge'; | ||
$env['GITHUB_SHA'] = '3fd27e3b7c1ae6a0931d3b637b742440f5eb5011'; | ||
|
||
$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('3fd27e3b7c1ae6a0931d3b637b742440f5eb5011-PR-1', $actual['CI_JOB_ID']); | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
|
@@ -232,6 +292,25 @@ public function shouldHaveReadEnvAfterCollectTravisCiEnvVars(CiEnvVarsCollector | |
$this->assertArrayHasKey('CI_NAME', $readEnv); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends shouldCollectGithubActionsEnvVars | ||
* | ||
* @param CiEnvVarsCollector $object | ||
*/ | ||
public function shouldHaveReadEnvAfterCollectGithubActionsEnvVars(CiEnvVarsCollector $object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder how is it possible to use param type hint on PHP 5.5? 🤔Build is green There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like that build runs only php 7.1.2 in appveyor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are run in 5.5 https://travis-ci.org/php-coveralls/php-coveralls/jobs/632963135 as well. Mysterious :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keradus, can we delete ci for php 5.5? |
||
{ | ||
$readEnv = $object->getReadEnv(); | ||
|
||
$this->assertCount(6, $readEnv); | ||
$this->assertArrayHasKey('GITHUB_REF', $readEnv); | ||
$this->assertArrayHasKey('CI_NAME', $readEnv); | ||
$this->assertArrayHasKey('CI_JOB_ID', $readEnv); | ||
$this->assertArrayHasKey('GITHUB_ACTIONS', $readEnv); | ||
$this->assertArrayHasKey('CI_BRANCH', $readEnv); | ||
$this->assertArrayHasKey('COVERALLS_REPO_TOKEN', $readEnv); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends shouldCollectTravisProEnvVars | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to keep the method order to comply with order in
collect()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that call
fillGithubActions
should last?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes