Skip to content

Commit 726dcd6

Browse files
author
Greg Bowler
committed
Merge branch 'master' of github.com:/php-actions/composer
2 parents bbf0c83 + f1ef0c3 commit 726dcd6

File tree

3 files changed

+62
-36
lines changed

3 files changed

+62
-36
lines changed

README.md

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v3
2828
- uses: php-actions/composer@v6
2929
# ... then your own project steps ...
3030
```
@@ -67,7 +67,7 @@ Any arbitrary arguments can be passed to composer by using the `args` input, how
6767
+ `args` - Optional arguments to pass - no constraints (default _empty_)
6868
+ `only_args` - Only run the desired command with this args. Ignoring all other provided arguments(default _empty_)
6969
+ `php_version` - Choose which version of PHP you want to use (7.1, 7.2, 7.3, 7.4 or 8.0)
70-
+ `version` - Choose which version of Composer you want to use (1 or 2)
70+
+ `version` - Choose which version of Composer you want to use (1.x, 2.x, 2.2.x, latest)
7171
+ `memory_limit` - Sets the composer memory limit - (default _empty_)
7272

7373
There are also SSH input available: `ssh_key`, `ssh_key_pub` and `ssh_domain` that are used for depending on private repositories. See below for more information on usage.
@@ -94,8 +94,10 @@ This action runs on a custom base image, available at https://github.com/php-act
9494

9595
Use the following inputs to run a specific PHP/Composer version combination:
9696

97-
+ `php_version` Available versions: `7.1`, `7.2`, `7.3`, `7.4`, `8.0` (default: `latest` aka: `8.0`)
98-
+ `version` Available versions: `1`, `2` (default: `latest` aka: `2`)
97+
+ `php_version` Available versions: `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1` (default: `latest` aka: `8.1`)
98+
+ `version` Available versions: `latest`, `preview`, `snapshot`, `1.x`, `2.x`, `2.2.x` or the exact version (default: `latest`)
99+
100+
Make sure to put the PHP version number in quotes, otherwise YAML will interpret e.g. `8.0` as `8` which means latest 8.x, not 8.0.
99101

100102
Example configuration that runs Composer version 1 on PHP version 7.1:
101103
```yaml
@@ -107,7 +109,7 @@ jobs:
107109
- name: Install dependencies
108110
uses: php-actions/composer@v6
109111
with:
110-
php_version: 7.1
112+
php_version: "7.1"
111113
version: 1
112114
```
113115

@@ -128,9 +130,9 @@ jobs:
128130
- name: Install dependencies
129131
uses: php-actions/composer@v6
130132
with:
131-
php_version: 7.4
133+
php_version: "7.4"
132134
php_extensions: redis exif
133-
version: 2
135+
version: 2.x
134136
```
135137

136138
Caching dependencies for faster builds
@@ -150,10 +152,10 @@ jobs:
150152
runs-on: [ubuntu-latest]
151153
152154
steps:
153-
- uses: actions/checkout@v2
155+
- uses: actions/checkout@v3
154156
155157
- name: Cache Composer dependencies
156-
uses: actions/cache@v2
158+
uses: actions/cache@v3
157159
with:
158160
path: /tmp/composer-cache
159161
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
@@ -170,7 +172,7 @@ Installing private repositories
170172

171173
To install from a private repository, SSH authentication must be used. Generate an SSH key pair for this purpose and add it to your private repository's configuration, preferable with only read-only privileges. On Github for instance, this can be done by using [deploy keys][deploy-keys].
172174

173-
Add the key pair to your project using [Github Secrets][secrets], and pass them into the `php-actions/composer` action by using the `ssh_key` and `ssh_key_pub` inputs. If your private repository is stored on another server than github.com, you also need to pass the domain via `ssh_domain`.
175+
Add the key pair to your project using [Github Secrets][secrets], and pass them into the `php-actions/composer` action by using the `ssh_key` and `ssh_key_pub` inputs. If your private repository is stored on another server than github.com, you also need to pass the domain via `ssh_domain`. If the private repository is configured to use a non-standard SSH port, you can configure this by passing `ssh_port`.
174176

175177
Example yaml, showing how to pass secrets:
176178

@@ -195,38 +197,23 @@ It's recommended to use SSH keys for authentication, but sometimes HTTP basic au
195197

196198
1) Create a [personal access token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) for the Github account you wish to authenticate with.
197199

198-
2) Add the following JSON to a new Github Secret called `COMPOSER_AUTH_JSON`:
199-
200-
```json
201-
{
202-
"http-basic": {
203-
"github.com": {
204-
"username": "<YOUR_GITHUB_USERNAME>",
205-
"password": "<YOUR_PERSONAL_ACCESS_TOKEN>"
206-
}
207-
}
208-
}
209-
```
200+
2) Create a new GitHub Secret called `PAT` with a value of personal access token.
210201

211-
3) Pass this secret to auth.json as a separate action step within your Yaml config, and remove auth.json to prevent deploying it:
202+
3) Pass this secret to COMPOSER_AUTH variable:
212203

213204
```yaml
214205
jobs:
215206
build:
216207
217208
...
218-
219-
- name: Add HTTP basic auth credentials
220-
run: echo '${{ secrets.COMPOSER_AUTH_JSON }}' > $GITHUB_WORKSPACE/auth.json
221209
222210
- name: Install dependencies
223211
uses: php-actions/composer@v6
224-
225-
- name: Remove auth.json file
226-
run: rm -f $GITHUB_WORKSPACE/auth.json
212+
env:
213+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT }}"} }'
227214
```
228215

229-
4) Now, any connections Composer makes to Github.com will use your HTTP basic auth credentials, which is essentially the same as being logged in as you, so your private repositories will now be available to Composer.
216+
4) Now, any connections Composer makes to GitHub.com will use your HTTP basic auth credentials, which is essentially the same as being logged in as you, so your private repositories will now be available to Composer.
230217

231218
***
232219

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ inputs:
6161
description: "The domain to gather SSH public keys for (automatic for github.com, gitlab.com, bitbucket.org)"
6262
required: false
6363

64+
ssh_port:
65+
description: Custom port to use in conjunction with ssh_domain
66+
required: false
67+
6468
working_dir:
6569
description: "Use the given directory as working directory"
6670
required: false
@@ -92,6 +96,7 @@ runs:
9296
ACTION_SSH_KEY: ${{ inputs.ssh_key }}
9397
ACTION_SSH_KEY_PUB: ${{ inputs.ssh_key_pub }}
9498
ACTION_SSH_DOMAIN: ${{ inputs.ssh_domain }}
99+
ACTION_SSH_PORT: ${{ inputs.ssh_port }}
95100
ACTION_WORKING_DIR: ${{ inputs.working_dir }}
96101
ACTION_MEMORY_LIMIT: ${{ inputs.memory_limit }}
97102
id: composer_run

composer-action.bash

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,41 @@ github_action_path=$(dirname "$0")
44
docker_tag=$(cat ./docker_tag)
55
echo "Docker tag: $docker_tag" >> output.log 2>&1
66

7-
phar_url="https://getcomposer.org"
8-
if [ "$ACTION_VERSION" == "latest" ]
7+
phar_url="https://getcomposer.org/"
8+
# check if $ACTION_VERSION is not set or empty or set to latest
9+
if [ -z "$ACTION_VERSION" ] || [ "$ACTION_VERSION" == "latest" ];
910
then
10-
phar_url="${phar_url}/composer-stable.phar"
11+
# if a version is not set, use latest composer version
12+
phar_url="${phar_url}download/latest-stable/composer.phar"
1113
else
12-
phar_url="${phar_url}/composer-${ACTION_VERSION}.phar"
14+
# if a version is set, choose the correct download
15+
case "$ACTION_VERSION" in
16+
# get the latest preview
17+
Preview | preview)
18+
phar_url="${phar_url}download/latest-preview/composer.phar"
19+
;;
20+
# get the latest snapshot
21+
Snapshot | snapshot)
22+
phar_url="${phar_url}composer.phar"
23+
;;
24+
# get the latest version of the v1 tree
25+
1 | 1.x)
26+
phar_url="${phar_url}download/latest-1.x/composer.phar"
27+
;;
28+
# get the latest version of the v2 tree
29+
2 | 2.x)
30+
phar_url="${phar_url}download/latest-2.x/composer.phar"
31+
;;
32+
# get the latest version of the v2.2 tree
33+
2.2 | 2.2.x)
34+
phar_url="${phar_url}download/latest-2.2.x/composer.phar"
35+
;;
36+
# if the version is not one of the above, assume that it is a exact
37+
# naming, possibly with additions (RC, beta1, ...)
38+
*)
39+
phar_url="${phar_url}download/${ACTION_VERSION}/composer.phar"
40+
;;
41+
esac
1342
fi
1443
curl --silent -H "User-agent: cURL (https://github.com/php-actions)" -L "$phar_url" > "${github_action_path}/composer.phar"
1544
chmod +x "${github_action_path}/composer.phar"
@@ -33,7 +62,12 @@ then
3362

3463
if [ -n "$ACTION_SSH_DOMAIN" ]
3564
then
36-
ssh-keyscan -t rsa "$ACTION_SSH_DOMAIN" >> ~/.ssh/known_hosts
65+
if [ -n "$ACTION_SSH_PORT" ]
66+
then
67+
ssh-keyscan -t rsa -p $ACTION_SSH_PORT "$ACTION_SSH_DOMAIN" >> ~/.ssh/known_hosts
68+
else
69+
ssh-keyscan -t rsa "$ACTION_SSH_DOMAIN" >> ~/.ssh/known_hosts
70+
fi
3771
fi
3872

3973
echo "$ACTION_SSH_KEY" > ~/.ssh/action_rsa
@@ -160,7 +194,7 @@ do
160194
fi
161195
done <<<$(env)
162196

163-
echo "::set-output name=full_command::${command_string}"
197+
echo "name=full_command::${command_string}" >> $GITHUB_OUTPUT
164198

165199
docker run --rm \
166200
--volume "${github_action_path}/composer.phar":/usr/local/bin/composer \

0 commit comments

Comments
 (0)