Skip to content

Commit

Permalink
Transform shop zipping and push to artifacts into a reusable action
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Sep 25, 2023
1 parent 2dc283d commit 1bcea01
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 30 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/actions/archive-shop/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Archive shop
description: Archive shop to share with future jobs, the action exports sources sql and xml checksum (optional)
inputs:
ps_dir:
description: Directory target
required: true
db_user:
description: DB user
required: true
db_password:
description: DB password
required: true
db_name:
description: DB name
required: true
artifact_name:
description: Artifact name, used later for download
required: false
default: shop-artifacts

runs:
using: "composite"
steps:
- name: Archive shop content
run: |
mkdir -p /tmp/${{ inputs.artifact_name }}
pushd ${{ inputs.ps_dir }}; zip -q -r /tmp/${{ inputs.artifact_name }}/sources.zip . -x \
"admin-dev/themes/new-theme/node_modules/**/*" \
"admin-dev/themes/default/node_modules/**/*" \
"themes/classic/_dev/**/*" \
"themes/_core/**/*" \
"themes/node_modules/**/*" \
"install-dev/**/*" \
"translations/*.zip" \
"var/cache/**/*" \
"tests/Integration/**/*" \
"tests/Resources/**/*" \
"tests/Unit/**/*" \
".git/**/*"; popd
docker exec my_prestashop_mysql_1 /usr/bin/mysqldump -u ${{ inputs.db_user }} -p${{ inputs.db_password }} ${{ inputs.db_name }} > /tmp/${{ inputs.artifact_name }}/db_dump.sql
shell: bash

- name: Upload shop artifacts "${{ inputs.artifact_name }}"
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifact_name }}
path: /tmp/${{ inputs.artifact_name }}
31 changes: 31 additions & 0 deletions .github/workflows/actions/archive-shop/download/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Download archive shop
description: Download archive shop and extracts it to the specified folder
inputs:
target_folder:
description: Target folder for extraction
required: true
artifact_name:
description: Artifact name, used later for download
required: false
default: shop-artifacts
outputs:
source-path:
description: Path to the sources zip file
value: /tmp/${{ inputs.artifact_name }}/sources.zip
db-dump-path:
description: Path to the sources zip file
value: /tmp/${{ inputs.artifact_name }}/db_dump.sql

runs:
using: "composite"
steps:
- name: Download docker artifacts
uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact_name }}
path: /tmp/${{ inputs.artifact_name }}

- name: Extract PrestaShop sources
run: |
unzip /tmp/${{ inputs.artifact_name }}/sources.zip -d ${{ inputs.target_folder }}
shell: bash
27 changes: 5 additions & 22 deletions .github/workflows/build-shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,29 +198,12 @@ jobs:
# Prepare archive contents to share with following jobs
- name: Archive shop content
if: always()
run: |
mkdir -p /tmp/shop-artifacts
zip -q -r /tmp/shop-artifacts/sources.zip ${{ env.PS_DIR }} -x \
"*/admin-dev/themes/new-theme/node_modules/**/*" \
"*/admin-dev/themes/default/node_modules/**/*" \
"*/themes/classic/_dev/**/*" \
"*/themes/_core/**/*" \
"*/themes/node_modules/**/*" \
"*/install-dev/**/*" \
"*/translations/*.zip" \
"*/var/cache/**/*" \
"*/tests/Integration/**/*" \
"*/tests/Resources/**/*" \
"*/tests/Unit/**/*" \
"*/.git/**/*"
docker exec my_prestashop_mysql_1 /usr/bin/mysqldump -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} ${{ env.DB_NAME }} > /tmp/shop-artifacts/db_dump.sql
- name: Upload shop artifacts
if: always()
uses: actions/upload-artifact@v3
uses: ./custom_actions/.github/workflows/actions/archive-shop
with:
name: shop-artifacts
path: /tmp/shop-artifacts
ps_dir: ${{ env.PS_DIR }}
db_user: ${{ env.DB_USER }}
db_password: ${{ env.DB_PASSWD }}
db_name: ${{ env.DB_NAME }}

- name: Save logs in case of error
uses: actions/upload-artifact@v3
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/test-with-prebuilt-shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,10 @@ jobs:
path: custom_actions

- name: Download docker artifacts
uses: actions/download-artifact@v3
id: download-shop
uses: ./custom_actions/.github/workflows/actions/archive-shop/download
with:
name: shop-artifacts
path: /tmp/shop-artifacts

- name: Extract PrestaShop sources
run: |
unzip /tmp/shop-artifacts/sources.zip -d .
target_folder: ${{ env.PS_DIR }}

# Pre pull/build images
- name: Pull mysql in background
Expand Down Expand Up @@ -121,7 +117,7 @@ jobs:
sleep 10
until docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }}; do echo "Sleep and retry to check"; sleep 2; done
echo Copying dump into docker
docker cp /tmp/shop-artifacts/db_dump.sql my_prestashop_mysql_1:/tmp/db_dump.sql
docker cp ${{ steps.download-shop.outputs.db-dump-path }} my_prestashop_mysql_1:/tmp/db_dump.sql
echo Creating ${{ env.DB_NAME }} database
docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} -e "CREATE DATABASE IF NOT EXISTS ${{ env.DB_NAME }};"
echo Load dump into DB
Expand Down

0 comments on commit 1bcea01

Please sign in to comment.