Skip to content

Commit 883e6d0

Browse files
committed
refactor: use one resolve step
1 parent d7199f7 commit 883e6d0

File tree

2 files changed

+52
-53
lines changed

2 files changed

+52
-53
lines changed

build-frontend/action.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ inputs:
3838
description: 'Image provider (only for Nuxt)'
3939
required: false
4040
default: 'ipx'
41-
extra_docker_envs:
41+
docker_buildargs:
4242
description: 'List of additional ENVs that should be passed at Docker image build-time'
4343
required: false
4444
runs:
@@ -55,16 +55,20 @@ runs:
5555
username: ${{ inputs.cloud_username }}
5656
password: ${{ inputs.cloud_password }}
5757

58-
- name: Resolve docker envs
59-
id: docker_envs
58+
- name: Resolve docker buildargs
59+
id: resolve
6060
uses: actions/github-script@v7
6161
env:
6262
INPUT_NPM_EMAIL: ${{ inputs.npm_email }}
6363
INPUT_NPM_PASS: ${{ inputs.npm_pass }}
6464
INPUT_NPM_USER: ${{ inputs.npm_user }}
6565
INPUT_NPM_REGISTRY: ${{ inputs.npm_registry }}
6666
INPUT_IMAGE_PROVIDER: ${{ inputs.image_provider }}
67-
INPUT_EXTRA_DOCKER_ENVS: ${{ inputs.extra_docker_envs }}
67+
INPUT_DOCKER_BUILDARGS: ${{ inputs.docker_buildargs }}
68+
INPUT_FRONTEND: ${{ inputs.frontend }}
69+
INPUT_VERSION: ${{ inputs.version }}
70+
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker_registry_url }}
71+
INPUT_PROJECT_NAME: ${{ inputs.project_name }}
6872
with:
6973
script: |
7074
const base = {
@@ -75,38 +79,34 @@ runs:
7579
'NUXT_IMAGE_PROVIDER': core.getInput('image_provider'),
7680
};
7781
78-
const transformedBaseEnv = Object.entries(base)
82+
const transformedBaseArgs = Object.entries(base)
7983
.map(([key, value]) => `${key}=${value}`);
8084
81-
const extraEnvs = core.getMultilineInput('extra_docker_envs', { required: false });
82-
const mergedEnvs = [
83-
...transformedBaseEnv,
84-
...extraEnvs,
85-
]
85+
const extraArgs = core.getMultilineInput('docker_buildargs', { required: false });
86+
const mergedArgs = [
87+
...transformedBaseArgs
88+
...extraArgs,
89+
];
8690
87-
core.setOutput('envs', mergedEnvs);
91+
core.setOutput('docker_args', mergedArgs);
8892
89-
- name: Resolve values of the versions, docker ref & dockerfile path
90-
id: resolve
91-
shell: bash
92-
run: |
93-
# Set the version of the app based on user input or use git commit hash
94-
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
95-
# Set the reference address for app in docker registry
96-
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
97-
# Set the path to the Dockerfile base on selected frontend framework
98-
if [[ $FRONTEND == "next" ]]; then
99-
echo "path=.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
100-
elif [[ $FRONTEND == "nextjs" ]]; then
101-
echo "path=.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
102-
elif [[ $FRONTEND == "nuxt" ]]; then
103-
echo "path=.vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
104-
else
105-
echo "Error: Unsupported FRONTEND value. Valid options are 'next' or 'nuxt'."
106-
exit 1
107-
fi
108-
env:
109-
FRONTEND: ${{ inputs.frontend }}
93+
const versionInput = core.getIntput('version');
94+
core.setOutput('version', versionInput || context.sha);
95+
96+
core.setOutput('ref', `${core.getInput('docker_registry_url')}/${core.getInput('project_name')}-storefrontcloud-io`);
97+
98+
const frontendInput = core.getInput('frontend');
99+
100+
switch (frontend) {
101+
case "next":
102+
core.setOutput('path', '.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend');
103+
break;
104+
case "nuxt":
105+
core.setOutput('path', '.vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend');
106+
break;
107+
default:
108+
core.setOutput('path', '.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend')
109+
}
110110
111111
- name: Check for existing image
112112
id: check-existing-image
@@ -126,4 +126,4 @@ runs:
126126
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront:${{ steps.resolve.outputs.version }}
127127
cache-from: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront:buildcache"
128128
cache-to: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront:buildcache,mode=max"
129-
build-args: ${{ steps.docker_envs.envs }}
129+
build-args: ${{ steps.resolve.outputs.docker_args }}

build-middleware/action.yml

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ inputs:
3030
version:
3131
description: 'Version of the app'
3232
required: false
33-
extra_docker_envs:
33+
docker_buildargs:
3434
description: 'List of additional ENVs that should be passed at Docker image build-time'
3535
required: false
3636
runs:
@@ -47,15 +47,18 @@ runs:
4747
username: ${{ inputs.cloud_username }}
4848
password: ${{ inputs.cloud_password }}
4949

50-
- name: Resolve docker envs
51-
id: docker_envs
50+
- name: Resolve docker buildargs
51+
id: resolve
5252
uses: actions/github-script@v7
5353
env:
5454
INPUT_NPM_EMAIL: ${{ inputs.npm_email }}
5555
INPUT_NPM_PASS: ${{ inputs.npm_pass }}
5656
INPUT_NPM_USER: ${{ inputs.npm_user }}
5757
INPUT_NPM_REGISTRY: ${{ inputs.npm_registry }}
58-
INPUT_EXTRA_DOCKER_ENVS: ${{ inputs.extra_docker_envs }}
58+
INPUT_DOCKER_BUILDARGS: ${{ inputs.docker_buildargs }}
59+
INPUT_VERSION: ${{ inputs.version }}
60+
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker_registry_url }}
61+
INPUT_PROJECT_NAME: ${{ inputs.project_name }}
5962
with:
6063
script: |
6164
const base = {
@@ -65,25 +68,21 @@ runs:
6568
'NPM_REGISTRY': core.getInput('npm_registry'),
6669
};
6770
68-
const transformedBaseEnv = Object.entries(base)
71+
const transformedBaseArgs = Object.entries(base)
6972
.map(([key, value]) => `${key}=${value}`);
7073
71-
const extraEnvs = core.getMultilineInput('extra_docker_envs', { required: false });
72-
const mergedEnvs = [
73-
...transformedBaseEnv,
74-
...extraEnvs,
75-
]
74+
const extraBuildArgs = core.getMultilineInput('docker_buildargs', { required: false });
75+
const mergedBuildArgs = [
76+
...transformedBaseArgs,
77+
...extraBuildArgs,
78+
];
7679
77-
core.setOutput('envs', mergedEnvs);
80+
core.setOutput('docker_args', mergedBuildArgs);
7881
79-
- name: Resolve values of the versions, docker ref & dockerfile path
80-
id: resolve
81-
shell: bash
82-
run: |
83-
# Set the version of the app based on user input or use git commit hash
84-
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
85-
# Set the reference address for app in docker registry
86-
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
82+
const versionInput = core.getIntput('version');
83+
core.setOutput('version', versionInput || context.sha);
84+
85+
core.setOutput('ref', `${core.getInput('docker_registry_url')}/${core.getInput('project_name')}-storefrontcloud-io`);
8786
8887
- name: Check for existing image
8988
id: check-existing-image
@@ -103,4 +102,4 @@ runs:
103102
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:${{ steps.resolve.outputs.version }}
104103
cache-from: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:buildcache"
105104
cache-to: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:buildcache,mode=max"
106-
build-args: ${{ steps.docker_envs.envs }}
105+
build-args: ${{ steps.resolve.outputs.docker_args }}

0 commit comments

Comments
 (0)