Skip to content

Commit a378859

Browse files
committed
Merge branch 'develop' into feature/retail-react-app-v5
2 parents 9da6085 + ca0bc0b commit a378859

File tree

128 files changed

+4205
-960
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+4205
-960
lines changed

.github/actions/changelog-check/action.yml

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: 'Changelog Check'
22
description: 'Check if changelog is updated for the changed packages'
33
inputs:
4-
github_token:
5-
description: 'GitHub token'
6-
required: true
74
pr_number:
85
description: 'Pull request number'
96
required: true
@@ -16,39 +13,26 @@ runs:
1613
with:
1714
fetch-depth: 0 # Fetch full history to access all commits
1815

19-
- name: Get Base Branch SHA
20-
id: get_base_sha
16+
- name: Determine Base SHA and Merge Base
17+
id: determine_base
2118
run: |
22-
if [ -n "${{ inputs.pr_number }}" ]; then
23-
BASE_SHA=$(curl -s -H "Authorization: token ${{ inputs.github_token }}" \
24-
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ inputs.pr_number }}" | \
25-
jq -r '.base.sha')
19+
if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
20+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
21+
MERGE_BASE=$(git merge-base $BASE_SHA ${{ github.sha }})
22+
echo "BASE_SHA=$BASE_SHA" >> $GITHUB_ENV
23+
echo "MERGE_BASE=$MERGE_BASE" >> $GITHUB_ENV
2624
else
27-
echo "Not running in a PR context. Skipping changelog check."
28-
echo "SKIP_CHANGELOG_CHECK=true" >> $GITHUB_ENV
29-
fi
30-
31-
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" == "null" ]; then
32-
echo "Unable to fetch base SHA or no base SHA available. Skipping changelog check."
25+
echo "Not running in a PR context or unable to determine base SHA. Skipping changelog check."
3326
echo "SKIP_CHANGELOG_CHECK=true" >> $GITHUB_ENV
34-
else
35-
echo "BASE_SHA=${BASE_SHA}" >> $GITHUB_ENV
3627
fi
3728
shell: bash
3829

39-
- name: Find merge base
40-
id: find_merge_base
30+
- name: Check if 'skip changelog' label is present
31+
id: check_labels
4132
run: |
42-
if [ -n "${{ env.BASE_SHA }}" ] && [ "${{ env.BASE_SHA }}" != "null" ]; then
43-
MERGE_BASE=$(git merge-base ${{ env.BASE_SHA }} ${{ github.sha }})
44-
if [ -z "$MERGE_BASE" ]; then
45-
echo "Unable to find merge base. Skipping changelog check."
46-
echo "SKIP_CHANGELOG_CHECK=true" >> $GITHUB_ENV
47-
else
48-
echo "MERGE_BASE=${MERGE_BASE}" >> $GITHUB_ENV
49-
fi
50-
else
51-
echo "Unable to make the merge base calculation due to missing or null BASE_SHA. Skipping changelog check."
33+
SKIP_CHANGELOG_LABEL="${{ contains(github.event.pull_request.labels.*.name, 'skip changelog') }}"
34+
if [ "$SKIP_CHANGELOG_LABEL" = "true" ]; then
35+
echo "Skip changelog label is present. Skipping changelog check."
5236
echo "SKIP_CHANGELOG_CHECK=true" >> $GITHUB_ENV
5337
fi
5438
shell: bash
@@ -58,20 +42,7 @@ runs:
5842
echo "Base SHA: ${{ env.BASE_SHA }}"
5943
echo "Current SHA: ${{ github.sha }}"
6044
echo "Merge Base: ${{ env.MERGE_BASE }}"
61-
shell: bash
62-
63-
- name: Fetch PR labels and check for skip changelog
64-
id: fetch_and_check_labels
65-
run: |
66-
PR_LABELS=$(curl -s -H "Authorization: token ${{ inputs.github_token }}" \
67-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ inputs.pr_number }}/labels" | \
68-
jq -r '.[].name | @sh' | tr '\n' ' ')
69-
echo "PR_LABELS=${PR_LABELS}" >> $GITHUB_ENV
70-
71-
if echo "${PR_LABELS}" | grep -q "'skip changelog'"; then
72-
echo "Skip changelog label is present. Skipping changelog check."
73-
echo "SKIP_CHANGELOG_CHECK=true" >> $GITHUB_ENV
74-
fi
45+
echo "SKIP_CHANGELOG_CHECK: ${{ env.SKIP_CHANGELOG_CHECK }}"
7546
shell: bash
7647

7748
- name: Check if changelog is updated
@@ -87,7 +58,7 @@ runs:
8758
PUBLIC_PACKAGES=("commerce-sdk-react" "pwa-kit-create-app" "pwa-kit-dev" "pwa-kit-react-sdk" "pwa-kit-runtime" "template-retail-react-app")
8859
8960
for PACKAGE in "${PUBLIC_PACKAGES[@]}"; do
90-
if echo "$CHANGED_FILES" | grep -i "^packages/$PACKAGE/"; then
61+
if echo "$CHANGED_FILES" | grep -iq "^packages/$PACKAGE/"; then
9162
if ! echo "$CHANGED_FILES" | grep -iq "^packages/$PACKAGE/CHANGELOG.md"; then
9263
echo "CHANGELOG.md was not updated for package $PACKAGE. Please update the CHANGELOG.md or add 'skip changelog' label to the PR."
9364
exit 1
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: create_mrt_target
2+
description: Create MRT Environment
3+
inputs:
4+
project_id:
5+
description: "MRT Project ID"
6+
target_id:
7+
description: "MRT Target ID"
8+
proxy_configs:
9+
description: "Proxy Configs"
10+
mobify_api_key:
11+
description: "Mobify user API key"
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Initialize
17+
id: initialize
18+
shell: bash
19+
run: |
20+
set -e
21+
echo "TARGET_API_BASE_URL=https://cloud.mobify.com/api/projects/${{ inputs.project_id }}/target" >> $GITHUB_ENV
22+
23+
- name: Get target
24+
id: get_target
25+
shell: bash
26+
run: |-
27+
set -e
28+
response=$(curl --location --silent --show-error --write-out "HTTPSTATUS:%{http_code}" "$TARGET_API_BASE_URL/${{ inputs.target_id }}" \
29+
--header "Authorization: Bearer ${{ inputs.mobify_api_key }}")
30+
31+
http_status=$(echo $response | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
32+
echo "status=$http_status" >> $GITHUB_OUTPUT
33+
34+
if [ "$http_status" -eq 404 ]; then
35+
echo "MRT environment not found, it will be created in the next step."
36+
elif [ "$http_status" -eq 200 ]; then
37+
echo "MRT environment already exists."
38+
else
39+
echo "Error: Unexpected HTTP status: $http_status"
40+
exit 1
41+
fi
42+
43+
- name: Create target
44+
id: create_target
45+
if: ${{ steps.get_target.outputs.status == '404' }}
46+
shell: bash
47+
run: |-
48+
set -e
49+
proxy_config_json=$(echo ${{ inputs.proxy_configs }} | jq -r .)
50+
response=$(curl --location --silent --show-error --write-out "HTTPSTATUS:%{http_code}" "$TARGET_API_BASE_URL/" \
51+
--header "Authorization: Bearer ${{ inputs.mobify_api_key }}" \
52+
--header "Content-Type: application/json" \
53+
--data "$(jq -n \
54+
--arg name "${{ inputs.target_id }}" \
55+
--arg slug "${{ inputs.target_id }}" \
56+
--argjson ssr_proxy_configs "$proxy_config_json" \
57+
'{name: $name, slug: $slug, ssr_proxy_configs: $ssr_proxy_configs}')")
58+
59+
http_status=$(echo "$response" | sed -n 's/.*HTTPSTATUS://p')
60+
response_body=$(echo "$response" | sed -e 's/HTTPSTATUS:.*//g')
61+
62+
echo "status=$http_status" >> $GITHUB_OUTPUT
63+
64+
if [ "$http_status" -ne 201 ]; then
65+
echo "Request failed with status code $http_status"
66+
echo "Response Body: $response_body"
67+
exit 1
68+
fi
69+
70+
- name: Wait for target to be active
71+
id: wait_for_target
72+
if: ${{ steps.create_target.outputs.status == '201' }}
73+
shell: bash
74+
run: |-
75+
set -e
76+
max_attempts=30
77+
sleep_duration=30
78+
attempts=0
79+
80+
while [ $attempts -lt $max_attempts ]; do
81+
response=$(curl --location --silent --show-error --write-out "HTTPSTATUS:%{http_code}" "$TARGET_API_BASE_URL/${{ inputs.target_id }}" \
82+
--header "Authorization: Bearer ${{ inputs.mobify_api_key }}")
83+
84+
http_status=$(echo $response | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
85+
response_body=$(echo $response | sed -e 's/HTTPSTATUS\:.*//g')
86+
87+
if [ "$http_status" -ne 200 ]; then
88+
echo "Request failed with status code $http_status"
89+
exit 1
90+
fi
91+
92+
current_state=$(echo $response_body | jq -r '.state')
93+
94+
if [ "$current_state" == "ACTIVE" ]; then
95+
echo "Target is now ACTIVE."
96+
exit 0
97+
elif [ "$current_state" != "CREATE_IN_PROGRESS" ]; then
98+
echo "Unexpected target state: $current_state."
99+
exit 1
100+
fi
101+
102+
attempts=$((attempts + 1))
103+
echo "Waiting for target to be ACTIVE. Attempt $attempts/$max_attempts."
104+
sleep $sleep_duration
105+
done
106+
107+
echo "Target did not become active within the expected time."
108+
exit 1

.github/actions/datadog/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ runs:
99
steps:
1010
- name: Send metrics to Datadog
1111
run : |
12+
# For the datadog cli, it must be installed via python
13+
# to install python packages on CI environment, we must activate the virtual env
14+
# or otherwise it throws error: externally-managed-environment
15+
python3 -m venv venv
16+
source venv/bin/activate
17+
pip install datadog
18+
1219
# Add a dogrc so we can submit metrics to datadog
1320
printf "[Connection]\napikey = ${{inputs.datadog_api_key}}\nappkey =\n" > ~/.dogrc
1421
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: deploy_app
2+
description: Deploy application to MRT
3+
inputs:
4+
project_id:
5+
description: MRT Project ID
6+
target_id:
7+
description: MRT Target ID
8+
project_dir:
9+
description: Project Directory
10+
mobify_user:
11+
description: "Mobify user email"
12+
mobify_api_key:
13+
description: "Mobify user API key"
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Create MRT credentials file
18+
id: create_mrt_credentials
19+
uses: "./.github/actions/create_mrt"
20+
with:
21+
mobify_user: ${{ inputs.mobify_user }}
22+
mobify_api_key: ${{ inputs.mobify_api_key }}
23+
24+
- name: Read application config
25+
id: read_config
26+
shell: bash
27+
run: |
28+
# Read proxy configs from the default config file using Node.js
29+
config=$(node -e "console.log(JSON.stringify(require('${{ inputs.project_dir }}/config/default.js')))")
30+
# Extract proxyConfigs as a JSON string
31+
echo "proxy_configs=$(echo "$config" | jq -c '.ssrParameters.proxyConfigs' | jq @json)" >> $GITHUB_OUTPUT
32+
33+
34+
- name: Create MRT target
35+
id: create_mrt_target
36+
uses: "./.github/actions/create_mrt_target"
37+
with:
38+
project_id: ${{ inputs.project_id }}
39+
target_id: ${{ inputs.target_id }}
40+
proxy_configs: ${{ steps.read_config.outputs.proxy_configs }}
41+
mobify_api_key: ${{ inputs.mobify_api_key }}
42+
43+
44+
- name: Push bundle to MRT
45+
id: push_bundle
46+
uses: "./.github/actions/push_to_mrt"
47+
with:
48+
CWD: ${{ inputs.project_dir }}
49+
TARGET: ${{ inputs.target_id }}
50+
FLAGS: --wait

.github/actions/e2e_generate_app/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ runs:
88
using: composite
99
steps:
1010
- name: Generate new project based on project-key
11-
run: node e2e/scripts/generate-project.js ${{ inputs.PROJECT_KEY }}
11+
run: node e2e/scripts/generate-project.js --project-key ${{ inputs.PROJECT_KEY }}
1212
shell: bash
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: generate_app
2+
description: Generate Application
3+
inputs:
4+
use_extensibility:
5+
description: Use Extensibility?
6+
project_id:
7+
description: Project ID
8+
instance_url:
9+
description: Instance Url
10+
org_id:
11+
description: Org Id
12+
short_code:
13+
description: Short Code
14+
client_id:
15+
description: Client Id
16+
site_id:
17+
description: Site Id
18+
is_private_client:
19+
description: Is Private Client?
20+
setup_hybrid:
21+
description: Setup Phased Headless rollout?
22+
project_dir:
23+
description: Project Directory
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: Parse input values
29+
id: parse_input
30+
shell: bash
31+
run: |
32+
use_extensibility_input="${{ inputs.use_extensibility }}"
33+
if [ "use_extensibility_input" = "true" ]; then
34+
use_extensibility_value=2
35+
else
36+
use_extensibility_value=1
37+
fi
38+
echo "USE_EXTENSIBILITY_VALUE=$use_extensibility_value" >> $GITHUB_ENV
39+
40+
is_private_client_input="${{ inputs.is_private_client }}"
41+
if [ "$is_private_client_input" = "true" ]; then
42+
is_private_client_value=1
43+
else
44+
is_private_client_value=2
45+
fi
46+
echo "IS_PRIVATE_CLIENT_VALUE=$is_private_client_value" >> $GITHUB_ENV
47+
48+
setup_hybrid_input="${{ inputs.setup_hybrid }}"
49+
if [ "$setup_hybrid_input" = "true" ]; then
50+
setup_hybrid_value=2
51+
else
52+
setup_hybrid_value=1
53+
fi
54+
echo "SETUP_HYBRID_VALUE=$setup_hybrid_value" >> $GITHUB_ENV
55+
56+
- name: Build project generator inputs
57+
id: build_generator_inputs
58+
shell: bash
59+
run: |
60+
echo '{
61+
"projectDir":"${{ inputs.project_dir }}",
62+
"responses": [
63+
{
64+
"expectedPrompt": "Choose a project preset to get started:",
65+
"response": "1\n"
66+
},
67+
{
68+
"expectedPrompt": "Do you wish to use template extensibility?",
69+
"response": "${{ env.USE_EXTENSIBILITY_VALUE }}\n"
70+
},
71+
{
72+
"expectedPrompt": "What is the name of your Project?",
73+
"response": "${{ inputs.project_id }}\n"
74+
},
75+
{
76+
"expectedPrompt": "What is the URL for your Commerce Cloud instance?",
77+
"response": "${{ inputs.instance_url }}\n"
78+
},
79+
{
80+
"expectedPrompt": "What is your SLAS Client ID?",
81+
"response": "${{ inputs.client_id }}\n"
82+
},
83+
{
84+
"expectedPrompt": "Is your SLAS client private?",
85+
"response":"${{ env.IS_PRIVATE_CLIENT_VALUE }}\n"
86+
},
87+
{
88+
"expectedPrompt": "What is your Site ID in Business Manager?",
89+
"response": "${{ inputs.site_id }}\n"
90+
},
91+
{
92+
"expectedPrompt": "What is your Commerce API organization ID in Business Manager?",
93+
"response": "${{ inputs.org_id }}\n"
94+
},
95+
{
96+
"expectedPrompt": "What is your Commerce API short code in Business Manager?",
97+
"response": "${{ inputs.short_code }}\n"
98+
},
99+
{
100+
"expectedPrompt": "Do you wish to set up a phased headless rollout?",
101+
"response": "${{ env.SETUP_HYBRID_VALUE }}\n"
102+
}
103+
] }' > generator-responses.json
104+
105+
- name: Generate project
106+
id: generate_project
107+
run: |
108+
cat generator-responses.json
109+
node e2e/scripts/generate-project.js --project-config "$(jq -c . generator-responses.json)"
110+
shell: bash
111+
112+
- name: Build generated project
113+
id: build_generated_project
114+
working-directory: ../generated-projects/${{ inputs.project_dir }}
115+
run: |-
116+
npm ci
117+
npm run build
118+
shell: bash

0 commit comments

Comments
 (0)