Skip to content

Commit

Permalink
Merge pull request #747 from 0xPolygon/hosted/check_deployment_fixes
Browse files Browse the repository at this point in the history
Hosted/check deployment fixes
  • Loading branch information
sshrihar authored Sep 26, 2024
2 parents 64997e6 + efe56e6 commit 0cbfef6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 69 deletions.
70 changes: 2 additions & 68 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,77 +30,11 @@ on:
type: string
description: "Cluster name for deployment"
default: "frontend-dev-ecs-cluster"

#
jobs:
check_files_changed:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
id-token: write
contents: write
outputs:
FILES_CHANGED: ${{ steps.changes.outputs.FILES_CHANGED }}
steps:
- name: Install GitHub CLI
run: |
(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Authenticate GitHub CLI
run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"

- name: Checkout Code Repository
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Get list of changed files
id: changes
run: |
changed_files=$(git diff --name-only HEAD^ HEAD)
num_changed_files=$(echo "$changed_files" | wc -l)
echo "Number of Files changed=$num_changed_files"
echo "FILES_CHANGED=$num_changed_files" >> "$GITHUB_OUTPUT"
check_pr_open:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
needs: [check_files_changed]
if: needs.check_files_changed.outputs.FILES_CHANGED != '' && startsWith(github.head_ref, 'hosted/')
permissions:
id-token: write
contents: write
outputs:
PR_OPEN: ${{ steps.check_pr.outputs.PR_OPEN }}
steps:
- name: Checkout Code Repository
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Check for open PR
id: check_pr
run: |
BRANCH_NAME=${{ github.head_ref }}
pr_number=$(gh pr list --head "$BRANCH_NAME" --state open --json number --jq '.[0].number')
echo "Checked PR number: $pr_number"
echo "PR_OPEN=$pr_number" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build_and_deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
needs: [check_files_changed, check_pr_open]
if: |
needs.check_files_changed.outputs.FILES_CHANGED != '' && github.ref == 'refs/heads/dev' ||
needs.check_pr_open.outputs.PR_OPEN != '' && needs.check_files_changed.outputs.FILES_CHANGED != '' &&
startsWith(github.head_ref, 'hosted/')
environment: ${{ inputs.environment }}
permissions:
id-token: write
contents: write
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/hosted-dev-deployment.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: Hosted PR and Dev Deployment
on:
pull_request:
types: [opened, edited, reopened, synchronize]
types: [opened, reopened, synchronize]
push:
branches:
- dev
workflow_dispatch:

jobs:
deploy:
if: github.event_name != 'push' || startsWith(github.head_ref, 'hosted/')
uses: ./.github/workflows/build_and_deploy.yml
secrets: inherit

0 comments on commit 0cbfef6

Please sign in to comment.