Skip to content

Inject GITHUB_TOKEN in composer config when present #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
steps:
- name: ${{ matrix.name }}
uses: laminas/laminas-continuous-integration-action@v1
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
with:
job: ${{ matrix.job }}
```
Expand All @@ -61,6 +63,11 @@ jobs:
>
> The action will perform a checkout of the repository at the requested reference as part of its work, and therefore does not require the actions/checkout action as a preceding step.

> ### GITHUB_TOKEN not required
>
> While injection of the `GITHUB_TOKEN` env variable is demonstrated above, in most cases it is not necessary.
> Only add it if you start seeing rate limit issues when using Composer (e.g., when you receive a "Could not authenticate against github.com" message when installing dependencies).

### Pre/Post commands

Some packages may require additional setup steps: setting up a web server to test an HTTP client, seeding a database or cache service, etc.
Expand Down
23 changes: 15 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ function checkout {

if [[ "$REF" == "$LOCAL_BRANCH" ]];then
echo "Checking out ref ${REF}"
git checkout $REF
git checkout "$REF"
else
echo "Checking out branch ${BASE_BRANCH}"
git checkout ${BASE_BRANCH}
git checkout "${BASE_BRANCH}"
echo "Fetching ref ${REF}"
git fetch origin "${REF}":"${LOCAL_BRANCH_NAME}"
echo "Checking out target ref to ${LOCAL_BRANCH_NAME}"
Expand All @@ -91,14 +91,17 @@ function composer_install {
case $DEPS in
lowest)
echo "Installing lowest supported dependencies via Composer"
# shellcheck disable=SC2086
composer update ${COMPOSER_ARGS} --prefer-lowest
;;
latest)
echo "Installing latest supported dependencies via Composer"
# shellcheck disable=SC2086
composer update ${COMPOSER_ARGS}
;;
*)
echo "Installing dependencies as specified in lockfile via Composer"
# shellcheck disable=SC2086
composer install ${COMPOSER_ARGS}
;;
esac
Expand Down Expand Up @@ -131,9 +134,9 @@ if [[ "${PHP}" == "" ]];then
fi

echo "Marking PHP ${PHP} as configured default"
update-alternatives --quiet --set php /usr/bin/php${PHP}
update-alternatives --quiet --set php-config /usr/bin/php-config${PHP}
update-alternatives --quiet --set phpize /usr/bin/phpize${PHP}
update-alternatives --quiet --set php "/usr/bin/php${PHP}"
update-alternatives --quiet --set php-config "/usr/bin/php-config${PHP}"
update-alternatives --quiet --set phpize "/usr/bin/phpize${PHP}"

checkout

Expand All @@ -154,24 +157,28 @@ fi

if [[ "${INI}" != "" ]];then
echo "Installing php.ini settings"
echo "$INI" > /etc/php/${PHP}/cli/conf.d/99-settings.ini
echo "$INI" > "/etc/php/${PHP}/cli/conf.d/99-settings.ini"
fi

echo "PHP version: $(php --version)"
echo "Installed extensions:"
php -m

# If a token is present, tell Composer about it so we can avoid rate limits
if [[ "${GITHUB_TOKEN}" != "" ]];then
composer config --global github-oauth.github.com "${GITHUB_TOKEN}"
fi
Comment on lines +167 to +170
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the primary change to review.

composer_install "${DEPS}" "${PHP}" "${IGNORE_PLATFORM_REQS_ON_8}"

if [[ "${COMMAND}" =~ phpunit ]];then
echo "Setting up PHPUnit problem matcher"
cp /etc/laminas-ci/problem-matcher/phpunit.json $(pwd)/phpunit.json
cp /etc/laminas-ci/problem-matcher/phpunit.json "$(pwd)/phpunit.json"
echo "::add-matcher::phpunit.json"
fi

if [[ "${COMMAND}" =~ markdownlint ]];then
echo "Setting up markdownlint problem matcher"
cp /etc/laminas-ci/problem-matcher/markdownlint.json $(pwd)/markdownlint-matcher.json
cp /etc/laminas-ci/problem-matcher/markdownlint.json "$(pwd)/markdownlint-matcher.json"
echo "::add-matcher::markdownlint-matcher.json"
if [ ! -f ".markdownlint.json" ];then
echo "Installing markdownlint configuration"
Expand Down