rector/.github/workflows/rector_ci.yaml

87 lines
3.5 KiB
YAML
Raw Normal View History

####
# 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
####
name: Rector CI
on:
pull_request: null
jobs:
rector-ci:
strategy:
fail-fast: false
matrix:
directories:
- packages
- rules
- src
- tests
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
2020-03-11 22:31:16 +01:00
-
uses: actions/checkout@v2
with:
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
-
uses: shivammathur/setup-php@v1
with:
# PHP 7.2 is required, so Rector's code is PHP 7.2 compatible even after refactoring
php-version: 7.2
coverage: none
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
## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anyhting in the future
- 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'
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'
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'
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
# In case we want to fail this job when there are changed files, just add "exit 1"