Skip to content

Commit

Permalink
feat: convert to a composite action
Browse files Browse the repository at this point in the history
This also adds the following features:

- Use `--prefer-stable` with lowest dependencies (#178)
- Allow use of a custom cache key (#167)
- Allow ability to ignore the cache

Fixes: #187, #161, #152, #79
  • Loading branch information
ramsey committed Dec 23, 2021
1 parent 96ea832 commit 5c815a4
Show file tree
Hide file tree
Showing 53 changed files with 1,147 additions and 1,723 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Expand Up @@ -7,6 +7,10 @@ root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 4

[*.{yml,yaml}]
indent_size = 2
13 changes: 12 additions & 1 deletion .gitattributes
@@ -1 +1,12 @@
dist/** -diff linguist-generated=true
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/CHANGELOG.md export-ignore
/CODE_OF_CONDUCT.md export-ignore
/composer.json export-ignore
/composer.lock export-ignore
/CONTRIBUTING.md export-ignore
/SECURITY.md export-ignore
/subdirectory/ export-ignore
/tests/ export-ignore
63 changes: 41 additions & 22 deletions .github/workflows/continuous-integration.yml
@@ -1,29 +1,31 @@
name: "CI"
# GitHub Actions Documentation: https://docs.github.com/en/actions

on:
pull_request:
push:
branches:
- "v[0-9]+"
name: "build"

jobs:
on: ["pull_request", "push"]

# Make sure build/ci work properly.
build:
name: "Build"
jobs:
test:
name: "Expect Tests"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
- name: "Checkout repository"
uses: "actions/checkout@v2"
- name: "Install expect"
run: |
sudo apt-get update
sudo apt-get -y install expect
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "latest"
- run: "npm install"
- run: "npm run all"
- uses: "codecov/codecov-action@v1"
tools: "composer:v2"
coverage: "none"
- name: "Run expect tests"
run: "composer test"

# Make sure the action works on a clean machine without building.
test:
name: "Test"
run:
name: "Run Action"
runs-on: "${{ matrix.operating-system }}"
strategy:
matrix:
Expand All @@ -35,14 +37,31 @@ jobs:
- "highest"
- "locked"
composer-options:
- "--working-dir subdirectory"
- "--ignore-platform-reqs"
- ""
working-directory:
- "subdirectory"
- ""
ignore-cache:
- "yes"
- ""
custom-cache-key:
- "my-super-custom-cache-key"
- ""
steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
- name: "Checkout repository"
uses: "actions/checkout@v2"
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "latest"
- uses: ./
tools: "composer:v2"
coverage: "none"
- name: "Run composer-install action"
uses: ./
with:
dependency-versions: "${{ matrix.dependency-versions }}"
composer-options: "${{ matrix.composer-options }}"
working-directory: "${{ matrix.working-directory }}"
ignore-cache: "${{ matrix.ignore-cache }}"
custom-cache-key: "${{ matrix.custom-cache-key }}"
103 changes: 2 additions & 101 deletions .gitignore
@@ -1,101 +1,2 @@
# Dependency directory
node_modules

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*

vendor/
**/vendor/
/tests/expect/**.txt
27 changes: 21 additions & 6 deletions CONTRIBUTING.md
Expand Up @@ -68,17 +68,32 @@ When you do begin working on your feature, here are some guidelines to consider:

## 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 `npm install`.
This project includes a suite of tests located in `tests/expect/`.
These tests use the [Expect](https://en.wikipedia.org/wiki/Expect) tool to
automate CLI interactions. The tests will run automatically as part of
continuous integration, or you may run them locally with:

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

To run the tests, you must have an up-to-date version of coreutils (8.30 or
later).

To generate a new test:

```
npm run all
cd tests/expect/
autoexpect ../../bin/path-to-script-to-test.sh
```

`autoexpect` will save the test to `script.exp`. Rename it with a more
descriptive name, and run it to ensure it does what you expect: `./script.exp`.
You may need to edit the test file or add to it, according to your needs.

When done, `cd ../..` and run `composer test`.
Your new test should run along with the other tests.

[github]: https://github.com/ramsey/composer-install
[issues]: https://github.com/ramsey/composer-install/issues
[pull requests]: https://github.com/ramsey/composer-install/pulls
Expand Down
77 changes: 58 additions & 19 deletions README.md
Expand Up @@ -38,8 +38,8 @@ the [Setup PHP](https://github.com/shivammathur/setup-php) action as a step.
```yaml
- uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
- uses: "ramsey/composer-install@v1"
php-version: "latest"
- uses: "ramsey/composer-install@v2"
```

:bulb: There is no need to set up a separate caching step since ramsey/composer-install
Expand All @@ -61,12 +61,12 @@ Valid values are:
(equivalent to running `composer update`)

* `lowest`: installs the lowest versions of Composer dependencies (equivalent
to running `composer update --prefer-lowest`)
to running `composer update --prefer-lowest --prefer-stable`)

For example:

```yaml
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"
with:
dependency-versions: "lowest"
```
Expand All @@ -80,33 +80,72 @@ options, you may use the `composer-options` input parameter.
For example:

```yaml
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"
with:
composer-options: "--ignore-platform-reqs --working-dir=backend"
composer-options: "--ignore-platform-reqs --optimize-autoloader"
```

### Alternate `composer.json` Locations
#### working-directory

If `composer.json` is not located in your repository root, or if you have
multiple `composer.json` files located in various parts of your project, you may
specify the `--working-dir` option as part of `composer-options`. You may use
this step as many times as needed, if you have multiple `composer.json` files.
The `working-directory` input parameter allows you to specify a different
location for your `composer.json` file. For example, if your `composer.json` is
located in `packages/acme-foo/`, use `working-directory` to tell
ramsey/composer-install where to run things.

```yaml
- uses: "ramsey/composer-install@v2"
with:
working-directory: "packages/acme-foo"
```

You may use this step as many times as needed, if you have multiple
`composer.json` files.

For example:

```yaml
# Install dependencies using composer.json in the root.
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"

# Install dependencies using composer.json in src/Component/Config/
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"
with:
composer-options: "--working-dir=src/Component/Config"
working-directory: "src/Component/Config"

# Install dependencies using composer.json in src/Component/Validator/
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"
with:
working-directory: "src/Component/Validator"
```

#### ignore-cache

If you have jobs for which you wish to completely ignore the caching step, you
may use the `ignore-cache` input parameter. When present, ramsey/composer-install
will neither read from nor write to the cache.

Values of `'yes'`, `true`, or `1` will tell the action to ignore the cache. For
any other value, the action will use the default behavior, which is to read from
and store to the cache.

```yaml
- uses: "ramsey/composer-install@v2"
with:
ignore-cache: "yes"
```

#### custom-cache-key

There may be times you wish to specify your own cache key. You may do so with
the `custom-cache-key` input parameter. When provided, ramsey/composer-install
will not use the auto-generated cache key, so if your `composer.json` or
`composer.lock` files change, you'll need to update the custom cache key if you
wish to update the cache.

```yaml
- uses: "ramsey/composer-install@v2"
with:
composer-options: "--working-dir=src/Component/Validator"
custom-cache-key: "my-custom-cache-key"
```

### Matrix Example
Expand All @@ -122,22 +161,22 @@ Here's an example of how you might use the `dependency-versions` and
strategy:
matrix:
php:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
dependencies:
- "lowest"
- "highest"
include:
- php-version: "8.1"
- php-version: "8.2"
composer-options: "--ignore-platform-reqs"

steps:
- uses: "actions/checkout@v2"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
- uses: "ramsey/composer-install@v1"
- uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "${{ matrix.composer-options }}"
Expand Down

0 comments on commit 5c815a4

Please sign in to comment.