forked from rectorphp/rector-src
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (114 loc) · 6.71 KB
/
build_scoped_rector.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# builds the content of https://github.com/rectorphp/rector
# inspiration from https://github.com/phpstan/phpstan-src/blob/master/.github/workflows/phar.yml
name: Build Scoped Rector
on:
push:
branches:
- main
tags:
- '*'
env:
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
COMPOSER_ROOT_VERSION: "dev-main"
jobs:
build_scoped_rector:
# Don't run on forks.
if: github.repository == 'rectorphp/rector-src'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# sometime, when 2 or more consecutive PRs merged, the checkout rectorphp/rector-src is overlapped
# and reverting other commit change
# this should not happen on create a tag, so wait first
-
name: "Wait before checkout rectorphp/rector-src on create a tag"
if: "startsWith(github.ref, 'refs/tags/')"
run: sleep 20
-
uses: actions/checkout@v4
with:
fetch-depth: 0
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
coverage: none
# fixes https://github.com/rectorphp/rector/pull/4559/checks?check_run_id=1359814403, see https://github.com/shivammathur/setup-php#composer-github-oauth
env:
COMPOSER_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# install do not use composer/ramsey github action package, it uses cache including "dev", we want to avoid it here
# this run is needed to install patches, the --no-dev skips them
- run: composer install --ansi
# to remove dev dependencies
- run: composer install --no-dev --ansi
# early downgrade individual functions
- run: bin/rector process src/functions/node_helper.php -c build/config/config-downgrade.php --ansi
# 1. copy files to $NESTED_DIRECTORY directory Exclude the scoped/nested directories to prevent rsync from copying in a loop
- run: rsync --exclude rector-build -av * rector-build --quiet
- run: rm -rf rector-build/rules-tests rector-build/tests rector-build/bin/generate-changelog.php rector-build/bin/validate-phpstan-version.php rector-build/vendor/tracy/tracy/examples rector-build/vendor/symfony/console/Tester rector-build/vendor/symfony/console/Event rector-build/vendor/symfony/console/EventListener rector-build/vendor/tracy/tracy/examples rector-build/vendor/tracy/tracy/src/Bridges rector-build/vendor/tracy/tracy/src/Tracy/Bar rector-build/vendor/tracy/tracy/src/Tracy/Session rector-build/vendor/symfony/service-contracts/Test
# 2. downgrade rector
- run: php -d memory_limit=-1 bin/rector process rector-build/bin rector-build/config rector-build/src rector-build/rules rector-build/vendor --config build/config/config-downgrade.php --ansi --no-diffs
# 3. prefix classes
- run: sh build/build-rector-scoped.sh rector-build rector-prefixed-downgraded
# 4. lint the code for PHP 7.2 - this must happen here, as setup-php allows only one PHP version switch: https://github.com/shivammathur/setup-php/issues/434
-
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
coverage: none
- run: composer global require php-parallel-lint/php-parallel-lint --ansi
- run: /home/runner/.composer/vendor/bin/parallel-lint rector-prefixed-downgraded --exclude rector-prefixed-downgraded/stubs --exclude rector-prefixed-downgraded/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded/vendor/rector/rector-generator/templates --exclude rector-prefixed-downgraded/vendor/symfony/console/Debug/CliRequest.php
# 5. copy repository meta files
- run: |
cp -R build/target-repository/. rector-prefixed-downgraded
cp -R templates rector-prefixed-downgraded/
cp CONTRIBUTING.md rector-prefixed-downgraded/
cp preload.php rector-prefixed-downgraded/
# 6. clone remote repository, so we can push it
-
uses: "actions/checkout@v4"
with:
repository: rectorphp/rector
path: remote-repository
token: ${{ secrets.ACCESS_TOKEN }}
# remove remote files, to avoid piling up dead code in remote repository
- run: rm -rf remote-repository/.github remote-repository/e2e remote-repository/docs remote-repository/config remote-repository/src remote-repository/rules remote-repository/packages remote-repository/vendor remote-repository/stubs-rector
- run: cp -a rector-prefixed-downgraded/. remote-repository
# 7. setup git
-
working-directory: remote-repository
run: |
git config user.email "[email protected]"
git config user.name "Tomas Votruba"
# commit metadata
-
name: "Get Git log"
id: git-log
run: |
echo "log<<EOF" >> $GITHUB_OUTPUT
echo "$(git log ${{ github.event.before }}..${{ github.event.after }} --reverse --pretty='https://github.com/rectorphp/rector-src/commit/%H %s')" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
# 8.A publish it to remote repository without tag
-
name: "Commit Prefixed - main"
working-directory: remote-repository
if: "!startsWith(github.ref, 'refs/tags/')"
env:
INPUT_LOG: ${{ steps.git-log.outputs.log }}
run: |
git add --all
git commit -m "Updated Rector to commit ${{ github.event.after }}" -m "$INPUT_LOG"
git push --quiet origin main
# 8.B publish it to remote repository with tag
-
name: "Commit Prefixed - tag"
working-directory: remote-repository
if: "startsWith(github.ref, 'refs/tags/')"
env:
INPUT_LOG: ${{ steps.git-log.outputs.log }}
run: |
git add --all
git commit -m "Rector ${GITHUB_REF#refs/tags/}" -m "$INPUT_LOG"
git push --quiet origin main
git tag ${GITHUB_REF#refs/tags/} -m "${GITHUB_REF#refs/tags/}"
git push --quiet origin ${GITHUB_REF#refs/tags/}