mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
80 lines
3.1 KiB
YAML
80 lines
3.1 KiB
YAML
####
|
|
# 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
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
rector-ci:
|
|
runs-on: ubuntu-latest
|
|
if: github.event.pull_request.head.repo.full_name == github.repository
|
|
steps:
|
|
-
|
|
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
|
|
|
|
-
|
|
uses: shivammathur/setup-php@v1
|
|
with:
|
|
php-version: 7.3
|
|
coverage: none
|
|
|
|
- run: composer install --no-progress --ansi
|
|
|
|
## First run Rector
|
|
- run: composer rector
|
|
|
|
-
|
|
name: Check for Rector modified files
|
|
id: rector-git-check
|
|
run: echo ::set-output name=modified::$(if git diff --exit-code --no-patch; then echo "false"; else echo "true"; fi)
|
|
|
|
- name: Git config
|
|
if: steps.rector-git-check.outputs.modified == 'true'
|
|
run: |
|
|
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")
|
|
|
|
- name: Commit Rector changes
|
|
if: steps.rector-git-check.outputs.modified == 'true'
|
|
run: git commit -am "fixup! ${COMMIT_MESSAGE}"
|
|
|
|
## Now, there might be coding standard issues after running Rector
|
|
-
|
|
if: steps.rector-git-check.outputs.modified == 'true'
|
|
run: composer fix-cs
|
|
|
|
-
|
|
name: Check for CS modified files
|
|
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)
|
|
|
|
- name: Commit CS changes
|
|
if: steps.cs-git-check.outputs.modified == 'true'
|
|
run: git commit -am "fixup! fixup! ${COMMIT_MESSAGE}"
|
|
|
|
|
|
- name: Push changes
|
|
if: steps.rector-git-check.outputs.modified == 'true'
|
|
run: git push
|
|
# In case we want to fail this job when there are changed files, just add "exit 1"
|
|
|