From 4c3c606d7a5750199ef7e4e2b48dcab013f41733 Mon Sep 17 00:00:00 2001 From: Saurabh Shrihar Date: Mon, 23 Sep 2024 16:09:29 +0400 Subject: [PATCH] Deployment Fix for main branch --- .github/workflows/build_and_deploy.yml | 15 ++++++++++++++- .github/workflows/pr-deployment.yml | 6 ++---- build_branches.py | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 1f9c4f01..eaba98a3 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/.github/workflows/pr-deployment.yml b/.github/workflows/pr-deployment.yml index 86a96125..418142f3 100644 --- a/.github/workflows/pr-deployment.yml +++ b/.github/workflows/pr-deployment.yml @@ -2,8 +2,6 @@ name: hosted branch pr deployment on: pull_request: types: [opened, edited, reopened] - branches: - - hosted/* push: branches: - dev @@ -11,6 +9,6 @@ on: jobs: deploy: + if: startsWith(github.head_ref, 'hosted/') || github.ref == 'refs/heads/dev' uses: ./.github/workflows/build_and_deploy.yml - secrets: inherit - \ No newline at end of file + secrets: inherit \ No newline at end of file diff --git a/build_branches.py b/build_branches.py index 33302ca7..0a820819 100755 --- a/build_branches.py +++ b/build_branches.py @@ -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/ folder. @@ -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 @@ -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) \ No newline at end of file