Skip to content
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

let php give extensions #436

Merged
merged 2 commits into from
Nov 12, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Login into Docker Hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
run: echo "${{ secrets.DOCKER_HUB_SHOPWARE_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_SHOPWARE_USERNAME }} --password-stdin

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
Expand Down
95 changes: 90 additions & 5 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dockers:
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
build_flag_templates:
- "--build-arg=PHP_VERSION=8.3"
- "--platform=linux/amd64"
Expand All @@ -60,6 +61,7 @@ dockers:
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
build_flag_templates:
- "--build-arg=PHP_VERSION=8.2"
- "--platform=linux/amd64"
Expand All @@ -69,6 +71,7 @@ dockers:
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.1-amd64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.1-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.1-amd64"
build_flag_templates:
- "--build-arg=PHP_VERSION=8.1"
- "--platform=linux/amd64"
Expand All @@ -80,6 +83,7 @@ dockers:
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"
build_flag_templates:
- "--build-arg=PHP_VERSION=8.3"
- "--platform=linux/arm64"
Expand All @@ -89,6 +93,7 @@ dockers:
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"
build_flag_templates:
- "--build-arg=PHP_VERSION=8.2"
- "--platform=linux/arm64"
Expand All @@ -98,10 +103,29 @@ dockers:
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.1-arm64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.1-arm64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.1-arm64"
build_flag_templates:
- "--build-arg=PHP_VERSION=8.1"
- "--platform=linux/arm64"

- use: buildx
goos: linux
goarch: amd64
dockerfile: Dockerfile.bin
image_templates:
- "shopware/shopware-cli:bin-{{ .Tag }}-amd64"
build_flag_templates:
- "--platform=linux/amd64"

- use: buildx
goos: linux
goarch: arm64
dockerfile: Dockerfile.bin
image_templates:
- "shopware/shopware-cli:bin-{{ .Tag }}-arm64"
build_flag_templates:
- "--platform=linux/arm64"

docker_manifests:
# GHCR
- name_template: ghcr.io/friendsofshopware/shopware-cli:latest
Expand All @@ -126,8 +150,13 @@ docker_manifests:

- name_template: ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"

- name_template: ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3
image_templates:
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"

- name_template: ghcr.io/friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2
image_templates:
Expand Down Expand Up @@ -162,8 +191,13 @@ docker_manifests:

- name_template: friendsofshopware/shopware-cli:{{ .Tag }}
image_templates:
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"

- name_template: friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3
image_templates:
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"

- name_template: friendsofshopware/shopware-cli:{{ .Tag }}-php-8.2
image_templates:
Expand All @@ -175,6 +209,57 @@ docker_manifests:
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.1-amd64"
- "friendsofshopware/shopware-cli:{{ .Tag }}-php-8.1-arm64"

# Shopware Docker Hub
- name_template: shopware/shopware-cli:latest
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"

- name_template: shopware/shopware-cli:latest-php-8.3
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"

- name_template: shopware/shopware-cli:latest-php-8.2
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"

- name_template: shopware/shopware-cli:latest-php-8.1
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.1-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.1-arm64"

- name_template: shopware/shopware-cli:{{ .Tag }}
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"

- name_template: shopware/shopware-cli:{{ .Tag }}-php-8.3
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.3-arm64"

- name_template: shopware/shopware-cli:{{ .Tag }}-php-8.2
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.2-arm64"

- name_template: shopware/shopware-cli:{{ .Tag }}-php-8.1
image_templates:
- "shopware/shopware-cli:{{ .Tag }}-php-8.1-amd64"
- "shopware/shopware-cli:{{ .Tag }}-php-8.1-arm64"

- name_template: shopware/shopware-cli:bin-{{ .Tag }}
image_templates:
- "shopware/shopware-cli:bin-{{ .Tag }}-amd64"
- "shopware/shopware-cli:bin-{{ .Tag }}-arm64"

- name_template: shopware/shopware-cli:bin
image_templates:
- "shopware/shopware-cli:bin-{{ .Tag }}-amd64"
- "shopware/shopware-cli:bin-{{ .Tag }}-arm64"

sboms:
- artifacts: archive
- id: source
Expand Down Expand Up @@ -219,7 +304,7 @@ aurs:
description: A cli which contains handy helpful commands for daily Shopware tasks
license: MIT
maintainers:
- "Soner Sayakci <[email protected]>"
- "Soner Sayakci <[email protected]>"
- "Max <[email protected]>"
private_key: '{{ .Env.AUR_KEY }}'
commit_author:
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM scratch
COPY shopware-cli /
ENTRYPOINT ["/shopware-cli"]
CMD ["--help"]
6 changes: 5 additions & 1 deletion cmd/project/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ func findClosestShopwareProject() (string, error) {
}

func filterAndWritePluginJson(cmd *cobra.Command, projectRoot string, shopCfg *shop.Config) error {
sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
sources, err := extension.DumpAndLoadAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

if err != nil {
return err
}

cfgs := extension.BuildAssetConfigFromExtensions(cmd.Context(), sources, extension.AssetBuildConfig{})

Expand Down
10 changes: 9 additions & 1 deletion cmd/project/project_admin_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ var projectAdminBuildCmd = &cobra.Command{

logging.FromContext(cmd.Context()).Infof("Looking for extensions to build assets in project")

sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "feature:dump"), projectRoot)); err != nil {
return err
}

sources, err := extension.DumpAndLoadAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

if err != nil {
return err
}

forceInstall, _ := cmd.PersistentFlags().GetBool("force-install-dependencies")

Expand Down
10 changes: 9 additions & 1 deletion cmd/project/project_storefront_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ var projectStorefrontBuildCmd = &cobra.Command{

logging.FromContext(cmd.Context()).Infof("Looking for extensions to build assets in project")

sources := extension.FindAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "feature:dump"), projectRoot)); err != nil {
return err
}

sources, err := extension.DumpAndLoadAssetSourcesOfProject(cmd.Context(), projectRoot, shopCfg)

if err != nil {
return err
}

forceInstall, _ := cmd.PersistentFlags().GetBool("force-install-dependencies")

Expand Down
47 changes: 47 additions & 0 deletions extension/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -98,6 +99,7 @@ func getProjectConstraintFromKernel(project string) (*version.Constraints, error
return &v, nil
}

// FindAssetSourcesOfProject This finds all assets without invoking any PHP function and thinks all plugins / apps are active. Optional for CI usage.
func FindAssetSourcesOfProject(ctx context.Context, project string, shopCfg *shop.Config) []asset.Source {
extensions := FindExtensionsFromProject(ctx, project)
sources := ConvertExtensionsToSources(ctx, extensions)
Expand Down Expand Up @@ -152,6 +154,51 @@ func FindAssetSourcesOfProject(ctx context.Context, project string, shopCfg *sho
return sources
}

func DumpAndLoadAssetSourcesOfProject(ctx context.Context, project string, shopCfg *shop.Config) ([]asset.Source, error) {
dumpExec := phpexec.ConsoleCommand(ctx, "bundle:dump")
dumpExec.Dir = project
dumpExec.Stdin = os.Stdin
dumpExec.Stdout = os.Stdout
dumpExec.Stderr = os.Stderr

if err := dumpExec.Run(); err != nil {
return nil, fmt.Errorf("could not bundle features: %w", err)
}

var pluginsJson map[string]ExtensionAssetConfigEntry

pluginJsonBytes, err := os.ReadFile(path.Join(project, "var", "plugins.json"))

if err != nil {
return nil, fmt.Errorf("could not read plugins.json: %w", err)
}

if err := json.Unmarshal(pluginJsonBytes, &pluginsJson); err != nil {
return nil, fmt.Errorf("could not parse plugins.json: %w", err)
}

var sources []asset.Source

for name, entry := range pluginsJson {
if entry.Administration.EntryFilePath != nil || entry.Storefront.EntryFilePath != nil {
source := asset.Source{
Name: name,
Path: entry.BasePath,
}

if extensionCfg, err := readExtensionConfig(path.Join(project, entry.BasePath)); err == nil {
source.AdminEsbuildCompatible = extensionCfg.Build.Zip.Assets.EnableESBuildForAdmin
source.StorefrontEsbuildCompatible = extensionCfg.Build.Zip.Assets.EnableESBuildForStorefront
source.NpmStrict = extensionCfg.Build.Zip.Assets.NpmStrict
}

sources = append(sources, source)
}
}

return sources, nil
}

func FindExtensionsFromProject(ctx context.Context, project string) []Extension {
extensions := make(map[string]Extension)

Expand Down