Skip to content

Commit f5d43a5

Browse files
authored
feat: add cache-magento action (#87)
1 parent 856d2df commit f5d43a5

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain
2727
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
2828
| [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package |
2929
| [Fix Magento Install](./fix-magento-install/README.md) | A Github Action that fixes Magento before `composer install` |
30+
| [Cache Magento](./cache-magento/README.md) | A Github Action that creates a composer cache for a Magento extension or store. |
3031
| [Get Magento Version](./get-magento-version/README.md) | A Github Action that computes the installed Magento version. |
3132
| [Installation Test](./installation-test/README.md) | A Github Action that tests the installability of a Magento Package |
3233
| [Supported Version](./supported-version/README.md) | A Github Action that computes the currently supported Github Actions Matrix for Magento 2 |

cache-magento/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Cache Magento Action
2+
3+
A Github Action that creates a composer cache for a Magento extension or store.
4+
5+
## Inputs
6+
7+
8+
See the [action.yml](./action.yml)
9+
10+
| Input | Description | Required | Default |
11+
| ------------------ | -------------------------------------------------------------------------------------- | -------- | ------------ |
12+
| composer_cache_key | A key to version the composer cache. Can be incremented if you need to bust the cache. | false | '__graycore' |
13+
| mode | "The mode for setup, one of: `extension` or `store`." | true | N/A |
14+
| magento_directory | The Magento directory for the action to run against. | true | N/A |
15+
16+
### Usage
17+
18+
```yml
19+
name: Magento Cache
20+
21+
on:
22+
push:
23+
branches:
24+
- main
25+
pull_request:
26+
branches:
27+
- main
28+
29+
jobs:
30+
showcase_cache:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v3
34+
- uses: graycoreio/github-actions-magento2/cache-magento@main
35+
with:
36+
magento_directory: $GITHUB_WORKSPACE
37+
mode: 'store'
38+
id: cache-magento
39+
40+
- run: composer install
41+
shell: bash
42+
name: Composer install
43+
```

cache-magento/action.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "Cache Magento 2 for Pipeline"
2+
author: "Graycore"
3+
description: "A Github Action that creates a composer cache for a Magento extension or store."
4+
5+
inputs:
6+
composer_cache_key:
7+
required: false
8+
default: "__graycore"
9+
description: A key to version the composer cache. Can be incremented if you need to bust the cache.
10+
11+
mode:
12+
required: true
13+
description: "The mode for setup, one of: `extension` or `store`."
14+
15+
outputs:
16+
cache-hit:
17+
description: "A boolean value to indicate an exact match was found for the key"
18+
value: ${{ steps.cache-magento-cache.outputs.cache-hit }}
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Get Composer Cache Directory
24+
shell: bash
25+
id: cache-magento-composer-cache
26+
run: |
27+
echo "dir=$(composer config cache-files-dir --global)" >> $GITHUB_OUTPUT
28+
29+
- run: echo "::set-output name=version::$(php -v | awk 'NR==1{print $2}')"
30+
shell: bash
31+
id: cache-magento-get-php-version
32+
33+
- run: echo "::set-output name=version::$(composer --version | awk '{print $3}')"
34+
shell: bash
35+
name: Compute Composer Version
36+
id: cache-magento-get-composer-version
37+
38+
- name: "Cache Composer Packages"
39+
uses: actions/cache@v3
40+
id: cache-magento-cache
41+
with:
42+
key: "composer | v5.8 | ${{ inputs.composer_cache_key }} | ${{ steps.cache-magento-get-composer-version.outputs.version }} | ${{ steps.cache-magento-get-php-version.outputs.version }}"
43+
path: ${{ steps.cache-magento-composer-cache.outputs.dir }}
44+
45+
branding:
46+
icon: "code"
47+
color: "green"

0 commit comments

Comments
 (0)