Skip to content

Commit

Permalink
Turn composer install into an action and use it in sanity as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Sep 16, 2023
1 parent e9df0a4 commit b3412c2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 57 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/actions/composer-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Install composer dependencies
description: Install composer dependencies
inputs:
ps_dir:
description: PrestaShop folder
required: true

runs:
using: "composite"
steps:
# Install composer vendors (must be done before building assets as classic theme is fetched from composer)
- name: Get Composer Cache Directory
id: composer-cache-dir
run: |
echo "composer-cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
working-directory: ${{ inputs.ps_dir }}
shell: bash

# Split composer caches into two steps, because the default automatic process always took some time on cleanup for unknown reason
# Restore composer cache dir and vendor
- name: Restore composer cache dir
uses: actions/cache/restore@v3
id: composer-cache
with:
path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- name: Restore composer vendor folder
uses: actions/cache/restore@v3
id: vendor-cache
with:
path: ${{ inputs.ps_dir }}/vendor
key: ${{ runner.os }}-vendor-${{ hashFiles('**/composer.lock') }}

# Run composer install
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader
working-directory: ${{ inputs.ps_dir }}
shell: bash

# Cache composer cache dir and vendor
- name: Save composer vendor folder
uses: actions/cache/save@v3
if: steps.vendor-cache.outputs.cache-hit != 'true'
with:
path: ${{ inputs.ps_dir }}/vendor
key: ${{ steps.vendor-cache.outputs.cache-primary-key }}
- name: Save composer cache dir
uses: actions/cache/save@v3
if: steps.composer-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }}
key: ${{ steps.composer-cache.outputs.cache-primary-key }}
42 changes: 3 additions & 39 deletions .github/workflows/build-shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,46 +93,10 @@ jobs:
# Build prestashop image in background
USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build >& /dev/null &
# Install composer vendors (must be done before building assets as classic theme is fetched from composer)
- name: Get Composer Cache Directory
id: composer-cache-dir
run: |
echo "composer-cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
working-directory: '${{ env.PS_DIR }}'

# Split composer caches into two steps, because the default automatic process always took some time on cleanup for unknown reason
# Restore composer cache dir and vendor
- name: Restore composer cache dir
uses: actions/cache/restore@v3
id: composer-cache
with:
path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- name: Restore composer vendor folder
uses: actions/cache/restore@v3
id: vendor-cache
with:
path: ${{ env.PS_DIR }}/vendor
key: ${{ runner.os }}-vendor-${{ hashFiles('**/composer.lock') }}

# Run composer install
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader
working-directory: '${{ env.PS_DIR }}'

# Cache composer cache dir and vendor
- name: Save composer vendor folder
uses: actions/cache/save@v3
if: steps.vendor-cache.outputs.cache-hit != 'true'
- name: Composer install
uses: ./custom_actions/.github/workflows/actions/composer-install
with:
path: ${{ env.PS_DIR }}/vendor
key: ${{ steps.vendor-cache.outputs.cache-primary-key }}
- name: Save composer cache dir
uses: actions/cache/save@v3
if: steps.composer-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }}
key: ${{ steps.composer-cache.outputs.cache-primary-key }}
ps_dir: ${{ env.PS_DIR }}

# Install node dependencies and build assets
- name: Build assets
Expand Down
21 changes: 3 additions & 18 deletions .github/workflows/test-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,10 @@ jobs:
## Add self-signed certificate to Chrome Trust Store
mkcert -install
# Install composer vendors
- name: Get Composer Cache Directory
id: composer-cache-dir
run: |
echo "composer-cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
working-directory: '${{ env.PS_DIR }}'
- uses: actions/cache@v3
id: composer-cache
with:
path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- uses: actions/cache@v3
id: vendor-cache
- name: Composer install
uses: ./custom_actions/.github/workflows/actions/composer-install
with:
path: ${{ env.PS_DIR }}/vendor
key: ${{ runner.os }}-vendor-${{ hashFiles('**/composer.lock') }}
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader
working-directory: '${{ env.PS_DIR }}'
ps_dir: ${{ env.PS_DIR }}

# Create shop with Docker without building assets, and initialize database and shop content
# No need to wait for install-dev ready it should be nearly automatic and just in case we build the assets after to leave
Expand Down

0 comments on commit b3412c2

Please sign in to comment.