Skip to content
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

Deployment Fix for main branch #736

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ jobs:
with:
fetch-depth: 0

- name: Get list of changed files
id: changes
run: |
changed_files=$(git diff --name-only HEAD^ HEAD)
echo "Changed files: $changed_files"
echo "FILES_CHANGED=$changed_files" >> "$GITHUB_OUTPUT"

- name: Stop if no files changed
if: ${{ steps.changes.outputs.FILES_CHANGED == '' }}
run: |
echo "No files were changed, skipping build."
exit 0

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down Expand Up @@ -119,4 +132,4 @@ jobs:
with:
cf_zone: ${{ secrets.CLOUDFLARE_ZONE }}
cf_auth: ${{ secrets.CLOUDFLARE_AUTH_KEY }}
hosts: ${{ env.APP_NAME }}.polygon.technology
hosts: ${{ env.APP_NAME }}.polygon.technology
6 changes: 2 additions & 4 deletions .github/workflows/pr-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ name: hosted branch pr deployment
on:
pull_request:
types: [opened, edited, reopened]
branches:
- hosted/*
push:
branches:
- dev
workflow_dispatch:

jobs:
deploy:
if: startsWith(github.head_ref, 'hosted/') || github.ref == 'refs/heads/dev'
uses: ./.github/workflows/build_and_deploy.yml
secrets: inherit

secrets: inherit
18 changes: 17 additions & 1 deletion build_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ def clone_data_to_branch_folder(branch_name, remote_url, parent_dir, pr_number=N
os.chdir(parent_dir)


def update_pr_description(pr_number):
"""
Updates PR description by adding the url to access the hosted environment under dev
if it does not already exist in the definition
:param pr_number: PR number for the branch hosting website
"""
command = ["gh", "pr", "view", pr_number, "--json", "body", "--jq", "'.body'"]
pr_description = subprocess.run(command, capture_output=True, text=True).stdout.strip()
hosted_url = f"docs-dev.polygon.technology/{pr_number}"
if hosted_url not in pr_description:
new_pr_description = f"Hosted url: [{hosted_url}](https://{hosted_url})\n" + pr_description
command = ["gh", "pr", "edit", pr_number, "--body", new_pr_description]
subprocess.run(command)


def process_branch_folders():
"""
Clones the branch specific code to hosted/<branch-name> folder.
Expand All @@ -95,6 +110,7 @@ def process_branch_folders():
continue
pr_number = str(branch_data["number"])
clone_data_to_branch_folder(branch_data["headRefName"], remote_url, parent_dir, pr_number)
update_pr_description(pr_number)
pr_numbers.append(pr_number)

return pr_numbers
Expand Down Expand Up @@ -129,4 +145,4 @@ def update_nginx_config(pr_numbers):
if __name__ == "__main__":
current_dir = os.getcwd()
pr_numbers = process_branch_folders()
update_nginx_config(pr_numbers)
update_nginx_config(pr_numbers)