-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache phar for each PHP version and channel
- Loading branch information
1 parent
72c0d09
commit 5b3f81b
Showing
2 changed files
with
99 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env bash | ||
|
||
check_phar() { | ||
phar=$1 | ||
echo "Checking $phar" | ||
php -r "try {\$p=new Phar('$phar', 0);exit(0);} catch(Exception \$e) {exit(1);}" | ||
if [ $? -eq 1 ]; then | ||
echo "ERROR: Broken $phar found" | ||
exit 1 | ||
else | ||
php "$phar" -V | ||
fi | ||
} | ||
|
||
fetch_phar_for_php_version() { | ||
php_version=$1 | ||
channel=$2 | ||
installer=$3 | ||
php_version_semver="$php_version.99" | ||
php_version_id=$(echo "${php_version_semver}" | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 100 + $2) * 100 + $3;}') | ||
cp -f "$installer" "$installer-${php_version}" | ||
sed -i -e "s/PHP_VERSION_ID/'$php_version_id'/g" -e "s/PHP_VERSION/'$php_version_semver'/g" "$installer-${php_version}" | ||
php "$installer-${php_version}" --"${channel}" --install-dir="$(pwd)" --filename=composer-"${php_version}"-"${channel}".phar | ||
check_phar composer-"${php_version}"-"${channel}".phar | ||
} | ||
|
||
fetch_installer() { | ||
installer=$1 | ||
EXPECTED_CHECKSUM="$(curl -sL https://composer.github.io/installer.sig)" | ||
curl -o "$installer" -sL https://getcomposer.org/installer | ||
ACTUAL_CHECKSUM="$(openssl dgst -sha384 "$installer" | cut -d ' ' -f 2)" | ||
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then | ||
echo 'ERROR: Invalid installer checksum' | ||
exit 1 | ||
fi | ||
} | ||
|
||
update_release() { | ||
release=$1 | ||
release_notes_file=$2 | ||
assets=() | ||
for asset in ./*.phar; do | ||
assets+=("$asset") | ||
done | ||
assets+=("$release_notes_file") | ||
echo "${assets[@]}" | ||
if ! gh release view "$release"; then | ||
gh release create "$release" "${assets[@]}" -t "$release" -F "$release_notes_file" | ||
else | ||
gh release upload "$release" "${assets[@]}" --clobber | ||
endpoint="$(gh api repos/"$GITHUB_REPOSITORY"/releases/tags/"$release" -H Accept:application/vnd.github.v3+json | jq -r '.url')" | ||
gh api "$endpoint" -H Accept:application/vnd.github.v3+json -H Content-Type:application/json -X PATCH -f body="$(cat "$release_notes_file")" --silent | ||
fi | ||
} | ||
|
||
check_manifest() { | ||
manifest_file=$1 | ||
release=$2 | ||
curl -o "$manifest_file" -sSL https://getcomposer.org/versions | ||
release_versions="$(curl -sSL https://github.com/"$GITHUB_REPOSITORY"/releases/latest/download/"$release")" | ||
if [ "$FORCE" != 'true' ] && [ "$(cat "$manifest_file")" = "$release_versions" ]; then | ||
echo "No new releases" | ||
exit 0 | ||
fi | ||
} | ||
|
||
channels=(stable preview snapshot 1 2) | ||
php_versions=(5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2) | ||
release=versions | ||
manifest_file=versions | ||
installer=installer | ||
|
||
|
||
check_manifest "$manifest_file" "$release" | ||
|
||
for channel in "${channels[@]}"; do | ||
curl -o composer-"$channel".phar -sSL https://getcomposer.org"$(jq -r ".\"$channel\"[].path" "$manifest_file" | head -n 1)" | ||
check_phar composer-"$channel".phar | ||
|
||
fetch_installer "$installer" | ||
for php_version in "${php_versions[@]}"; do | ||
fetch_phar_for_php_version "$php_version" "$channel" "$installer" | ||
done | ||
done | ||
|
||
update_release "$release" "$manifest_file" |