Skip to content

Commit

Permalink
feat: implement GitHub Action to install Composer dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Sep 17, 2020
0 parents commit ccf9820
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig http://EditorConfig.org

# top-most EditorConfig file
root = true

# This applies to all files
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[*.{yml,yaml}]
indent_size = 2
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/CODE_OF_CONDUCT.md export-ignore
/CONTRIBUTING.md export-ignore
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: ramsey
Empty file added .gitignore
Empty file.
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
95 changes: 95 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Contributing

Contributions are welcome. This project accepts pull requests on [GitHub][].

This project adheres to a [code of conduct][]. By participating in
this project and its community, you are expected to uphold this code.

[code of conduct]: CODE_OF_CONDUCT.md


## Communication Channels

You can find help and discussion in the following places:

* GitHub Issues: <https://github.com/ramsey/composer-install/issues>


## Reporting Bugs

Bugs are tracked in the project's [issue tracker][issues].

When submitting a bug report, please include enough information to reproduce the
bug. A good bug report includes the following sections:

* Expected outcome
* Actual outcome
* Steps to reproduce, including sample code
* Any other information that will help debug and reproduce the issue, including
stack traces, system/environment information, and screenshots

**Please do not include passwords or any personally identifiable information in
your bug report and sample code.**


## Fixing Bugs

This project welcomes pull requests to fix bugs!

If you see a bug report that you'd like to fix, please feel free to do so.
Following the directions and guidelines described in the "Adding New Features"
section below, you may create bugfix branches and send pull requests.


## Adding New Features

If you have an idea for a new feature, it's a good idea to check out the
[issues][] or active [pull requests][] first to see if the feature is already
being worked on. If not, feel free to submit an issue first, asking whether the
feature is beneficial to the project. This will save you from doing a lot of
development work only to have your feature rejected. We don't enjoy rejecting
your hard work, but some features don't fit with the goals of the project.

When you do begin working on your feature, here are some guidelines to consider:

* Your pull request description should clearly detail the changes you have made.
We will use this description to update the CHANGELOG. If there is no
description or it does not adequately describe your feature, we may ask you
to update the description.
* ramsey/composer-install follows the **[PSR-12 coding standard][psr-12]**. Please
ensure your code does, too.
* Please **write tests** for any new features you add.
* Please **ensure that tests pass** before submitting your pull request.
ramsey/composer-install has GitHub Actions automatically running tests for
pull requests. However, running the tests locally will help save time.
* **Use topic/feature branches.** Please do not ask to pull from your master
branch.
* For more information, see "[Understanding the GitHub flow][gh-flow]."
* **Submit one feature per pull request.** If you have multiple features you
wish to submit, please break them up into separate pull requests.
* **Write good commit messages.** Make sure each individual commit in your pull
request is meaningful. If you had to make multiple intermediate commits while
developing, please squash them before submitting.
* For more information, see "[How to Write a Git Commit Message][git-commit]."


## Running Tests

The following must pass before we will accept a pull request. If this does not
pass, it will result in a complete build failure. Before you can run this, be
sure to `composer install`.

To run all the tests and coding standards checks, execute the following from the
command line, while in the project root directory:

```
composer test
```


[github]: https://github.com/ramsey/composer-install
[issues]: https://github.com/ramsey/composer-install/issues
[pull requests]: https://github.com/ramsey/composer-install/pulls
[psr-12]: https://www.php-fig.org/psr/psr-12/
[gh-flow]: https://guides.github.com/introduction/flow/
[git-commit]: https://chris.beams.io/posts/git-commit/
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020 Ben Ramsey <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<h1 align="center">ramsey/composer-install</h1>

<p align="center">
<strong>A GitHub Action to streamline installation of Composer dependencies.</strong>
</p>

<p align="center">
<a href="https://github.com/ramsey/composer-install"><img src="http://img.shields.io/badge/source-ramsey/composer--install-blue.svg?style=flat-square" alt="Source Code"></a>
<a href="https://github.com/ramsey/composer-install/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-darkcyan.svg?style=flat-square" alt="Read License"></a>
<a href="https://phpc.chat/channel/ramsey"><img src="https://img.shields.io/badge/phpc.chat-%23ramsey-darkslateblue?style=flat-square" alt="Chat with the maintainers"></a>
</p>

## About

ramsey/composer-install is a GitHub Action to streamline installation of
Composer dependencies in workflows.

This project adheres to a [code of conduct](CODE_OF_CONDUCT.md).
By participating in this project and its community, you are expected to
uphold this code.

## Usage

Use a step within a job:

```yaml
- uses: "ramsey/composer-install@v1"
```
By default, the action will use `composer install` to install dependencies. This
means it will use a `composer.lock` file to install dependencies, if one is
present. Otherwise, it will use the latest versions of dependencies, as defined
in `composer.json`.

To install the highest or lowest versions of dependencies, without respect for
`composer.lock`, use the `dependency-versions` input parameter.

```yaml
- uses: "ramsey/composer-install@v1"
with:
dependency-versions: highest
```

The `dependency-versions` input parameter may be either `highest`, `lowest`, or
`locked`. By default, it is `locked`.

You may also pass additional options to the `composer` command:

```yaml
- uses: "ramsey/composer-install@v1"
with:
dependency-versions: lowest
composer-options: "--ignore-platform-reqs"
```

## Contributing

Contributions are welcome! Before contributing to this project, familiarize
yourself with [CONTRIBUTING.md](CONTRIBUTING.md).

## Copyright and License

The ramsey/conventional-commits library is copyright © [Ben Ramsey](https://benramsey.com)
and licensed for use under the terms of the MIT License (MIT). Please see
[LICENSE](LICENSE) for more information.
47 changes: 47 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Install Composer Dependencies"
description: >-
Installs and caches Composer dependencies, accepting arguments to configure
how and what to install.
inputs:
dependency-versions:
description: >-
The version of dependencies to prefer (lowest, highest, or locked).
required: true
default: "locked"
composer-options:
description: >-
Additional options to pass to Composer (e.g. --ignore-platform-reqs).
required: false

runs:
using: "composite"
steps:

- name: "Get PHP environment details"
id: phpenv
shell: bash
run: |
echo "::set-output name=php-version::$(php -r 'echo phpversion();')"
echo "::set-output name=composer-cache-dir::$(composer config cache-files-dir)"
- name: "Cache Composer dependencies"
uses: "actions/cache@v2"
with:
path: "${{ steps.phpenv.outputs.composer-cache-dir }}"
key: "php-${{ steps.phpenv.outputs.php-version }}-${{ inputs.dependency-versions }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}-${{ inputs.composer-options }}"
restore-keys: |
php-${{ steps.phpenv.outputs.php-version }}-${{ inputs.dependency-versions }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}-
php-${{ steps.phpenv.outputs.php-version }}-${{ inputs.dependency-versions }}-
- name: "Install lowest Composer dependencies"
if: ${{ inputs.dependency-versions == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress ${{ inputs.composer-options }}"

- name: "Install highest Composer dependencies"
if: ${{ inputs.dependency-versions == 'highest' }}
run: "composer update --no-interaction --no-progress ${{ inputs.composer-options }}"

- name: "Install locked Composer dependencies"
if: ${{ inputs.dependency-versions == 'locked' }}
run: "composer install --no-interaction --no-progress ${{ inputs.composer-options }}"

0 comments on commit ccf9820

Please sign in to comment.