2020-03-12 22:27:37 +01:00
####
# Due to some Github Actions limitations, we are running realtime fixes (commits) only for self-owned-pr
#
# Current limitations:
# - Secrets (ACCESS_TOKEN) are not available in PRs from forks
# - Github Token has Read-only access (can not commit), Personal Access Token must be used instead
# - Github Token does not trigger workflows after push
#
# So we basically have chicken-egg problem here
#
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token
####
2020-01-22 01:07:32 +01:00
name : Rector CI
on :
pull_request : null
jobs :
rector-ci :
2020-10-19 16:37:35 +02:00
strategy :
fail-fast : false
matrix :
directories :
- packages
- rules
- src
- tests
2020-01-22 01:07:32 +01:00
runs-on : ubuntu-latest
2020-03-12 22:27:37 +01:00
if : github.event.pull_request.head.repo.full_name == github.repository
2020-01-22 01:07:32 +01:00
steps :
2020-03-11 22:31:16 +01:00
-
uses : actions/checkout@v2
with :
2020-03-12 22:27:37 +01:00
ref : ${{ github.event.pull_request.head.ref }} # Solves the not "You are not currently on a branch" problem, see https://github.com/actions/checkout/issues/124#issuecomment-586664611
token : ${{ secrets.ACCESS_TOKEN }} # Must be used to trigger workflow after push
2020-03-11 22:31:16 +01:00
2020-01-22 01:07:32 +01:00
-
uses : shivammathur/setup-php@v1
with :
2020-09-01 19:56:30 +02:00
# PHP 7.2 is required, so Rector's code is PHP 7.2 compatible even after refactoring
php-version : 7.2
2020-01-22 01:07:32 +01:00
coverage : none
2020-10-25 14:49:56 +01:00
tools : composer:v1
2020-03-11 22:31:16 +01:00
2020-05-02 11:47:43 +02:00
- run : composer install --no-progress --ansi
2020-03-19 11:35:49 +01:00
2020-09-23 13:29:42 +02:00
## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anyhting in the future
2020-10-19 16:37:35 +02:00
- run : bin/rector process ${{ matrix.directories }} --config rector-ci.php --ansi --no-progress-bar
2020-03-11 21:59:06 +01:00
-
2020-03-19 11:35:49 +01:00
name : Check for Rector modified files
2020-03-19 12:35:33 +01:00
id : rector-git-check
run : echo ::set-output name=modified::$(if git diff --exit-code --no-patch; then echo "false"; else echo "true"; fi)
2020-03-11 21:59:06 +01:00
2020-03-19 11:35:49 +01:00
- name : Git config
2020-03-19 12:35:33 +01:00
if : steps.rector-git-check.outputs.modified == 'true'
2020-03-11 21:59:06 +01:00
run : |
2020-03-12 21:11:38 +01:00
git config --global user.name 'rector-bot'
git config --global user.email 'tomas@getrector.org'
2020-04-04 00:13:24 +02:00
echo ::set-env name=COMMIT_MESSAGE::$(git log -1 --pretty=format:"%s")
2020-03-19 11:35:49 +01:00
- name : Commit Rector changes
2020-03-19 12:35:33 +01:00
if : steps.rector-git-check.outputs.modified == 'true'
2020-08-01 01:39:40 +02:00
run : git commit -am "[rector] ${COMMIT_MESSAGE}"
2020-03-19 11:35:49 +01:00
## Now, there might be coding standard issues after running Rector
-
2020-03-19 12:35:33 +01:00
if : steps.rector-git-check.outputs.modified == 'true'
2020-03-19 11:35:49 +01:00
run : composer fix-cs
-
name : Check for CS modified files
2020-03-19 12:35:33 +01:00
if : steps.rector-git-check.outputs.modified == 'true'
id : cs-git-check
run : echo ::set-output name=modified::$(if git diff --exit-code --no-patch; then echo "false"; else echo "true"; fi)
2020-03-19 11:35:49 +01:00
- name : Commit CS changes
2020-03-19 12:35:33 +01:00
if : steps.cs-git-check.outputs.modified == 'true'
2020-08-01 01:39:40 +02:00
run : git commit -am "[cs] ${COMMIT_MESSAGE}"
2020-03-19 11:35:49 +01:00
- name : Push changes
2020-03-19 12:35:33 +01:00
if : steps.rector-git-check.outputs.modified == 'true'
2020-03-19 11:35:49 +01:00
run : git push
2020-03-12 22:27:37 +01:00
# In case we want to fail this job when there are changed files, just add "exit 1"