Skip to content

Commit

Permalink
feat: updating the script to not run unit tests and better debugging …
Browse files Browse the repository at this point in the history
…for package creation
  • Loading branch information
actions-user committed Aug 20, 2024
1 parent 41c3a67 commit e3fe214
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 43 deletions.
39 changes: 10 additions & 29 deletions .github/workflows/package-version-creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ jobs:
with:
node-version: '20'

- name: Install jq
run: sudo apt-get install jq
- name: Install yq
run: sudo snap install yq

- name: Make script executable
run: chmod +x scripts/update-app-info-version.sh
- name: Make scripts executable
run: |
chmod +x scripts/update-app-info-version.sh
chmod +x scripts/create-new-package-version.sh
- name: Verify And Update App Version
run: scripts/update-app-info-version.sh
Expand All @@ -41,33 +43,12 @@ jobs:
run: sf org login sfdx-url -f secret.json --set-default-dev-hub

- name: Create Package Version
run: |
PACKAGE_VERSION_ID=$(sf package version create -p "Adyen Salesforce Order Management" -c -k Payments@Adyen --json | jq -r '.result.Id')
echo "PACKAGE_VERSION_ID=$PACKAGE_VERSION_ID" >> $GITHUB_ENV
- name: Poll for Package Creation Status
run: |
while true; do
STATUS=$(sf package version report --package "$PACKAGE_VERSION_ID" --json | jq -r '.result.Status')
if [ "$STATUS" == "Success" ]; then
echo "Package creation completed successfully."
break
elif [ "$STATUS" == "Error" ]; then
echo "Package creation failed."
exit 1
else
echo "Package creation is in progress. Current status: $STATUS"
fi
# Wait for 2 minutes before checking again
sleep 120
done
env:
MAX_ATTEMPTS: ${{ vars.MAX_ATTEMPTS }}
run: scripts/create-new-package-version.sh

- name: Commit Modified Files
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git add sfdx-project.json
git commit -m "chore: Update sfdx-project.json with new package version id: $PACKAGE_VERSION_ID"
git commit -m "Update sfdx-project.json and "
git push origin "$GITHUB_REF"
3 changes: 1 addition & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ on:
branches:
- '**'
branches-ignore:
- release/*
- Release/*
- main

jobs:
build-and-deploy:
Expand Down
54 changes: 54 additions & 0 deletions scripts/create-new-package-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Create the package version and capture both the result and any error
PACKAGE_CREATION_RESULT=$(sf package version create -p "Adyen Salesforce Order Management" -c -k Payments@Adyen --json)

# Extract the package version ID (if available) or handle errors
PACKAGE_VERSION_ID=$(echo "$PACKAGE_CREATION_RESULT" | yq -r '.result.Id')

# Check if the PACKAGE_VERSION_ID is null or empty
if [[ "$PACKAGE_VERSION_ID" == "null" || -z "$PACKAGE_VERSION_ID" ]]; then
# Extract the error message from the returned JSON
ERROR_MESSAGE=$(echo "$PACKAGE_CREATION_RESULT" | yq -r '.message')
echo "Error: Package version creation failed. Error message: $ERROR_MESSAGE"
# Stop the workflow with an error
exit 1
fi

echo "Package version creation id: $PACKAGE_VERSION_ID";
MAX_ATTEMPTS=${MAX_ATTEMPTS:-30}
echo "Using MAX_ATTEMPTS: $MAX_ATTEMPTS" # Max number of attempts (minutes) before giving up
echo

ATTEMPT=0
while true; do
# Fetch the package version creation status and the full JSON response
PACKAGE_CREATION_RESULT=$(sf package version create report -i "$PACKAGE_VERSION_ID" --json)
# Print the full JSON response for debugging (optional)
echo "Package creation result - attempt $((ATTEMPT + 1)):"
echo "$PACKAGE_CREATION_RESULT"

# Extract the status from the result
STATUS=$(echo "$PACKAGE_CREATION_RESULT" | yq -r '.result[0].Status')

if [ "$STATUS" == "Success" ]; then
echo "Package creation completed successfully."
break
elif [ "$STATUS" == "Error" ]; then
echo "Package creation failed, check the result json"
exit 1
else
echo "Package creation is in progress. Current status: $STATUS"
fi
echo

# Increment the attempt counter
ATTEMPT=$((ATTEMPT + 1))

# Check if we've reached the max attempts
if [ "$ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then
echo "Package creation is taking too long. Stopping after $MAX_ATTEMPTS minutes."
exit 1
fi

# Wait for a minute before checking again
sleep 60
done
17 changes: 6 additions & 11 deletions scripts/update-app-info-version.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
#!/bin/bash

# Extract version from branch name
DESTINATION_BRANCH=$(jq -r .pull_request.base.ref < "${GITHUB_EVENT_PATH}")
echo "Destination branch: $DESTINATION_BRANCH"

# Convert the branch name to lowercase to handle case-insensitive 'release'/'Release'
DESTINATION_BRANCH_LOWER=$(echo "$DESTINATION_BRANCH" | tr '[:upper:]' '[:lower:]')

# Source branch name (release/#.#.#)
BRANCH_NAME=${GITHUB_REF##*/}
# Extract version from the branch name (e.g., release/3.0.0 -> 3.0.0)
BRANCH_VERSION=${DESTINATION_BRANCH_LOWER#release/}
BRANCH_VERSION=${BRANCH_NAME#release/}

# Path to the AdyenOMSConstants.cls file
APEX_FILE="force-app/main/default/classes/AdyenOMSConstants.cls"

# Read version from sfdx-project.json
PROJECT_OMS_VERSION=$(jq -r '.packageDirectories[] | select(.default == true) | .versionNumber' sfdx-project.json | sed 's/.NEXT//')
PROJECT_LIBRARY_VERSION=$(jq -r '.packageDirectories[].dependencies[]? | select(.package | startswith("API Library Apex Adyen@")) | .package' sfdx-project.json | sed -E 's/.*@([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
PROJECT_OMS_VERSION=$(yq -r '.packageDirectories[] | select(.default == true) | .versionNumber' sfdx-project.json | sed 's/.NEXT//')
PROJECT_LIBRARY_VERSION=$(yq -r '.packageDirectories[].dependencies[]? | select(.package | test("API Library Apex Adyen@")) | .package' sfdx-project.json | sed -E 's/.*@([0-9]+\.[0-9]+\.[0-9]+).*/\1/')

# Read version from AdyenOMSConstants.cls using awk for single quotes
APEX_OMS_VERSION=$(awk -F"[']" '/MERCHANT_APP_VERSION_FOR_APP_INFO/ {print $2}' "$APEX_FILE")
Expand Down Expand Up @@ -56,10 +51,10 @@ fi

# Commit changes if any updates were made
if [ "$UPDATE_OMS" = true ] || [ "$UPDATE_LIBRARY" = true ]; then
echo "Adding $APEX_FILE to git"
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git add "$APEX_FILE"
git commit -m "chore: Update AdyenOMSConstants.cls version to $PROJECT_OMS_VERSION and library version to $PROJECT_LIBRARY_VERSION"
else
echo "AdyenOMSConstants.cls is already up to date."
fi
2 changes: 1 addition & 1 deletion sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"package": "Adyen Salesforce Order Management",
"definitionFile": "config/project-scratch-def.json",
"versionName": "version 3.0",
"versionNumber": "3.0.0.NEXT",
"versionNumber": "3.0.1.NEXT",
"ancestorVersion": "HIGHEST",
"dependencies": [
{
Expand Down

0 comments on commit e3fe214

Please sign in to comment.