Skip to content

Commit

Permalink
Updated branchtest to run only on approval
Browse files Browse the repository at this point in the history
  • Loading branch information
lmnzx committed Sep 27, 2024
1 parent 14137c2 commit 39fa623
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions .github/workflows/branchtest.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
name: Deploy and Test Branch

on:
pull_request_review:
types: [submitted]
pull_request_target:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy and test'
required: true
default: 'develop'
pull_request:
types: [opened, synchronize, reopened]
branches: [develop]

jobs:
check-pr-approval:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_review' || github.event_name == 'pull_request_target'
outputs:
approved: ${{ steps.check.outputs.approved }}
steps:
- name: Check if PR is approved
id: check
run: |
if [[ "${{ github.event.review.state }}" == "approved" ]] || [[ "${{ github.event_name }}" == "pull_request_target" && "${{ github.event.pull_request.state }}" == "open" ]]; then
echo "approved=true" >> $GITHUB_OUTPUT
else
echo "approved=false" >> $GITHUB_OUTPUT
fi
skip-check:
runs-on: ubuntu-latest
needs: [check-pr-approval]
if: github.event_name == 'workflow_dispatch' || needs.check-pr-approval.outputs.approved == 'true'
outputs:
skip: ${{ steps.skip.outputs.skip }}
steps:
Expand All @@ -24,8 +42,8 @@ jobs:

getbranch:
runs-on: ubuntu-latest
needs: skip-check
if: ${{ needs.skip-check.outputs.skip != 'true' }}
needs: [skip-check, check-pr-approval]
if: (needs.skip-check.outputs.skip != 'true') && (github.event_name == 'workflow_dispatch' || needs.check-pr-approval.outputs.approved == 'true')
outputs:
netclientbranch: ${{ steps.getbranch.outputs.netclientbranch }}
netmakerbranch: ${{ steps.getbranch.outputs.netmakerbranch }}
Expand All @@ -37,14 +55,16 @@ jobs:
echo "NETMAKER_BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
echo "NETCLIENT_BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
else
echo "NETMAKER_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
echo "NETMAKER_BRANCH=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
echo "NETCLIENT_BRANCH=develop" >> $GITHUB_ENV
fi
- name: Checkout netclient repository
uses: actions/checkout@v4
with:
repository: gravitl/netclient
fetch-depth: 0

- name: Check if netclient branch exists and set output
id: getbranch
run: |
Expand All @@ -59,7 +79,8 @@ jobs:
branchtest:
uses: gravitl/devops/.github/workflows/testdeploybranch.yml@master
needs: [getbranch, skip-check]
needs: [getbranch, skip-check, check-pr-approval]
if: (needs.skip-check.outputs.skip != 'true') && (github.event_name == 'workflow_dispatch' || needs.check-pr-approval.outputs.approved == 'true')
with:
netclientbranch: ${{ needs.getbranch.outputs.netclientbranch }}
netmakerbranch: ${{ needs.getbranch.outputs.netmakerbranch }}
Expand Down

0 comments on commit 39fa623

Please sign in to comment.