From 66487934fa0abce9868c6b34aa35e26b920f5808 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 19:08:39 +0530 Subject: [PATCH 1/5] ACMS-4329: Add manual deployment workflow. --- .github/workflows/deployment.workflow.yml | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index b8d5fb678..592bfd8e2 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -2,6 +2,30 @@ name: "Code Deployment on Acquia Environment" on: push: branches: [ develop ] + workflow_dispatch: + inputs: + environment: + description: 'Choose environment' + type: choice + options: + - dev + - stage + - prod + - next + - ode1 + - ode2 + - ode3 + - ode4 + - ode5 + - ode6 + - ode7 + - ode8 + required: true + default: 'dev' + drupal-core: + description: 'Choose Drupal Core' + required: true + default: '^11' concurrency: group: "ci-${{ github.ref }}" @@ -13,16 +37,16 @@ env: GIT_COMMITTER_EMAIL: "no-reply@acquia.com" GIT_AUTHOR_EMAIL: "no-reply@acquia.com" PHP_VERSION: 8.3 - CORE_VERSION: ^11 + CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '^11' }} + ACQUIA_CLOUD_ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }} jobs: acquia_code_deployment: - if: ${{ github.event_name == 'push' }} + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} name: "Code Deployment" runs-on: ubuntu-latest environment: acquia_code_deployment env: - ACQUIA_CLOUD_ENVIRONMENT: "dev" ACQUIA_CLOUD_API_KEY: ${{ secrets.ACQUIA_CLOUD_API_KEY }} ACQUIA_CLOUD_API_SECRET: ${{ secrets.ACQUIA_CLOUD_API_SECRET }} ACQUIA_CLOUD_APPLICATION: ${{ secrets.ACQUIA_CLOUD_APPLICATION }} From 9aa939a29caa4260817ee26f6d8473e09534d007 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 19:10:09 +0530 Subject: [PATCH 2/5] Minor debug. --- .github/workflows/deployment.workflow.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index 592bfd8e2..a7d9cdc5e 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -26,6 +26,16 @@ on: description: 'Choose Drupal Core' required: true default: '^11' + php-version: + description: 'Choose PHP Version' + type: choice + options: + - "8.1" + - "8.2" + - "8.3" + - "8.4" + required: true + default: '8.3' concurrency: group: "ci-${{ github.ref }}" @@ -36,7 +46,7 @@ env: GIT_COMMITTER_NAME: "CD" GIT_COMMITTER_EMAIL: "no-reply@acquia.com" GIT_AUTHOR_EMAIL: "no-reply@acquia.com" - PHP_VERSION: 8.3 + PHP_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.php-version || '8.3' }} CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '^11' }} ACQUIA_CLOUD_ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }} @@ -114,6 +124,16 @@ jobs: acli remote:aliases:download -n git add . && git commit -m "Added acli & drush alias configurations." 2>/dev/null + - name: Find & Switch PHP Version + run: | + # Find the PHP version. + ENV_PHP_VERSION=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.configuration.php.version') + echo $ENV_PHP_VERSION + exit 1 + # If PHP_VERSION is NOT the same as the one we want to switch to. Then switch PHP version. + if [ "${ENV_PHP_VERSION}" != "${PHP_VERSION}" ]; then + acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n + fi - name: Deploy & Switch Code shell: bash run: | From ea08e4b5255e3befb29828650087156b90eef78a Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 23:18:21 +0530 Subject: [PATCH 3/5] ACMS-4329: Temp run github CI. --- .github/workflows/deployment.workflow.yml | 41 +++++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index a7d9cdc5e..b8d3926bf 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -1,7 +1,7 @@ -name: "Code Deployment on Acquia Environment" +name: "Code Deployment (Acquia)" on: push: - branches: [ develop ] + branches: [ develop, ACMS-4329 ] workflow_dispatch: inputs: environment: @@ -23,7 +23,7 @@ on: required: true default: 'dev' drupal-core: - description: 'Choose Drupal Core' + description: 'Choose Drupal Core Version' required: true default: '^11' php-version: @@ -36,6 +36,10 @@ on: - "8.4" required: true default: '8.3' + download-latest-dependencies: + description: 'Download latest dependencies' + type: boolean + default: false concurrency: group: "ci-${{ github.ref }}" @@ -47,8 +51,9 @@ env: GIT_COMMITTER_EMAIL: "no-reply@acquia.com" GIT_AUTHOR_EMAIL: "no-reply@acquia.com" PHP_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.php-version || '8.3' }} - CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '^11' }} + CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '' }} ACQUIA_CLOUD_ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }} + DOWNLOAD_LATEST_DEPENDENCIES: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.download-latest-dependencies || 'false' }} jobs: acquia_code_deployment: @@ -88,12 +93,24 @@ jobs: ACQUIA_CLOUD_KNOWN_HOSTS: ${{ vars.ACQUIA_CLOUD_KNOWN_HOSTS }} - name: Setup Drupal Project run: | - # Install specific version of Drupal Core. - composer require drupal/core:${CORE_VERSION} drupal/core-composer-scaffold:${CORE_VERSION} drupal/core-recommended:${CORE_VERSION} --no-install --no-update -n + # Download specific version of Drupal Core, if requested. + [ -n "${CORE_VERSION}" ] && echo composer require drupal/core:${CORE_VERSION} drupal/core-composer-scaffold:${CORE_VERSION} drupal/core-recommended:${CORE_VERSION} --no-install --no-update -n || true - # Move some of development dependencies to production depencies or else acli push:artifact will fail. + # Move some of development dependencies to production dependencies or else acli push:artifact will fail. composer require oomphinc/composer-installers-extender --no-install --no-update -n - composer update "drupal/core-*" drush/drush "drupal/*" -W --with=drupal/core:${CORE_VERSION} --minimal-changes + + if [ "${DOWNLOAD_LATEST_DEPENDENCIES}" == "true" ]; then + rm composer.lock + composer install + else + # Update specific version of Drupal Core, if requested or else simply install all dependencies. + if [ -n "${CORE_VERSION}" ]; then + composer update "drupal/core-*" drush/drush "drupal/*" -W --with=drupal/core:${CORE_VERSION} --minimal-changes + else + # In CI, we don't need to run composer install again, as it's already will be done by below command. + composer update oomphinc/composer-installers-extender + fi + fi # Include MySQL 5.7 connection settings, before DRS require line is added. echo "require DRUPAL_ROOT . '/modules/contrib/mysql57/settings.inc';" >> docroot/sites/default/settings.php @@ -128,11 +145,13 @@ jobs: run: | # Find the PHP version. ENV_PHP_VERSION=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.configuration.php.version') - echo $ENV_PHP_VERSION - exit 1 + echo "The CI php-version: ${PHP_VERSION}" + echo "The Acquia Cloud environment php-version: $ENV_PHP_VERSION" # If PHP_VERSION is NOT the same as the one we want to switch to. Then switch PHP version. if [ "${ENV_PHP_VERSION}" != "${PHP_VERSION}" ]; then - acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n + echo "Switching PHP version to ${PHP_VERSION}" + acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n + sleep 10 fi - name: Deploy & Switch Code shell: bash From e7d9bd84349d9b267846d75f5263d6d538e8a835 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Thu, 5 Dec 2024 01:00:31 +0530 Subject: [PATCH 4/5] ACMS-4329: More improvements. --- .github/workflows/deployment.workflow.yml | 81 ++++++++++++----------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index b8d3926bf..e41fb30ef 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -1,7 +1,7 @@ name: "Code Deployment (Acquia)" on: push: - branches: [ develop, ACMS-4329 ] + branches: [ develop, main, ACMS-*, feature/* ] workflow_dispatch: inputs: environment: @@ -158,54 +158,59 @@ jobs: run: | BRANCH_TO_DEPLOY=acli-${GITHUB_REF_NAME} + # Push changes on Acuia Cloud. acli push:artifact ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n - DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') + # If the event is push and branch is develop or if CI is triggered manually, then only switch code. + if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" == "develop" ]] || [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then - # If BRANCH_TO_DEPLOY is NOT the same as DEPLOYED_BRANCH. Then switch code. - if [ "$BRANCH_TO_DEPLOY" != "$DEPLOYED_BRANCH" ]; then - # Step 1: Run the code:switch command and capture its output. - response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) + DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') - # Step 2: Extract the notification ID from the JSON response - notification_id=$(echo "$response" | jq -r '.notification') + # If BRANCH_TO_DEPLOY is NOT the same as DEPLOYED_BRANCH. Then switch code. + if [ "${BRANCH_TO_DEPLOY}" != "${DEPLOYED_BRANCH}" ]; then + # Step 1: Run the code:switch command and capture its output. + response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) - # Step 3: Check if the notification ID was successfully extracted. - if [[ -z "$notification_id" ]]; then - echo "Error: Notification ID not found in the response." - exit 1 - fi + # Step 2: Extract the notification ID from the JSON response + notification_id=$(echo "$response" | jq -r '.notification') - progress=0 - timeout=1800 # Timeout in seconds (30 minutes). - start_time=$(date +%s) # Get the current time in seconds + # Step 3: Check if the notification ID was successfully extracted. + if [[ -z "$notification_id" ]]; then + echo "Error: Notification ID not found in the response." + exit 1 + fi - echo "Please wait while code is being switched..." - # Step 4: Poll the notification status until progress reaches 100. - while [[ "$progress" -lt 100 ]]; do - # Run the notification find command. - notification_response=$(acli api:notifications:find "$notification_id" -n) + progress=0 + timeout=1800 # Timeout in seconds (30 minutes). + start_time=$(date +%s) # Get the current time in seconds - # Extract the progress value. - progress=$(echo "$notification_response" | jq -r '.progress') + echo "Please wait while code is being switched..." + # Step 4: Poll the notification status until progress reaches 100. + while [[ "$progress" -lt 100 ]]; do + # Run the notification find command. + notification_response=$(acli api:notifications:find "$notification_id" -n) - # Display current progress. - #echo "Current progress: $progress%" + # Extract the progress value. + progress=$(echo "$notification_response" | jq -r '.progress') - # Check if we've exceeded the timeout (5 minutes). - current_time=$(date +%s) - elapsed_time=$((current_time - start_time)) + # Display current progress. + #echo "Current progress: $progress%" - if [[ "$elapsed_time" -ge "$timeout" ]]; then - # Calculate minutes and seconds. - minutes=$((elapsed_time / 60)) - seconds=$((elapsed_time % 60)) + # Check if we've exceeded the timeout (5 minutes). + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) - echo "Error: Timeout reached after $minutes minute(s) and $seconds second(s). Progress did not reach 100%." - exit 1 - fi + if [[ "$elapsed_time" -ge "$timeout" ]]; then + # Calculate minutes and seconds. + minutes=$((elapsed_time / 60)) + seconds=$((elapsed_time % 60)) + + echo "Error: Timeout reached after $minutes minute(s) and $seconds second(s). Progress did not reach 100%." + exit 1 + fi - # Wait for 5 seconds before polling again. - sleep 5 - done + # Wait for 5 seconds before polling again. + sleep 5 + done + fi fi From d3e6f5357b623d8eab3603e697dd7994f6c50023 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Thu, 5 Dec 2024 01:23:23 +0530 Subject: [PATCH 5/5] ACMS-4329: Try more improvements. --- .github/workflows/deployment.workflow.yml | 36 ++++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index e41fb30ef..9eac6f44e 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -70,27 +70,6 @@ jobs: - uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} - - name: Configure SSH keys - run: | - mkdir -p ~/.ssh - echo "${ACQUIA_CLOUD_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - eval `ssh-agent -s` - ssh-add ~/.ssh/id_rsa - - # Loop through each line in the environment variable. - echo "${ACQUIA_CLOUD_KNOWN_HOSTS}" | while IFS= read -r KNOWN_HOST; do - if [[ -n "${KNOWN_HOST}" ]]; then - CLEANED_HOST=$(echo "${KNOWN_HOST}" | tr -d '\r' | xargs -n1) - ssh-keyscan "${CLEANED_HOST}" >> ~/.ssh/known_hosts 2>/dev/null || { - echo "Warning: Unable to scan host ${CLEANED_HOST}. Skipping." - } - fi - done - shell: bash - env: - ACQUIA_CLOUD_SSH_PRIVATE_KEY: ${{ secrets.ACQUIA_CLOUD_SSH_PRIVATE_KEY }} - ACQUIA_CLOUD_KNOWN_HOSTS: ${{ vars.ACQUIA_CLOUD_KNOWN_HOSTS }} - name: Setup Drupal Project run: | # Download specific version of Drupal Core, if requested. @@ -153,6 +132,21 @@ jobs: acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n sleep 10 fi + - name: Configure SSH keys + run: | + mkdir -p ~/.ssh + echo "${ACQUIA_CLOUD_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + eval `ssh-agent -s` + ssh-add ~/.ssh/id_rsa + + SSH_URL=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.ssh_url' | awk -F'[@:]' '{print $2}') + GIT_URL=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.url' | awk -F'[@:]' '{print $2}') + + ssh-keyscan "${SSH_URL}" >> ~/.ssh/known_hosts && ssh-keyscan "${GIT_URL}" >> ~/.ssh/known_hosts + shell: bash + env: + ACQUIA_CLOUD_SSH_PRIVATE_KEY: ${{ secrets.ACQUIA_CLOUD_SSH_PRIVATE_KEY }} - name: Deploy & Switch Code shell: bash run: |