-
Notifications
You must be signed in to change notification settings - Fork 555
89 lines (82 loc) · 3.44 KB
/
branchtest.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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'
jobs:
check-pr-approval:
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
outputs:
approved: ${{ steps.check.outputs.approved }}
steps:
- name: Check if PR is approved or author is a contributor
id: check
run: |
if [[ "${{ github.event.review.state }}" == "approved" ]] || \
[[ "${{ github.event_name }}" == "pull_request_target" && "${{ github.event.pull_request.author_association }}" =~ ^(OWNER|MEMBER|COLLABORATOR)$ ]]; 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:
- id: skip
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: 'always'
getbranch:
runs-on: ubuntu-latest
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 }}
steps:
- name: Determine branches
id: determine_branches
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "NETMAKER_BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
echo "NETCLIENT_BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
else
echo "NETMAKER_BRANCH=${{ github.event.pull_request.head.ref || github.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: |
if git ls-remote --heads origin ${{ env.NETCLIENT_BRANCH }} | grep -q ${{ env.NETCLIENT_BRANCH }}; then
echo "netclient branch ${{ env.NETCLIENT_BRANCH }} exists"
echo "netclientbranch=${{ env.NETCLIENT_BRANCH }}" >> $GITHUB_OUTPUT
else
echo "netclient branch ${{ env.NETCLIENT_BRANCH }} does not exist, using develop"
echo "netclientbranch=develop" >> $GITHUB_OUTPUT
fi
echo "netmakerbranch=${{ env.NETMAKER_BRANCH }}" >> $GITHUB_OUTPUT
branchtest:
uses: gravitl/devops/.github/workflows/testdeploybranch.yml@master
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 }}
tag: ${{ github.run_id }}-${{ github.run_attempt }}
secrets: inherit