Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add cache-magento action #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package |
| [Fix Magento Install](./fix-magento-install/README.md) | A Github Action that fixes Magento before `composer install` |
| [Cache Magento](./cache-magento/README.md) | A Github Action that creates a composer cache for a Magento extension or store. |
| [Get Magento Version](./get-magento-version/README.md) | A Github Action that computes the installed Magento version. |
| [Installation Test](./installation-test/README.md) | A Github Action that tests the installability of a Magento Package |
| [Supported Version](./supported-version/README.md) | A Github Action that computes the currently supported Github Actions Matrix for Magento 2 |
43 changes: 43 additions & 0 deletions cache-magento/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Cache Magento Action

A Github Action that creates a composer cache for a Magento extension or store.

## Inputs


See the [action.yml](./action.yml)

| Input | Description | Required | Default |
| ------------------ | -------------------------------------------------------------------------------------- | -------- | ------------ |
| composer_cache_key | A key to version the composer cache. Can be incremented if you need to bust the cache. | false | '__graycore' |
| mode | "The mode for setup, one of: `extension` or `store`." | true | N/A |
| magento_directory | The Magento directory for the action to run against. | true | N/A |

### Usage

```yml
name: Magento Cache

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
showcase_cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: graycoreio/github-actions-magento2/cache-magento@main
with:
magento_directory: $GITHUB_WORKSPACE
mode: 'store'
id: cache-magento

- run: composer install
shell: bash
name: Composer install
```
47 changes: 47 additions & 0 deletions cache-magento/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Cache Magento 2 for Pipeline"
author: "Graycore"
description: "A Github Action that creates a composer cache for a Magento extension or store."

inputs:
composer_cache_key:
required: false
default: "__graycore"
description: A key to version the composer cache. Can be incremented if you need to bust the cache.

mode:
required: true
description: "The mode for setup, one of: `extension` or `store`."

outputs:
cache-hit:
description: "A boolean value to indicate an exact match was found for the key"
value: ${{ steps.cache-magento-cache.outputs.cache-hit }}

runs:
using: "composite"
steps:
- name: Get Composer Cache Directory
shell: bash
id: cache-magento-composer-cache
run: |
echo "dir=$(composer config cache-files-dir --global)" >> $GITHUB_OUTPUT

- run: echo "::set-output name=version::$(php -v | awk 'NR==1{print $2}')"
shell: bash
id: cache-magento-get-php-version

- run: echo "::set-output name=version::$(composer --version | awk '{print $3}')"
shell: bash
name: Compute Composer Version
id: cache-magento-get-composer-version

- name: "Cache Composer Packages"
uses: actions/cache@v3
id: cache-magento-cache
with:
key: "composer | v5.8 | ${{ inputs.composer_cache_key }} | ${{ steps.cache-magento-get-composer-version.outputs.version }} | ${{ steps.cache-magento-get-php-version.outputs.version }}"
path: ${{ steps.cache-magento-composer-cache.outputs.dir }}

branding:
icon: "code"
color: "green"