Skip to content
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 Github Actions and COVERALLS_FLAG_NAME support #296

Merged
merged 36 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
367798f
Add support for Github Actions
Smolevich Oct 21, 2019
452ce4e
Change typo
Smolevich Oct 22, 2019
e605806
Add return for Github Actions
Smolevich Oct 22, 2019
f2fbd9e
Fix failed test
Smolevich Oct 22, 2019
ac9dbc1
Fix cs errors
Smolevich Oct 22, 2019
bb38e5d
Merge remote-tracking branch 'upstream/2.2' into add-support-for-gith…
Smolevich Nov 20, 2019
16fed6b
Merge 2.2 and add blank yaml for GIthub Actions
Smolevich Nov 20, 2019
da77b94
Fix github actions
Smolevich Nov 20, 2019
98107a0
Fix ci
Smolevich Nov 20, 2019
ff5ced5
Update exception message
Smolevich Jan 5, 2020
b9c9d4c
GA tweaks
simPod Jan 6, 2020
cde6a12
Reformat method fillGithubActions
Smolevich Jan 6, 2020
3cfbf08
Add condition for pull request
Smolevich Jan 6, 2020
f188c9e
Install dev tools in workflow file
Smolevich Jan 6, 2020
39ed46b
Fix cs fixer errors
Smolevich Jan 6, 2020
dadbc8b
Merge branch 'add-support-for-github-actions' into add-support-for-gi…
Smolevich Jan 6, 2020
26e4c81
Merge pull request #1 from simPod/add-support-for-github-actions
Smolevich Jan 6, 2020
34dc99b
Fix test CiEnvVarsCollectorTest
Smolevich Jan 6, 2020
7b9bea1
Change collector and test for him
Smolevich Jan 7, 2020
6eef3ee
Change test
Smolevich Jan 16, 2020
42b8068
Fix test for GA
Smolevich Jan 16, 2020
895f08e
Fix failed tests
Smolevich Jan 16, 2020
db8add4
Merge remote-tracking branch 'upstream/2.3' into feature/github-actions
twinh Sep 27, 2020
d73a2cb
build: added PHP 7.4
twinh Jun 13, 2020
743818d
refactor: use GITHUB_RUN_ID as CI_JOB_ID, same as coverallsapp/github…
twinh Jun 13, 2020
905ff53
docs: add link about GITHUB_RUN_ID
twinh Sep 27, 2020
342cc47
ci: Replace extension-csv to extension
twinh Sep 27, 2020
3f5d1af
test: fix job ID test fail
twinh Sep 27, 2020
381ecd0
feat: add COVERALLS_FLAG_NAME support
twinh Sep 28, 2020
48a4ead
docs: add Github Actions setup
twinh Sep 28, 2020
ed5f839
chore: update requirements
twinh Sep 28, 2020
4b7b51d
style: ignore PHPMD.ExcessiveClassComplexity for JsonFile
twinh Sep 28, 2020
86fc259
test: add test for flagName
twinh Sep 28, 2020
304e3fa
test: add test for GitHub actions push tag
twinh Sep 28, 2020
fb5b943
test: add test for requireGithubActions
twinh Sep 28, 2020
8c8e6cb
chore: fix email error
twinh Sep 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/blank.yml
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, 7.4]
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 }}
extensions: 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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ In the "Configure your environment variables" section:
COVERALLS_REPO_TOKEN=your_token
```

## GitHub Actions

Add a new step after phpunit generate coverage report.

```yaml
- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/logs/clover.xml -v
```

## From local environment

If you would like to call Coveralls API from your local environment, you can set `COVERALLS_RUN_LOCALLY` environment variable. This configuration requires `repo_token` to specify which project on Coveralls your project maps to. This can be done by configuring `.coveralls.yml` or `COVERALLS_REPO_TOKEN` environment variable.
Expand Down Expand Up @@ -265,6 +278,12 @@ Coveralls provides the ability to combine coverage result from multiple parallel
COVERALLS_PARALLEL=true
```

To distinguish your job name, please set the `COVERALLS_FLAG_NAME` environment variable.

```sh
COVERALLS_FLAG_NAME=$YOUR_PHP_VERSION
```

Bear in mind that you will need to configure your build to send a webhook after all the parallel builds are done in order for Coveralls to merge the results.

Refer to [Parallel Builds Webhook](https://docs.coveralls.io/parallel-build-webhook) for more information for setup on your environment.
Expand Down
45 changes: 45 additions & 0 deletions src/Bundle/CoverallsBundle/Collector/CiEnvVarsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function collect(array $env)
->fillCircleCi()
->fillAppVeyor()
->fillJenkins()
->fillGithubActions()
->fillLocal()
->fillRepoToken()
->fillParallel();
Expand Down Expand Up @@ -113,6 +114,46 @@ 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'];
$githubRef = $this->env['GITHUB_REF'];

if (strpos($githubRef, 'refs/heads/') !== false) {
$githubRef = str_replace('refs/heads/', '', $githubRef);
} 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'];
} elseif (strpos($githubRef, 'refs/tags/') !== false) {
$githubRef = str_replace('refs/tags/', '', $githubRef);
}

// Same as coverallsapp/github-action
// @link https://github.com/coverallsapp/github-action/blob/5984097c6e76d873ef1d8e8e1836b0914d307c3c/src/run.ts#L47
$this->env['CI_JOB_ID'] = $this->env['GITHUB_RUN_ID'];
$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'];
$this->readEnv['CI_JOB_ID'] = $this->env['CI_JOB_ID'];
$this->readEnv['CI_BRANCH'] = $this->env['CI_BRANCH'];

return $this;
}

/**
* Fill CircleCI environment variables.
*
Expand Down Expand Up @@ -241,6 +282,10 @@ protected function fillParallel()
$this->readEnv['COVERALLS_PARALLEL'] = $this->env['COVERALLS_PARALLEL'];
}

if (isset($this->env['COVERALLS_FLAG_NAME'])) {
$this->readEnv['COVERALLS_FLAG_NAME'] = $this->env['COVERALLS_FLAG_NAME'];
}

return $this;
}
}
4 changes: 2 additions & 2 deletions src/Bundle/CoverallsBundle/Collector/GitInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

return $exploded[1];
return $matches[1];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public function getHelpMessage()
- APPVEYOR
- APPVEYOR_BUILD_NUMBER

For Githib Actions users:
- GITHUB_REF
- GITHUB_ACTIONS
- GITHUB_RUN_ID
- GITHUB_EVENT_NAME

From local environment:

- COVERALLS_RUN_LOCALLY
Expand Down
49 changes: 49 additions & 0 deletions src/Bundle/CoverallsBundle/Entity/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Data represents "json_file" of Coveralls API.
*
* @author Kitamura Satoshi <with.no.parachute@gmail.com>
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class JsonFile extends Coveralls
{
Expand Down Expand Up @@ -107,6 +108,14 @@ class JsonFile extends Coveralls
*/
protected $parallel;

/**
* If this is set, the job being reported will be named in the view and have
* it’s own independent status reported to your VCS provider.
*
* @var string
*/
protected $flagName;

// API

/**
Expand All @@ -129,6 +138,7 @@ public function toArray()
'service_event_type' => 'serviceEventType',
'repo_token' => 'repoToken',
'parallel' => 'parallel',
'flag_name' => 'flagName',
'git' => 'git',
'run_at' => 'runAt',
'source_files' => 'sourceFiles',
Expand Down Expand Up @@ -331,6 +341,30 @@ public function getParallel()
return $this->parallel;
}

/**
* Set flag name.
*
* @param string $flagName flag name
*
* @return $this
*/
public function setFlagName($flagName)
{
$this->flagName = $flagName;

return $this;
}

/**
* Return flag name.
*
* @return null|string
*/
public function getFlagName()
{
return $this->flagName;
}

/**
* Set service job id.
*
Expand Down Expand Up @@ -541,6 +575,7 @@ protected function fillStandardizedEnvVars(array $env)
'serviceEventType' => 'COVERALLS_EVENT_TYPE',
'repoToken' => 'COVERALLS_REPO_TOKEN',
'parallel' => 'COVERALLS_PARALLEL',
'flagName' => 'COVERALLS_FLAG_NAME',
];

foreach ($map as $propName => $envName) {
Expand Down Expand Up @@ -581,6 +616,10 @@ protected function ensureJobs()
return $this;
}

if ($this->requireGithubActions()) {
return $this;
}

if ($this->isUnsupportedServiceJob()) {
return $this;
}
Expand Down Expand Up @@ -636,6 +675,16 @@ protected function requireRepoToken()
&& $this->repoToken !== null;
}

/**
* Return whether the job requires "service_number", "service_job_id" and "repo_token" (for GithubActions).
*
* @return bool
*/
protected function requireGithubActions()
{
return $this->serviceName === 'github' && $this->serviceJobId !== null && $this->repoToken !== null;
}

/**
* Return whether the job is running on unsupported service.
*
Expand Down