@@ -36,7 +36,7 @@ PROJECT_ID="$INPUT_PROJECT_ID"
3636GITHUB_ACCESS_TOKEN="$INPUT_GH_PERSONAL_ACCESS_TOKEN "
3737OUT
3838
39- initGitRepoForTargetDir () {
39+ initTargetDirGitRepo () {
4040 rsync -avq " $sourceDirPath /.git" " $targetDirPath "
4141
4242 pushd " $targetDirPath " > /dev/null
@@ -68,29 +68,43 @@ copyFilesFromSourceDirToTargetDir() {
6868 # --exclude=node_modules/ \
6969}
7070
71- # $dirPath: Directory path with composer.json file.
7271initComposerPackages () {
7372 pushd " $1 " > /dev/null
7473 composer update --no-dev --no-interaction
7574 composer dump-autoload --classmap-authoritative --no-interaction
7675 popd > /dev/null
7776}
7877
79- initGitRepoForTargetDir
78+ prepareTheTargetDir () {
79+ pushd " $targetDirPath " > /dev/null
80+
81+ # Remove the source composer.json, composer.lock, vendor, and vendor_prefixed to avoid collisions when receiving the prefixed results
82+ find " $targetDirPath " \( \( -name composer.json -o -name composer.lock \) -type f \) -print0 | xargs -0 rm -rf
83+ find " $targetDirPath " \( \( -name vendor -o -name vendor_prefixed \) -type d \) -print0 | xargs -0 rm -rf
84+ }
85+
86+ # Create the target directory where the prefixed results will be stored
87+ initTargetDirGitRepo
88+
89+ # Composer update & dump-autoload to check everything is Ok
8090initComposerPackages " $sourceDirPath "
91+
92+ # Copy everything from source to target to have the complete project on the target directory
8193copyFilesFromSourceDirToTargetDir
82- initComposerPackages " $targetDirPath "
8394
84- pushd " $targetDirPath " > /dev/null
95+ # Composer update & dump-autoload to check everything is Ok
96+ initComposerPackages " $targetDirPath "
8597
86- find " $targetDirPath " \( \( -name composer.json -o -name composer.lock \) -type f \) -print0 | xargs -0 rm -rf
87- find " $targetDirPath " \( \( -name vendor -o -name vendor_prefixed \) -type d \) -print0 | xargs -0 rm -rf
98+ # Clean the composer-related files from target directory before prefixing
99+ prepareTheTargetDir
88100
101+ # Let's go!
89102/php-prefixer-cli.phar prefix --delete-build
90103
91104CHANGED=$( git status --porcelain)
92105
93106if [ -n " ${CHANGED} " ]; then
107+ # If there're changes, commit them
94108 git add --all .
95109 git commit --all -m " Publish prefixed build $( date ' +%Y-%m-%d %H:%M:%S' ) "
96110 git pull -s ours $remote " $INPUT_TARGET_BRANCH " || true # remote may not exist
0 commit comments