diff --git a/.github/workflows/package-version-creation.yml b/.github/workflows/package-version-creation.yml index 0cb4855..47d956b 100644 --- a/.github/workflows/package-version-creation.yml +++ b/.github/workflows/package-version-creation.yml @@ -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 @@ -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 'actions@github.com' 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" \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 8ba7312..8633e67 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -5,8 +5,7 @@ on: branches: - '**' branches-ignore: - - release/* - - Release/* + - main jobs: build-and-deploy: diff --git a/scripts/create-new-package-version.sh b/scripts/create-new-package-version.sh new file mode 100755 index 0000000..067e791 --- /dev/null +++ b/scripts/create-new-package-version.sh @@ -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 diff --git a/scripts/update-app-info-version.sh b/scripts/update-app-info-version.sh old mode 100644 new mode 100755 index 2db474f..7bffd05 --- a/scripts/update-app-info-version.sh +++ b/scripts/update-app-info-version.sh @@ -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") @@ -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 'actions@github.com' 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 \ No newline at end of file diff --git a/sfdx-project.json b/sfdx-project.json index 43fdc80..7800cac 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -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": [ {