-
Notifications
You must be signed in to change notification settings - Fork 0
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
Deploy to Dawn Staging Theme [Aligent's Shopify Test Store] #1
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
THEME_PATH=theme | ||
IMAGE_NAME=naturally-sweet-shopify | ||
CONTAINER_NAME=naturally-sweet-shopify_cli-container | ||
SHOPIFY_STORE=coffeeequalslife.myshopify.com | ||
THEME_PRODUCTION_ID=157104111920 | ||
THEME_STAGING_ID=170306994480 | ||
FAIL_LEVEL=crash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
name: Naturally Sweet Shopify Theme Deployment | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'feature/*' # Trigger for feature branches for theme checks | ||
- staging # Trigger for the staging branch to push as unpublished | ||
- main # Trigger for the main branch to publish the theme | ||
|
||
jobs: | ||
theme-check: | ||
runs-on: ubuntu-latest | ||
if: github.ref_name == 'main' || github.ref_name == 'staging' || startsWith(github.ref_name, 'feature/') | ||
container: | ||
image: aaronmedinaaligent/shopify-cli-base:latest | ||
credentials: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_SECRET_KEY }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most GHA default actions are |
||
|
||
- name: Verify Ruby Installation | ||
run: ruby -v | ||
|
||
- name: Verify Node.js Installation | ||
run: | | ||
node -v | ||
npm -v | ||
|
||
- name: Verify Shopify CLI Installation | ||
run: shopify version | ||
|
||
- name: List files in current directory | ||
run: | | ||
echo "Current directory: $(pwd)" | ||
ls -al | ||
|
||
- name: Read variables from file | ||
run: | | ||
# Check if the file exists | ||
if [ ! -f .env ]; then | ||
echo "Error: .env file not found!" | ||
exit 1 | ||
fi | ||
|
||
# Read each line from .env, ignoring comments and empty lines, and add to GitHub environment | ||
while IFS= read -r line || [ -n "$line" ]; do | ||
# Skip empty lines and lines that start with # | ||
[[ -z "$line" || "$line" =~ ^# ]] && continue | ||
|
||
# Print each line being processed for debugging | ||
echo "Processing line: $line" | ||
|
||
# Add to GitHub environment | ||
echo "$line" >> $GITHUB_ENV | ||
done < .env | ||
|
||
- name: Check /theme Directory Exists | ||
run: | | ||
if [ ! -d "./theme" ]; then | ||
echo "/theme directory does not exist." | ||
exit 1 | ||
fi | ||
echo "/theme directory exists." | ||
|
||
- name: List Files in /theme | ||
run: find theme -exec ls -ld --time-style=long-iso {} \; | awk '{print $6, $7, $8, $9}' | ||
|
||
- name: Run Shopify Theme Check | ||
run: shopify theme check --fail-level=$FAIL_LEVEL --path=$THEME_PATH | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: theme-check # Ensure deploy only runs if theme-check is successful | ||
if: github.ref_name == 'main' || github.ref_name == 'staging' | ||
container: | ||
image: aaronmedinaaligent/shopify-cli-base:latest | ||
credentials: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_SECRET_KEY }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Verify Ruby Installation | ||
run: ruby -v | ||
|
||
- name: Verify Node.js Installation | ||
run: | | ||
node -v | ||
npm -v | ||
|
||
- name: Verify Shopify CLI Installation | ||
run: shopify version | ||
|
||
- name: List files in current directory | ||
run: | | ||
echo "Current directory: $(pwd)" | ||
ls -al | ||
|
||
- name: Read variables from file | ||
run: | | ||
# Check if the file exists | ||
if [ ! -f .env ]; then | ||
echo "Error: .env file not found!" | ||
exit 1 | ||
fi | ||
|
||
# Read each line from .env, ignoring comments and empty lines, and add to GitHub environment | ||
while IFS= read -r line || [ -n "$line" ]; do | ||
# Skip empty lines and lines that start with # | ||
[[ -z "$line" || "$line" =~ ^# ]] && continue | ||
|
||
# Print each line being processed for debugging | ||
echo "Processing line: $line" | ||
|
||
# Add to GitHub environment | ||
echo "$line" >> $GITHUB_ENV | ||
done < .env | ||
|
||
- name: Check /theme Directory Exists | ||
run: | | ||
if [ ! -d "./theme" ]; then | ||
echo "/theme directory does not exist." | ||
exit 1 | ||
fi | ||
echo "/theme directory exists." | ||
|
||
- name: List Files in /theme | ||
run: find theme -exec ls -ld --time-style=long-iso {} \; | awk '{print $6, $7, $8, $9}' | ||
|
||
- name: Deploy Theme | ||
shell: bash | ||
run: | | ||
if [[ "${GITHUB_REF_NAME}" == "staging" ]]; then | ||
echo -e "Deploying to \033[36mSTAGING\033[0m..." | ||
shopify theme push --store="$SHOPIFY_STORE" --password="$SHOPIFY_ACCESS_TOKEN" --theme="$THEME_STAGING_ID" --path=$THEME_PATH --verbose --nodelete | ||
elif [[ "${GITHUB_REF_NAME}" == "main" ]]; then | ||
echo -e "Deploying to \033[36mPRODUCTION\033[0m..." | ||
shopify theme push --store="$SHOPIFY_STORE" --password="$SHOPIFY_ACCESS_TOKEN" --theme="$THEME_PRODUCTION_ID" --path=$THEME_PATH --verbose --allow-live | ||
fi | ||
|
||
env: | ||
SHOPIFY_ACCESS_TOKEN: ${{ secrets.SHOPIFY_ACCESS_TOKEN }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# prevent .access_token from being committed | ||
.access_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Use the custom base image with Ruby, Node.js, npm, and Shopify CLI pre-installed | ||
FROM aaronmedinaaligent/shopify-cli-base:latest | ||
|
||
# Set build arguments for user ID and group ID | ||
ARG USER_ID | ||
ARG GROUP_ID | ||
|
||
# Create a group and user matching the host UID and GID to avoid permission issues | ||
RUN groupadd -g $GROUP_ID shopifygroup && \ | ||
useradd -u $USER_ID -g shopifygroup -m shopifyuser | ||
|
||
# Create the /theme directory and set the correct permissions | ||
RUN mkdir -p /theme && chown shopifyuser:shopifygroup /theme | ||
|
||
# Install xdg-utils for opening URLs | ||
RUN apt-get update && apt-get install -y xdg-utils | ||
|
||
# Modify permissions during the build process | ||
RUN chown -R shopifyuser:shopifygroup /usr/local/lib/node_modules/@shopify/cli/dist/assets/cli-ruby | ||
|
||
# Set the working directory | ||
WORKDIR /theme | ||
|
||
# Switch to the non-root user for security | ||
USER shopifyuser | ||
|
||
# Verify installations | ||
RUN node -v && npm -v && ruby -v && bundler -v && shopify version && xdg-open --version | ||
|
||
# Default command to keep the container running in an interactive shell | ||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Load common utility functions and variables | ||
source "$(dirname "$0")/utils.sh" | ||
|
||
# Navigate to the project directory | ||
navigate_to_project | ||
|
||
# Load environment variables | ||
load_env | ||
|
||
# Check if IMAGE_NAME variable is set | ||
check_variable "IMAGE_NAME" | ||
|
||
# Build the Docker image with the current user's UID and GID | ||
echo -e "Building Docker image '$IMAGE_NAME' with USER_ID=$(id -u) and GROUP_ID=$(id -g)..." | ||
docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --progress=plain -t "$IMAGE_NAME" . | ||
|
||
# Check if the build was successful | ||
if [ $? -eq 0 ]; then | ||
echo -e "Docker image '$IMAGE_NAME' built successfully." | ||
else | ||
echo -e "Failed to build Docker image '$IMAGE_NAME'." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# Load common utility functions and variables | ||
source "$(dirname "$0")/utils.sh" | ||
|
||
# Navigate to the project directory | ||
navigate_to_project | ||
|
||
# Load environment variables | ||
load_env | ||
|
||
# Check if SHOPIFY_STORE and CONTAINER_NAME variables are set | ||
check_variable "SHOPIFY_STORE" | ||
check_variable "CONTAINER_NAME" | ||
|
||
# Run the Shopify theme development command inside the container | ||
docker exec -it "$CONTAINER_NAME" shopify theme dev --store="$SHOPIFY_STORE" --password="$SHOPIFY_ACCESS_TOKEN" --nodelete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# Load common utility functions and variables | ||
source "$(dirname "$0")/shopify-utils.sh" | ||
|
||
# Navigate to the project directory | ||
navigate_to_project | ||
|
||
# Load environment variables | ||
load_env | ||
|
||
# Check if required variables are set | ||
check_variable "SHOPIFY_STORE" | ||
check_variable "SHOPIFY_ACCESS_TOKEN" | ||
|
||
# Fetch detailed theme information using the Shopify Admin API | ||
curl -s -X GET "https://$SHOPIFY_STORE/admin/api/2023-07/themes.json" \ | ||
-H "X-Shopify-Access-Token: $SHOPIFY_ACCESS_TOKEN" | jq . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# Load common utility functions and variables | ||
source "$(dirname "$0")/utils.sh" | ||
|
||
# Navigate to the project directory | ||
navigate_to_project | ||
|
||
# Load environment variables | ||
load_env | ||
|
||
# Check if SHOPIFY_STORE and CONTAINER_NAME variables are set | ||
check_variable "SHOPIFY_STORE" | ||
check_variable "CONTAINER_NAME" | ||
|
||
# Check if the container is already running | ||
if is_container_running "$CONTAINER_NAME"; then | ||
echo -e "\n\nContainer ${YELLOW}$CONTAINER_NAME${RESET} is already running." | ||
else | ||
# Check if the container exists but is stopped | ||
if docker ps -aq -f name="$CONTAINER_NAME" | grep -q .; then | ||
start_existing_container "$CONTAINER_NAME" | ||
else | ||
run_new_container "$CONTAINER_NAME" | ||
|
||
# Check if the container started successfully | ||
if [ $? -eq 0 ]; then | ||
echo -e "\n\nContainer ${YELLOW}'$CONTAINER_NAME'${RESET} is running in detached mode." | ||
else | ||
echo -e "\n\n${RED}FAILED${RESET} to start the container." | ||
exit 1 | ||
fi | ||
fi | ||
fi | ||
|
||
echo -e "\nUse the following command to execute commands inside the container:" | ||
echo -e "\n${GREEN}docker exec -it $CONTAINER_NAME <command>${RESET}" | ||
echo -e "\n\nFor example, to start Shopify theme dev:" | ||
echo -e "\n${GREEN}docker exec -it $CONTAINER_NAME shopify theme dev --store='$SHOPIFY_STORE' --verbose${RESET}" | ||
echo -e "\n\nSHOPIFY_STORE: ${YELLOW}$SHOPIFY_STORE${RESET}" | ||
echo -e "\nTHEME_PRODUCTION_ID: ${YELLOW}$THEME_PRODUCTION_ID${RESET}" | ||
echo -e "\nTHEME_STAGING_ID: ${YELLOW}$THEME_STAGING_ID${RESET}\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Load common utility functions and variables | ||
source "$(dirname "$0")/utils.sh" | ||
|
||
# Navigate to the project directory | ||
navigate_to_project | ||
|
||
# Load environment variables | ||
load_env | ||
|
||
# Check if CONTAINER_NAME variable is set | ||
check_variable "CONTAINER_NAME" | ||
|
||
# Check if the container is running | ||
if is_container_running "$CONTAINER_NAME"; then | ||
echo -e "Stopping and removing the container ${YELLOW}$CONTAINER_NAME${RESET}...\n" | ||
|
||
# Stop the running container | ||
docker stop "$CONTAINER_NAME" | ||
|
||
# Remove the container | ||
docker rm "$CONTAINER_NAME" | ||
|
||
echo -e "Container ${YELLOW}$CONTAINER_NAME${RESET} has been stopped and removed.\n" | ||
else | ||
echo -e "Container ${YELLOW}$CONTAINER_NAME${RESET} is not running.\n" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
|
||
# Load common utility functions and variables | ||
source "$(dirname "$0")/utils.sh" | ||
|
||
# Navigate to the project directory | ||
navigate_to_project | ||
|
||
# Load environment variables | ||
load_env | ||
|
||
# Check if SHOPIFY_STORE and CONTAINER_NAME variables are set | ||
check_variable "SHOPIFY_STORE" | ||
check_variable "CONTAINER_NAME" | ||
|
||
# Check if the container is already running | ||
if is_container_running "$CONTAINER_NAME"; then | ||
echo "Container '${YELLOW}$CONTAINER_NAME${RESET}' is already running." | ||
else | ||
# Check if the container exists but is stopped | ||
if docker ps -aq -f name="$CONTAINER_NAME" | grep -q .; then | ||
start_existing_container "$CONTAINER_NAME" | ||
else | ||
run_new_container "$CONTAINER_NAME" | ||
|
||
# Check if the container started successfully | ||
if [ $? -eq 0 ]; then | ||
echo -e "Container '${YELLOW}$CONTAINER_NAME${RESET}' is running in detached mode." | ||
else | ||
echo -e "Failed to start the container." | ||
exit 1 | ||
fi | ||
fi | ||
fi | ||
|
||
|
||
docker exec -it "$CONTAINER_NAME" shopify theme check --fail-level=$FAIL_LEVEL | ||
|
||
# Capture the exit code of the last command | ||
EXIT_CODE=$? | ||
|
||
|
||
# Optionally, handle the exit code | ||
if [ $EXIT_CODE -ne 0 ]; then | ||
echo -e "The theme check FAILED to pass the fail level = $FAIL_LEVEL" | ||
echo -e "Exit code: $EXIT_CODE" | ||
# Add any additional error handling or exit the script if needed | ||
exit $EXIT_CODE | ||
else | ||
echo -e "The theme check PASSED, ready for deployment!" | ||
|
||
fi |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My GHA might be dated, but I found this too sensitive in the past.
I have previously used the
pull_request
trigger instead and in the Job added a merge check to only run the job when the merge completed.