Skip to content

Commit caa8524

Browse files
authored
Merge branch 'v3' into patch-2
2 parents 3f62848 + 2da6381 commit caa8524

18 files changed

+413
-30
lines changed

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ When you do begin working on your feature, here are some guidelines to consider:
8181
* **Submit one feature per pull request.** If you have multiple features you
8282
wish to submit, please break them into separate pull requests.
8383
* **Write good commit messages.** This project follows the
84-
[Conventional Commits][] specification and uses Git hooks to ensure all
84+
[Conventional Commits][conv-commit] specification and uses Git hooks to ensure all
8585
commits follow this standard. Running `composer install` will set up the Git
8686
hooks, so when you run `git commit`, you'll be prompted to create a commit
8787
using the Conventional Commits rules.
@@ -117,3 +117,4 @@ composer test
117117
[issues]: https://github.com/ramsey/composer-install/issues
118118
[pull requests]: https://github.com/ramsey/composer-install/pulls
119119
[gh-flow]: https://guides.github.com/introduction/flow/
120+
[conv-commit]: https://www.conventionalcommits.org/

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ For example:
8585
composer-options: "--ignore-platform-reqs --optimize-autoloader"
8686
```
8787

88+
#### composer-filename
89+
90+
If you have a custom Composer filename, you may use `composer-filename` to change
91+
the filename Composer uses. For example, your Composer file could be
92+
`composer-gh-actions.json` or `composer-staging.json` instead of the default
93+
`composer.json`.
94+
95+
You should specify the filename without the extension, since it will determine
96+
both the JSON and lock filenames to use. The default value is `"composer"`,
97+
which will use `composer.json` and `composer.lock` as the filenames.
98+
99+
For example:
100+
101+
```yaml
102+
- uses: "ramsey/composer-install@v3"
103+
with:
104+
custom-composer-filename: "composer-gh-actions"
105+
```
106+
88107
#### working-directory
89108

90109
The `working-directory` input parameter allows you to specify a different
@@ -120,6 +139,8 @@ For example:
120139

121140
#### ignore-cache
122141

142+
Normally, ramsey/composer-install preserves composer's cache between jobs
143+
so that subsequent identically-invoked jobs execute faster.
123144
If you have jobs for which you wish to completely ignore the caching step, you
124145
may use the `ignore-cache` input parameter. When present, ramsey/composer-install
125146
will neither read from nor write to the cache.
@@ -175,6 +196,17 @@ even more specific, you can specify a suffix to be added to the cache key via th
175196
> [!WARNING]
176197
> Specifying a `custom-cache-key` will take precedence over the `custom-cache-suffix`.
177198

199+
200+
#### require-lock-file
201+
202+
By default, if no composer.lock file is found in the working directory
203+
ramsey/composer-install will invoke `composer update` regardless of the value of
204+
`dependency-versions`.
205+
206+
If this is set to a value of `true`, ramsey/composer-install will fail in its
207+
execution if it does not find a lock file.
208+
209+
178210
### Fork and private repositories
179211

180212
Sometimes it's needed to use the `repositories` key in your `composer.json` to pull in forks, PRs with patches or private repositories. In this case, your GitHub Action may start failing with a `Could not authenticate against github.com` error message. To solve this, you need to use an authorized token; luckily [GHA provides you with one automatically at each run](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication), you just need to set the `repository-projects` permission to `read`:

action.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ inputs:
3939
Require lock file for install command.
4040
required: false
4141
default: "false"
42+
composer-filename:
43+
description: >-
44+
The Composer filename to use, without the extension (e.g. `composer`,
45+
`composer-gh-actions`, `composer-staging`). Please note: this is not a
46+
path. If you need to specify a different path, use `working-directory`.
47+
required: false
48+
default: "composer"
4249

4350
runs:
4451
using: "composite"
@@ -51,17 +58,17 @@ runs:
5158
- name: "Determine whether we should ignore caching"
5259
id: "should-cache"
5360
shell: "bash"
54-
run: "${GITHUB_ACTION_PATH}/bin/should_cache.sh \"${{ inputs.ignore-cache }}\""
61+
run: '${GITHUB_ACTION_PATH}/bin/should_cache.sh "${{ inputs.ignore-cache }}"'
5562

5663
- name: "Determine Composer paths"
5764
id: "composer"
58-
if: steps.should-cache.outputs.do-cache == 1
5965
shell: "bash"
6066
run: |
6167
${GITHUB_ACTION_PATH}/bin/composer_paths.sh \
6268
"" \
6369
"${{ inputs.working-directory }}" \
64-
"${{ steps.php.outputs.path }}"
70+
"${{ steps.php.outputs.path }}" \
71+
"${{ inputs.composer-filename }}"
6572
6673
- name: "Determine cache key"
6774
id: "cache-key"
@@ -73,7 +80,7 @@ runs:
7380
"${{ steps.php.outputs.version }}" \
7481
"${{ inputs.dependency-versions }}" \
7582
"${{ inputs.composer-options }}" \
76-
"${{ hashFiles('**/composer.json', '**/composer.lock') }}" \
83+
"${{ hashFiles('**/${{ inputs.composer-filename }}.json', '**/${{ inputs.composer-filename }}.lock') }}" \
7784
"${{ inputs.custom-cache-key }}" \
7885
"${{ inputs.custom-cache-suffix }}" \
7986
"${{ inputs.working-directory }}"
@@ -97,4 +104,5 @@ runs:
97104
"${{ steps.php.outputs.path }}" \
98105
"${{ steps.composer.outputs.composer_command }}" \
99106
"${{ steps.composer.outputs.lock }}" \
100-
"${{ inputs.require-lock-file }}"
107+
"${{ inputs.require-lock-file }}" \
108+
"${{ inputs.composer-filename }}" \

bin/composer_install.sh

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ php_path="${4:-$(which php)}"
77
composer_path="${5:-$(which composer)}"
88
composer_lock="${6:-}"
99
require_lock_file="${7:-}"
10+
composer_filename="${8:-composer}"
1011

1112
composer_command="update"
1213
composer_options=("--no-interaction" "--no-progress" "--ansi")
@@ -33,6 +34,10 @@ if [ -n "${working_directory}" ]; then
3334
composer_options+=("--working-dir" "${working_directory}")
3435
fi
3536

37+
COMPOSER="${composer_filename}.json"
38+
export COMPOSER
39+
3640
full_command="${php_path} ${composer_path} ${composer_command} ${composer_options[*]}"
3741
echo "::debug::Using the following Composer command: '${full_command}'"
42+
echo "::debug::The COMPOSER environment variable is '${COMPOSER}'"
3843
$full_command

bin/composer_paths.sh

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@
33
composer_path="${1:-$(which composer)}"
44
working_directory="${2:-.}"
55
php_path="${3:-$(which php)}"
6+
composer_filename="${4:-composer}"
67

78
function test_composer {
89
"${php_path}" "${composer_path}" --version > /dev/null 2>&1
910
}
1011

1112
function validate_composer {
12-
"${php_path}" "${composer_path}" validate --no-check-publish --no-check-lock --working-dir "${working_directory}" > /dev/null 2>&1
13+
"${php_path}" "${composer_path}" validate --no-check-publish --no-check-lock --working-dir "${working_directory}" > /dev/null 2>&1
1314
}
1415

1516
if ! test_composer; then
1617
echo "::error title=Composer Not Found::Unable to find Composer at '${composer_path}'"
1718
exit 1
1819
fi
1920

20-
composer_json="composer.json"
21-
composer_lock="composer.lock"
21+
composer_json="${composer_filename}.json"
22+
composer_lock="${composer_filename}.lock"
23+
24+
COMPOSER="${composer_json}"
25+
export COMPOSER
2226

2327
if [ -n "${working_directory}" ]; then
2428
if [ ! -d "${working_directory}" ]; then
2529
echo "::error title=Working Directory Not Found::Unable to find working directory at '${working_directory}'"
2630
exit 1
2731
fi
2832

29-
composer_json="${working_directory}/composer.json"
30-
composer_lock="${working_directory}/composer.lock"
33+
composer_json="${working_directory}/${composer_json}"
34+
composer_lock="${working_directory}/${composer_lock}"
3135
fi
3236

3337
if [ ! -f "${composer_json}" ]; then
@@ -45,14 +49,15 @@ if [ ! -f "${composer_lock}" ]; then
4549
composer_lock=""
4650
fi
4751

48-
composer_version="$($composer_path --version)"
52+
composer_version="$($composer_path --version 2>/dev/null)"
4953
cache_dir="$($composer_path --working-dir="${working_directory}" config cache-dir)"
5054

5155
echo "::debug::Composer path is '${composer_path}'"
5256
echo "::debug::${composer_version}"
5357
echo "::debug::Composer cache directory found at '${cache_dir}'"
5458
echo "::debug::File composer.json found at '${composer_json}'"
5559
echo "::debug::File composer.lock path computed as '${composer_lock}'"
60+
echo "::debug::The COMPOSER environment variable is '${COMPOSER}'"
5661
{
5762
echo "composer_command=${composer_path}"
5863
echo "cache-dir=${cache_dir}"

tests/composer_install.bats

+30-10
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ teardown() {
2424
'' \
2525
'' \
2626
'' \
27-
'composer.lock'
27+
'composer.lock' \
28+
''
2829

2930
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer install --no-interaction --no-progress --ansi'$"
31+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
3032
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
3133
assert_line --partial 'Verifying lock file contents can be installed on current platform'
3234
assert_line --partial 'Generating autoload files'
@@ -43,9 +45,11 @@ teardown() {
4345
'' \
4446
'' \
4547
'' \
46-
'composer.lock'
48+
'composer.lock' \
49+
''
4750

4851
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable'$"
52+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
4953
assert_line --partial 'Updating dependencies'
5054
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
5155
assert_line --partial 'Generating autoload files'
@@ -62,9 +66,11 @@ teardown() {
6266
'' \
6367
'' \
6468
'' \
65-
'composer.lock'
69+
'composer.lock' \
70+
''
6671

6772
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer update --no-interaction --no-progress --ansi'$"
73+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
6874
assert_line --partial 'Updating dependencies'
6975
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
7076
assert_line --partial 'Generating autoload files'
@@ -81,9 +87,11 @@ teardown() {
8187
'' \
8288
'' \
8389
'' \
84-
'composer.lock'
90+
'composer.lock' \
91+
''
8592

8693
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer install --no-interaction --no-progress --ansi'$"
94+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
8795
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
8896
assert_line --partial 'Verifying lock file contents can be installed on current platform'
8997
assert_line --partial 'Generating autoload files'
@@ -100,9 +108,11 @@ teardown() {
100108
'' \
101109
'' \
102110
'' \
103-
'composer.lock'
111+
'composer.lock' \
112+
''
104113

105114
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer install --no-interaction --no-progress --ansi'$"
115+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
106116
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
107117
assert_line --partial 'Verifying lock file contents can be installed on current platform'
108118
assert_line --partial 'Generating autoload files'
@@ -119,9 +129,11 @@ teardown() {
119129
'' \
120130
'' \
121131
'' \
122-
'composer.lock'
132+
'composer.lock' \
133+
''
123134

124135
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'$"
136+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
125137
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
126138
assert_line --partial 'Verifying lock file contents can be installed on current platform'
127139
assert_line --partial 'Generating optimized autoload files'
@@ -138,9 +150,11 @@ teardown() {
138150
'' \
139151
'' \
140152
'' \
141-
'composer.lock'
153+
'composer.lock' \
154+
''
142155

143156
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable --ignore-platform-reqs --optimize-autoloader'$"
157+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
144158
assert_line --partial 'Updating dependencies'
145159
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
146160
assert_line --partial 'Generating optimized autoload files'
@@ -157,9 +171,11 @@ teardown() {
157171
'' \
158172
'' \
159173
'' \
160-
'composer.lock'
174+
'composer.lock' \
175+
''
161176

162177
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer update --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'$"
178+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
163179
assert_line --partial 'Updating dependencies'
164180
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
165181
assert_line --partial 'Generating optimized autoload files'
@@ -176,9 +192,11 @@ teardown() {
176192
'' \
177193
'' \
178194
'' \
179-
'composer.lock'
195+
'composer.lock' \
196+
''
180197

181198
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'$"
199+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
182200
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
183201
assert_line --partial 'Verifying lock file contents can be installed on current platform'
184202
assert_line --partial 'Generating optimized autoload files'
@@ -195,9 +213,11 @@ teardown() {
195213
'' \
196214
'' \
197215
"$PROJECT_ROOT/tests/fixtures/composer.phar" \
198-
'composer.lock'
216+
'composer.lock' \
217+
''
199218

200219
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer\.phar install --no-interaction --no-progress --ansi'$"
220+
assert_line "::debug::The COMPOSER environment variable is 'composer.json'"
201221
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
202222
assert_line --partial 'Verifying lock file contents can be installed on current platform'
203223
assert_line --partial 'Generating autoload files'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bats
2+
3+
setup() {
4+
load 'test_helper/common_setup'
5+
_common_setup
6+
7+
cd "$PROJECT_ROOT/tests/fixtures/custom-composer" || exit 1
8+
}
9+
10+
teardown() {
11+
if [ -d vendor ]; then
12+
rm -rf vendor
13+
fi
14+
15+
git restore composer-gh-actions.lock
16+
17+
cd ../.. || exit 1
18+
}
19+
20+
@test 'installs dependencies using custom composer file and lock file' {
21+
run -0 composer_install.sh \
22+
'' \
23+
'' \
24+
'' \
25+
'' \
26+
'' \
27+
'composer-gh-actions.lock' \
28+
'' \
29+
'composer-gh-actions'
30+
31+
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer install --no-interaction --no-progress --ansi'$"
32+
assert_line "::debug::The COMPOSER environment variable is 'composer-gh-actions.json'"
33+
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
34+
assert_line --partial 'Verifying lock file contents can be installed on current platform'
35+
assert_line --partial 'Generating autoload files'
36+
37+
refute_line --partial 'Updating dependencies'
38+
39+
assert_dir_exists "$PROJECT_ROOT/tests/fixtures/custom-composer/vendor"
40+
}
41+
42+
@test 'installs dependencies using custom composer file without lock file' {
43+
run -0 composer_install.sh \
44+
'' \
45+
'' \
46+
'' \
47+
'' \
48+
'' \
49+
'' \
50+
'' \
51+
'composer-gh-actions'
52+
53+
assert_line --index 0 --regexp "^::debug::Using the following Composer command: '.*/php .*/composer update --no-interaction --no-progress --ansi'$"
54+
assert_line "::debug::The COMPOSER environment variable is 'composer-gh-actions.json'"
55+
assert_line --partial 'Updating dependencies'
56+
assert_line --partial 'Installing dependencies from lock file (including require-dev)'
57+
assert_line --partial 'Generating autoload files'
58+
59+
refute_line --partial 'Verifying lock file contents can be installed on current platform'
60+
61+
assert_dir_exists "$PROJECT_ROOT/tests/fixtures/custom-composer/vendor"
62+
}

0 commit comments

Comments
 (0)