-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3408bd0
commit 3be471f
Showing
1 changed file
with
109 additions
and
64 deletions.
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 |
---|---|---|
|
@@ -2,15 +2,17 @@ name: "Code Deployment on Acquia Environment" | |
on: | ||
push: | ||
branches: [ develop, main, ACMS-4329 ] | ||
|
||
env: | ||
GIT_AUTHOR_NAME: "Vishal Khode" | ||
GIT_COMMITTER_NAME: "Vishal Khode" | ||
GIT_COMMITTER_EMAIL: "[email protected]" | ||
GIT_AUTHOR_EMAIL: "[email protected]" | ||
|
||
jobs: | ||
acquia_code_deployment: | ||
build: | ||
if: ${{ github.event_name == 'push' }} | ||
name: "Code Deployment on Acquia Environment" | ||
env: | ||
GIT_AUTHOR_NAME: "Vishal Khode" | ||
GIT_COMMITTER_NAME: "Vishal Khode" | ||
GIT_COMMITTER_EMAIL: "[email protected]" | ||
GIT_AUTHOR_EMAIL: "[email protected]" | ||
name: "Build Project" | ||
runs-on: ubuntu-latest | ||
environment: acquia_code_deployment | ||
concurrency: production | ||
|
@@ -72,6 +74,7 @@ jobs: | |
curl -OL https://github.com/acquia/cli/releases/latest/download/acli.phar | ||
chmod +x acli.phar | ||
mv acli.phar /usr/local/bin/acli | ||
cp /usr/local/bin/acli ./vendor/bin/acli | ||
acli --version | ||
acli auth:login --key=${ACQUIA_CLOUD_API_KEY} --secret=${ACQUIA_CLOUD_API_SECRET} -n | ||
|
@@ -82,61 +85,103 @@ jobs: | |
ACQUIA_CLOUD_API_KEY: ${{ secrets.ACQUIA_CLOUD_API_KEY }} | ||
ACQUIA_CLOUD_API_SECRET: ${{ secrets.ACQUIA_CLOUD_API_SECRET }} | ||
ACQUIA_APPLICATION_UUID: ${{ secrets.ACQUIA_APPLICATION_UUID }} | ||
- name: Deploy & Switch Code | ||
shell: bash | ||
- name: Create Patch for changes | ||
run: | | ||
BRANCH_TO_DEPLOY=acli-${GITHUB_REF_NAME} | ||
acli push:artifact ${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n | ||
DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') | ||
# 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_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) | ||
# Step 2: Extract the notification ID from the JSON response | ||
notification_id=$(echo "$response" | jq -r '.notification') | ||
# 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 | ||
progress=0 | ||
timeout=1800 # Timeout in seconds (30 minutes). | ||
start_time=$(date +%s) # Get the current time in seconds | ||
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) | ||
# Extract the progress value. | ||
progress=$(echo "$notification_response" | jq -r '.progress') | ||
# Display current progress. | ||
#echo "Current progress: $progress%" | ||
# Check if we've exceeded the timeout (5 minutes). | ||
current_time=$(date +%s) | ||
elapsed_time=$((current_time - start_time)) | ||
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 | ||
fi | ||
env: | ||
ACQUIA_CLOUD_ENVIRONMENT: ${{ secrets.ACQUIA_CLOUD_ENVIRONMENT }} | ||
git format-patch -2 HEAD --stdout > changes.patch | ||
# Upload patches as artifacts. | ||
- name: Upload Changes | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: patches | ||
path: | | ||
changes.patch | ||
~/.ssh/id_rsa | ||
~/.ssh/id_rsa.pub | ||
~/.ssh/known_hosts | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.3 | ||
- name: Download Changes | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: patches | ||
- name: Download Dependencies | ||
run: | | ||
git apply changes.patch && rm changes.patch | ||
git add . && git commit -m "Apply changes from patch." | ||
composer install | ||
mkdir -p ~/.ssh | ||
mv id_rsa* ~/.ssh/ && mv known_hosts ~/.ssh/ | ||
chmod 600 ~/.ssh/id_rsa | ||
eval `ssh-agent -s` | ||
ssh-add ~/.ssh/id_rsa | ||
# - name: Deploy & Switch Code | ||
# shell: bash | ||
# run: | | ||
# ls -ltr vendor || true | ||
# git log | ||
# exit 1 | ||
# # Move back acli. | ||
# mv ./vendor/bin/acli /usr/local/bin/acli | ||
# | ||
# BRANCH_TO_DEPLOY=acli-${GITHUB_REF_NAME} | ||
# | ||
# acli push:artifact ${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n | ||
# | ||
# DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') | ||
# | ||
# # 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_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) | ||
# | ||
# # Step 2: Extract the notification ID from the JSON response | ||
# notification_id=$(echo "$response" | jq -r '.notification') | ||
# | ||
# # 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 | ||
# | ||
# progress=0 | ||
# timeout=1800 # Timeout in seconds (30 minutes). | ||
# start_time=$(date +%s) # Get the current time in seconds | ||
# | ||
# 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) | ||
# | ||
# # Extract the progress value. | ||
# progress=$(echo "$notification_response" | jq -r '.progress') | ||
# | ||
# # Display current progress. | ||
# #echo "Current progress: $progress%" | ||
# | ||
# # Check if we've exceeded the timeout (5 minutes). | ||
# current_time=$(date +%s) | ||
# elapsed_time=$((current_time - start_time)) | ||
# | ||
# 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 | ||
# fi | ||
# env: | ||
# ACQUIA_CLOUD_ENVIRONMENT: ${{ secrets.ACQUIA_CLOUD_ENVIRONMENT }} |