Skip to content

Commit 93365ba

Browse files
committed
Initial version
0 parents  commit 93365ba

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea
2+
*~

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Ernesto Baschny
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
baschny/action-php-composer
2+
===========================
3+
4+
This GitHub action allows to run the latest composer on your source code.
5+
6+
It uses the official composer docker image and allows efficient caching of
7+
downloaded assets.
8+
9+
Input
10+
-----
11+
* `composer_version`: Major version to install. Basically any tag name from https://hub.docker.com/_/composer -
12+
i.e. `1` or `2`. Defaults to `latest`.
13+
14+
* `command`: The composer command to run, defaults to `install`. Set to `get_config` to only generate the output
15+
variables of the composer setup (for use in cache, see example below)
16+
17+
* `args`: Other command line arguments to pass to composer, defaults to `--optimize-autoloader --no-progress`
18+
19+
Output
20+
------
21+
* `composer_cache_dir`: where the composer cache is located, in case you want to use `actions/cache`
22+
23+
* `composer_major_version`: the detected major version of composer, useful to have a separate cache tag based on
24+
this, since there can be slight differences in the caches between major versions.
25+
26+
* `composer_version`: the exact composer version, in case you want to output this somewhere.
27+
28+
Example Workflow
29+
----------------
30+
31+
```yaml
32+
name: PHP Building Workflow
33+
34+
on: [push]
35+
36+
jobs:
37+
38+
composer_install:
39+
runs-on: ubuntu-latest
40+
41+
env:
42+
COMPOSER_VERSION: 1
43+
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v2
47+
48+
- name: Get composer cache directory
49+
id: composer_config
50+
uses: baschny/action-php-composer
51+
with:
52+
composer_version: ${{ env.COMPOSER_VERSION }}
53+
command: get_config
54+
55+
- name: Cache composer downloads
56+
uses: actions/cache@v2
57+
with:
58+
path: ${{ steps.composer_config.outputs.composer_cache_dir }}
59+
key: composer-v${{ steps.composer_config.outputs.composer_major_version }}
60+
61+
- name: Run composer install
62+
uses: baschny/action-php-composer
63+
with:
64+
composer_version: ${{ env.COMPOSER_VERSION }}
65+
command: install
66+
```
67+
68+
License
69+
-------
70+
71+
See LICENSE file.
72+
73+
See also
74+
--------
75+
76+
The idea came after some brainstorming in https://github.com/php-actions/composer.
77+
78+
Author
79+
------
80+
81+
Ernesto Baschny, cron IT GmbH

action.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: 'PHP Composer'
2+
description: 'Use the Composer CLI in your Github Actions.'
3+
4+
inputs:
5+
composer_version:
6+
description: "What version of Composer to use"
7+
default: latest
8+
required: false
9+
10+
command:
11+
description: "Composer command to run (or get_config to just get the output vars)"
12+
required: true
13+
default: install
14+
15+
args:
16+
description: "Command line arguments to composer"
17+
required: false
18+
default: "--optimize-autoloader --no-progress"
19+
20+
outputs:
21+
composer_cache_dir:
22+
description: "Where composer created its cache"
23+
value: ${{ steps.composer_run.outputs.composer_cache_dir }}
24+
25+
composer_major_version:
26+
description: "Major version of the composer run (can be used as part of the cache key)"
27+
value: ${{ steps.composer_run.outputs.composer_major_version }}
28+
29+
composer_version:
30+
description: "Exact version of the composer run"
31+
value: ${{ steps.composer_run.outputs.composer_major_version }}
32+
33+
runs:
34+
using: "composite"
35+
steps:
36+
- env:
37+
COMPOSER_VERSION: ${{ inputs.composer_version }}
38+
COMPOSER_COMMAND: ${{ inputs.command }}
39+
COMPOSER_ARGS: ${{ inputs.args }}
40+
shell: bash
41+
id: composer_run
42+
run: |
43+
set -e
44+
45+
# Make sure the latest version is available, pull it quietly
46+
docker pull -q composer:${COMPOSER_VERSION}
47+
48+
# Extract the major version
49+
DETECTED_VERSION=$(docker run --rm composer:${COMPOSER_VERSION} --version | perl -pe '($_)=/\b(\d+.\d+\.\d+)\b/;')
50+
DETECTED_MAJOR_VERSION=$(docker run --rm composer:${COMPOSER_VERSION} --version | perl -pe '($_)=/\b(\d)\d*\.\d+\.\d+/;')
51+
echo "::set-output name=composer_cache_dir::${RUNNER_WORKSPACE}/composer/cache"
52+
echo "::set-output name=composer_major_version::${DETECTED_MAJOR_VERSION}"
53+
echo "::set-output name=composer_version::${DETECTED_VERSION}"
54+
55+
case "${COMPOSER_COMMAND}" in
56+
get_config)
57+
exit
58+
;;
59+
60+
*)
61+
echo "Running composer v${DETECTED_VERSION} with: $COMPOSER_COMMAND $COMPOSER_ARGS"
62+
docker run --rm \
63+
--volume ${RUNNER_WORKSPACE}/composer:/tmp \
64+
--volume ${GITHUB_WORKSPACE}:/app \
65+
-w /app \
66+
composer:${COMPOSER_VERSION} $COMPOSER_COMMAND $COMPOSER_ARGS
67+
;;
68+
esac
69+
70+
branding:
71+
icon: 'package'
72+
color: 'purple'

0 commit comments

Comments
 (0)