Skip to content

Commit

Permalink
Add file watcher for shopware/shopware (#1209)
Browse files Browse the repository at this point in the history
* Add more test files

* Test error

* Optimize loop

* Remove output

* Add word and rename repo

* Add new filters to pyspelling

* Adjust comments

* Remove test file

* Remove test file

* Minor fix from review dog
  • Loading branch information
Isengo1989 authored Dec 8, 2023
1 parent f2b7b7f commit a9f8e64
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 9 deletions.
61 changes: 61 additions & 0 deletions .github/scripts/file-watcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#! /usr/bin/env bash

# Set the path to the snippets folder
WATCHER_PATH=$1
COUNTER=0
ERROR_FOUND=0


# Find all files in the snippets folder
while IFS= read -r -d '' file; do
# Check if the file contains the string "WATCHER_URL" and is therefore a watcher file
cat "$file" | grep 'WATCHER_URL' >> /dev/null || continue
((COUNTER++))

# Get the JSON from the first line of the file
HEAD=$(cat "$file" | grep 'WATCHER_URL')
JSON=$(sed "s/<!-- //;s/ -->//" <<< "$HEAD")

# Get the values from the JSON
WATCHER_URL=$(echo $JSON | jq -r '.WATCHER_URL')
WATCHER_HASH=$(echo $JSON | jq -r '.WATCHER_HASH')
WATCHER_CONTAINS=$(echo $JSON | jq -r '.WATCHER_CONTAINS')

# Get the hash of the URL
EVAL_HASH="curl -sl $WATCHER_URL | md5sum | cut -d ' ' -f 1"
CALLED_HASH="$(eval $EVAL_HASH)"

# Check if the hashes are equal
if [ "$WATCHER_HASH" == "$CALLED_HASH" ]; then
echo "Both hashes are equal."
else
echo "Hashes are not equal."

FILE_CONTENT=$(curl -sl $WATCHER_URL)

# Check if $WATCHER_CONTAINS contains the string "null" and is therefore empty or not set
if [[ $WATCHER_CONTAINS == "null" ]]; then
ERROR_FOUND=1
echo "Sourcefile: https://github.com/shopware/docs/blob/main/$file"
fi
# Check if $WATCHER_CONTAINS contains the string $WATCHER_CONTAINS and if not call the Slack webhook
if [[ $FILE_CONTENT == *"$WATCHER_CONTAINS"* ]]; then
echo "String found!"
else
echo "String not found! Please check $WATCHER_URL"
echo "Sourcefile: https://github.com/shopware/docs/blob/main/$file"
ERROR_FOUND=1
fi
fi
done < <(find $WATCHER_PATH -type f -regex '.*\.\(md\|yaml\)$' -print0)

echo "Found $COUNTER files with a watcher tag."

if [ "$ERROR_FOUND" -eq 1 ]
then
echo "Error found, exiting..."
exit 1
else
echo "No error found, exiting..."
exit 0
fi
35 changes: 35 additions & 0 deletions .github/workflows/watcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Check shopware files for changes
on:
pull_request:
workflow_dispatch:

jobs:
check-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
./.github/scripts/file-watcher.sh
id: watcher
continue-on-error: true
- name: Send custom JSON data to Slack workflow
if: steps.watcher.outcome != 'success'
id: slack
uses: slackapi/[email protected]
with:
payload: |
{
"text": "Text: GitHub Action build result: ${{ job.status }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":ladybug: Failed file watcher with status '${{ steps.watcher.outcome }}': Please check ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
12 changes: 12 additions & 0 deletions .spellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ matrix:
ignores:
- code
- pre
- pyspelling.filters.context:
context_visible_first: true
escapes: \\[\\`~]
delimiters:
- open: '(?s)^(?P<open> *`{3,})$'
close: '^(?P=open)$'
- open: '(?P<open>`+)'
close: '(?P=open)'
- open: '(?P<open># {"+)'
close: '(?P=open)'
- open: '# {'
close: '}'
sources:
- '**/*.md|!resources/references/adr/*|!resources/guidelines/code/core/*'
default_encoding: utf-8
1 change: 1 addition & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ ProductListRoute
ProductManufacturerDefinition
ProductMediaDefinition
ProductNumber
productNumber
ProductOptionRelationDataSet
ProductPage
ProductPriceAttributeDataSet
Expand Down
3 changes: 3 additions & 0 deletions guides/hosting/configurations/shopware/html-sanitizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ If you want to deactivate the sanitizer despite security risks, you can also do
::: warning
Disabling the HTML sanitizer will allow potentially unsafe or malicious HTML code to be inserted.
:::


<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Resources/config/packages/shopware.yaml","WATCHER_HASH":"183f85ba8f15e8e7d0006b70be20940f","WATCHER_CONTAINS":"html_sanitizer"} -->
2 changes: 2 additions & 0 deletions guides/hosting/configurations/shopware/stock.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ To disable, set `shopware.stock.enable_stock_management` to `false`:
<<< @/docs/snippets/config/stock_disabled.yaml

For more detailed implementation refer to [Stock](../../../../guides/plugins/plugins/content/stock/) guide section.

<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Resources/config/packages/shopware.yaml","WATCHER_HASH":"183f85ba8f15e8e7d0006b70be20940f","WATCHER_CONTAINS":"enable_stock_management"} -->
2 changes: 2 additions & 0 deletions guides/hosting/infrastructure/filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ shopware:
sitemap:
url: "{url-to-your-sitemap-files}"
# The Adapter Configuration

```
<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Resources/config/packages/shopware.yaml","WATCHER_HASH":"183f85ba8f15e8e7d0006b70be20940f","WATCHER_CONTAINS":"filesystem"} -->

If you want to regulate the uploaded file types, then you could add the keys `allowed_extensions`for the public filesystem or `private_local_download_strategy` for the private filesystem.
With the `private_local_download_strategy` key you could choose the download strategy for private files (e.g., the downloadable products):
Expand Down
2 changes: 2 additions & 0 deletions guides/hosting/infrastructure/message-queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ Following environment variables are in use out of the box:

The number of workers depends on the number of messages queued and the type of messages they are. Product indexing messages are usually slow, while other messages are processed very fast. Therefore, it is difficult to give a general recommendation. You should be able to monitor the queue and adjust the number of workers accordingly.
Sometimes, it also makes sense to route messages to a different transport to limit the number of workers for a specific type of message to avoid database locks or prioritize messages like sending emails.

<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Resources/config/packages/shopware.yaml","WATCHER_HASH":"183f85ba8f15e8e7d0006b70be20940f","WATCHER_CONTAINS":"enable_admin_worker"} -->
2 changes: 2 additions & 0 deletions guides/hosting/infrastructure/reverse-http-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,5 @@ Additionally, we need to set up some VCL Snippets in the Fastly interface:
<PageRef page="https://github.com/shopware/recipes/blob/main/shopware/fastly-meta/6.4/config/fastly/hit.vcl" title="vcl_hit" target="_blank" />

<PageRef page="https://github.com/shopware/recipes/blob/main/shopware/fastly-meta/6.4/config/fastly/recv.vcl" title="vcl_recv" target="_blank" />

<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Storefront/Resources/config/packages/storefront.yaml","WATCHER_HASH":"caead56ad257ecec0e10a62dd3121bb6"} -->
2 changes: 2 additions & 0 deletions guides/integrations-api/general-concepts/search-criteria.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,5 @@ The `grouping` parameter allows you to group the result over fields. It can be u
"grouping": ["active"]
}
```

<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/store-api-reference/37fb4382af17d88cc50dfbe549752339dec01837/docs/concepts/search-queries.md","WATCHER_HASH":"5a95741bd3bf9d4b900f27a90e87f77b"} -->
2 changes: 2 additions & 0 deletions guides/plugins/apps/shipping-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,5 @@ Here, you can set the display order of the shipping methods in the checkout. If
</shipping-methods>
</manifest>
```

<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/App/Manifest/Xml/ShippingMethod/ShippingMethod.php","WATCHER_HASH":"cafda2eb40608199c21a229e46d5a32e"} -->
10 changes: 5 additions & 5 deletions guides/plugins/themes/add-icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ nav:

## Overview

In this guide you will learn how to use the icon renderer component as well as adding custom icons.
In this guide, you will learn how to use the icon renderer component as well as adding custom icons.

::: info
Even if this is originally a plugin guide, everything will work perfectly in a theme as well. Actually, a theme even is a kind of plugin. So don't get confused by us talking about plugins here.
:::

## Prerequisites

In order to follow this guide easily, you first need to have a functioning plugin installed. Head over to our [Plugin base guide](../plugins/plugin-base-guide) to create a plugin, if you don't know how it's done yet. Also knowing and understanding SCSS will be quite mandatory to fully understand what's going on here. Furthermore, it might be helpful to read the guide on how to [handle own assets](../plugins/storefront/add-custom-assets) in your plugin before you start with this one.
To follow this guide easily, you first need to have a functioning plugin installed. Head over to our [Plugin base guide](../plugins/plugin-base-guide) to create a plugin, if you don't know how it's done yet. Also, knowing and understanding SCSS will be quite mandatory to fully understand what's going on here. Furthermore, it might be helpful to read the guide on how to [handle own assets](../plugins/storefront/add-custom-assets) in your plugin before you start with this one.

## Adding icon

In order to add any icons to the Storefront, you use our `sw_icon` twig action. This way, an icon of choice is displayed in the Storefront.
To add any icons to the Storefront, you use our `sw_icon` twig action. This way, an icon of choice is displayed in the Storefront.

Needless to say, the first step is saving your image somewhere in your plugin where Shopware can find it. The default path for icons is the following:

Expand All @@ -30,7 +30,7 @@ Needless to say, the first step is saving your image somewhere in your plugin wh
`
```

You can also provide "solid" icons or any other custom pack names which can be configured later with the `pack` parameter. You can do that by creating a folder with the pack name:
You can also provide "solid" icons or any other custom pack names that can be configured later with the `pack` parameter. You can do that by creating a folder with the pack name:

```text
<YourPlugin>/src/Resources/app/storefront/dist/assets/icon/<pack-name>
Expand Down Expand Up @@ -89,7 +89,7 @@ A simple but fully functional example could look like below:
Icons or other custom assets are not included in the theme inheritance.
:::

Inside your theme, you cannot put an icon in a directory corresponding the core folder structure and expect the core one to be automatically overwritten by it, as you're used to with themes in general.
Inside your theme, you cannot put an icon in a directory corresponding to the core folder structure and expect the core one to be automatically overwritten by it, as you're used to with themes in general.

## Load icons from custom locations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ nav:

A theme is a special type of Plugin or App, aimed at easily changing the visual appearance of the Storefront. If you want to get more information about plugins and apps you can check out the [Plugin Base Guide](../plugins/plugin-base-guide) and [App Base Guide](../apps/app-base-guide).

There are basically several ways to change the appearance of the Storefront. You can have "regular" plugins or apps which main purpose is to add new functions and change the behavior of the shop. These plugins / apps might also contain SCSS/CSS and JavaScript to be able to embed their new features into the Storefront.
There are basically several ways to change the appearance of the Storefront. You can have "regular" plugins or apps whose main purpose is to add new functions and change the behavior of the shop. These plugins / apps might also contain SCSS/CSS and JavaScript to be able to embed their new features into the Storefront.

Technically a theme is also a plugin / app but it will be visible in the theme manger once its activated and can be assigned to a specific sales channel, while plugins / apps are activated globally. To distinguish a theme from a "regular" plugin / app you need to implement the Interface `Shopware\Storefront\Framework\ThemeInterface`. A theme can inherit also from other themes, overwrite the default configuration \(colors, fonts, media\) and add new configuration options.
Technically, a theme is also a plugin / app, but it will be visible in the theme manger once it's activated and can be assigned to a specific sales channel, while plugins / apps are activated globally. To distinguish a theme from a "regular" plugin / app you need to implement the Interface `Shopware\Storefront\Framework\ThemeInterface`. A theme can inherit also from other themes, overwrite the default configuration \(colors, fonts, media\) and add new configuration options.

You do not need to write any PHP code in a theme. If you need PHP code you should choose a plugin instead. Another important distinction to themes is this: Themes are specific for a sales channel and have to be assigned to them to take effect, the other way around plugins and apps have a global effect on the Shopware installation.
You do not need to write any PHP code in a theme. If you need PHP code, you should choose a plugin instead. Another important distinction to themes is this: Themes are specific for a sales channel and have to be assigned to them to take effect, the other way around plugins and apps have a global effect on the Shopware installation.

## Next steps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ nav:

This is an overview of all the directives registered globally to Vue.
Directives are the same as normally in Vue. Checkout the [Using directives](../../../guides/plugins/plugins/administration/adding-directives.md) article
or refer to the [directives](https://github.com/shopware/shopware/tree/trunk/src/Administration/Resources/app/administration/src/app/directive) folder on GIT repo.
or refer to the [directives](https://github.com/shopware/shopware/tree/trunk/src/Administration/Resources/app/administration/src/app/directive) folder in the GIT repository.

## Overview of directives

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,6 @@ All available hooks that can be used to execute scripts during your app's lifecy
| **Available Data** | products: `array`<br>salesChannelContext: [`Shopware\Core\System\SalesChannel\SalesChannelContext`](https://github.com/shopware/shopware/blob/trunk/src/Core/System/SalesChannel/SalesChannelContext.php)<br>context: [`Shopware\Core\Framework\Context`](https://github.com/shopware/shopware/blob/trunk/src/Core/Framework/Context.php)<br> |
| **Available Services** | [repository](./data-loading-script-services-reference#RepositoryFacade)<br>[price](./cart-manipulation-script-services-reference#PriceFactory)<br>[config](./miscellaneous-script-services-reference#SystemConfigFacade)<br>[store](./data-loading-script-services-reference#SalesChannelRepositoryFacade)<br> |
| **Stoppable** | `false` |


<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Webhook/Hookable/HookableEventCollector.php","WATCHER_HASH":"c8d1e5be8efb3ab8e06e434be1330489"} -->
2 changes: 2 additions & 0 deletions snippets/guide/app_database_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ composer req symfony/maker-bundle migrations
```

And create your first migration using `bin/console make:migration` (which is using the `AbstractShop` Class) and apply it to your database with `bin/console doctrine:migrations:migrate`.

<!-- {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Resources/config/packages/shopware.yaml","WATCHER_HASH":"183f85ba8f15e8e7d0006b70be20940f","WATCHER_CONTAINS":"html_sanitizer"} -->

0 comments on commit a9f8e64

Please sign in to comment.