Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions update.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
#!/bin/bash
#
# Update repository from the latest release of php-stubs/wordpress-stubs
#

current_version=$(curl https://api.github.com/repos/snicco/php-scoper-wordpress-excludes/tags -s | jq -r .[].name | grep '^[0-9]\.[0-9]*\.[0-9]*$' | sort -nr | head -n1)
echo "Current version: $current_version"

tmp_version=$(curl https://api.github.com/repos/php-stubs/wordpress-stubs/tags -s | jq -r .[].name | grep '^v[0-9]\.[0-9]*\.[0-9]*$' | sort -nr | head -n1)
lastest_version=$(echo "$tmp_version" | cut -c 2-)
echo "Latest WordPress version: $lastest_version"

if dpkg --compare-versions "$lastest_version" gt "$current_version";
then
rm -rf generated/
mkdir generated
composer require php-stubs/wordpress-stubs:"$lastest_version" --dev
composer update php-stubs/wordpress-stubs
composer install
vendor/bin/generate-excludes --json --exclude-empty
mv generated/exclude-wordpress-globals-constants.json generated/exclude-wordpress-constants.json
git add -A
git commit -a -m "Automatic release for WordPress: $lastest_version"
git push
git tag "$lastest_version" HEAD
git push --tags
echo "Tagged new version:" "$lastest_version"
exit 0
else
current_version="$(composer show --available --format=json snicco/php-scoper-wordpress-excludes | jq -r '."versions" | first(.[] | select(test("^v?\\d+\\.\\d+\\.\\d+$"))) | ltrimstr("v")')"
echo "Current version: ${current_version}"

php_stubs_latest_version="$(composer show --available --format=json php-stubs/wordpress-stubs | jq -r '."versions" | first(.[] | select(test("^v?\\d+\\.\\d+\\.\\d+$"))) | ltrimstr("v")')"
echo "Latest WordPress version: ${php_stubs_latest_version}"

if dpkg --compare-versions "${php_stubs_latest_version}" le "${current_version}"; then
echo "Everything is up-to-date!"
exit 1
exit 1
fi

rm -rf generated/
mkdir generated
composer require --dev --no-update "php-stubs/wordpress-stubs:${php_stubs_latest_version}"
composer update php-stubs/wordpress-stubs

vendor/bin/generate-excludes --json --exclude-empty
mv generated/exclude-wordpress-globals-constants.json generated/exclude-wordpress-constants.json

if git diff --quiet; then
echo "No content change!"
exit 2
fi

git add -A
git commit -a -m "Automatic release for WordPress: ${php_stubs_latest_version}"
git tag "${php_stubs_latest_version}" HEAD
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git tag "${php_stubs_latest_version}" HEAD
git tag "v${php_stubs_latest_version}" HEAD

Here goes v as "version".

git push
git push --tags

echo "Tagged new version: ${php_stubs_latest_version}"