From 8d8e939165fa0e79f919e5012168a8c9f017a8aa Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 17 Mar 2023 14:35:04 -0400 Subject: [PATCH 1/9] new branch test workflow --- .github/workflows/branchtest.yml | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/branchtest.yml diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml new file mode 100644 index 00000000..a6d64a4c --- /dev/null +++ b/.github/workflows/branchtest.yml @@ -0,0 +1,48 @@ +name: Test Workflow + +on: + workflow_dispatch: + pull_request: + types: [opened, synchronize, reopened] + branch: develop + +jobs: + getbranch: + runs-on: ubuntu-latest + outputs: + netclientbranch: ${{ steps.checkbranch.outputs.netclientbranch }} + steps: + - name: checkout + uses: actions/checkout@v3 + with: + repository: gravitl/netclient + ref: develop + - name: check if branch exists + id: checkbranch + run: | + if git show-ref ${{ github.ref_name}}; then + echo branch exists + echo "netclientbranch=${{ github.ref_name }}" >> $GITHUB_OUTPUT + else + echo branch does not exist + echo "netclientbranch=develop" >> $GITHUB_OUTPUT + fi + + terraform: + needs: getbranch + uses: gravitl/devops/.github/workflows/terraform.yml + with: + netmakerbranch: ${{ github.ref_name }} + netclientbranch: ${{ needs.getbranch.outputs.netclientbranch }} + secrets: inherit + + + testbranch: + #needs: [getbranch, terraform] + needs: [getbranch] + uses: gravitl/devops/.github/workflows/branchtest.yml + with: + tag: ${{ github.ref_name }} + network: ${{ github.ref_name }} + secrets: inherit + From 1f5b31212b8cfb1a9cdc40e3f50d6c0a357525f5 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 17 Mar 2023 14:38:28 -0400 Subject: [PATCH 2/9] specify version of reusable workflows --- .github/workflows/branchtest.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index a6d64a4c..0a6acaac 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: pull_request: types: [opened, synchronize, reopened] - branch: develop + branches: develop jobs: getbranch: @@ -30,7 +30,7 @@ jobs: terraform: needs: getbranch - uses: gravitl/devops/.github/workflows/terraform.yml + uses: gravitl/devops/.github/workflows/terraform.yml@master with: netmakerbranch: ${{ github.ref_name }} netclientbranch: ${{ needs.getbranch.outputs.netclientbranch }} @@ -40,7 +40,7 @@ jobs: testbranch: #needs: [getbranch, terraform] needs: [getbranch] - uses: gravitl/devops/.github/workflows/branchtest.yml + uses: gravitl/devops/.github/workflows/branchtest.yml@master with: tag: ${{ github.ref_name }} network: ${{ github.ref_name }} From 238704b23438b6fef62abf2e399f280a01e0dd6a Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 17 Mar 2023 14:54:45 -0400 Subject: [PATCH 3/9] add dependency on terraform for testbranch job --- .github/workflows/branchtest.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index 0a6acaac..b5d313f6 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -38,8 +38,7 @@ jobs: testbranch: - #needs: [getbranch, terraform] - needs: [getbranch] + needs: [getbranch, terraform] uses: gravitl/devops/.github/workflows/branchtest.yml@master with: tag: ${{ github.ref_name }} From e3f5e5e79f1191d4fcb8bdb5c0aa9c2999988420 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 17 Mar 2023 14:57:53 -0400 Subject: [PATCH 4/9] update test name --- .github/workflows/branchtest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index b5d313f6..fe478b54 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -1,4 +1,4 @@ -name: Test Workflow +name: Deploy and Test Branch on: workflow_dispatch: From 9c3e75a68e492b1e0b496bfdfa61abcca110dbc3 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Wed, 22 Mar 2023 10:19:36 -0400 Subject: [PATCH 5/9] skip concurrent runs --- .github/workflows/branchtest.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index fe478b54..5c23b96c 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -4,11 +4,22 @@ on: workflow_dispatch: pull_request: types: [opened, synchronize, reopened] - branches: develop + branches: [develop] jobs: + skip-check: + runs-on: ubuntu-latest + outputs: + skip: ${{ steps.check.outputs.skip }} + steps: + - id: skip + uses: fkirc/skip-duplicate-actions@v5 + with: + concurrent_skiping: 'always' getbranch: runs-on: ubuntu-latest + needs: skip-check + if: ${{ needs.skip-check.outputs.skip != 'true' }} outputs: netclientbranch: ${{ steps.checkbranch.outputs.netclientbranch }} steps: From f602eb1a79ccd1a3502fd8c22b1f99c406c7924e Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Wed, 29 Mar 2023 13:33:17 -0400 Subject: [PATCH 6/9] tag/network vars for testbranch workflow --- .github/workflows/branchtest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index 5c23b96c..f3bfe54f 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -52,7 +52,7 @@ jobs: needs: [getbranch, terraform] uses: gravitl/devops/.github/workflows/branchtest.yml@master with: - tag: ${{ github.ref_name }} - network: ${{ github.ref_name }} + tag: ${{ github.run_id }}-${{ github.run_attempt }} + network: terraform secrets: inherit From 0feb1b958a04b0c0fcbe0373572ecea599070763 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Wed, 29 Mar 2023 13:56:34 -0400 Subject: [PATCH 7/9] delete droplets on completion of tests --- .github/workflows/deletedroplets.yml | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/deletedroplets.yml diff --git a/.github/workflows/deletedroplets.yml b/.github/workflows/deletedroplets.yml new file mode 100644 index 00000000..3820fcc6 --- /dev/null +++ b/.github/workflows/deletedroplets.yml @@ -0,0 +1,38 @@ +name: Delete Droplets + +on: + workflows_run: + workflows: [Run All Test on Branch] + types: + - completed + +jobs: + on-success: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: delete droplets + run: | + sleep 15m + curl -X GET \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ + "https://api.digitalocean.com/v2/droplets?tag_name=$TAG" + env: + DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} + TAG: ${{ github.event.workflow_run.run_id }}-${{ github.event.workflow_run.run_attempt }} + + on-failure: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + steps: + - name: delete droplets + run: | + sleep 6h + curl -X GET \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ + "https://api.digitalocean.com/v2/droplets?tag_name=$TAG" + env: + DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} + TAG: ${{ github.event.workflow_run.run_id }}-${{ github.event.workflow_run.run_attempt }} From dcab20150f0b0f8021b3390f2c71ddf5efdd05c1 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Wed, 29 Mar 2023 14:01:10 -0400 Subject: [PATCH 8/9] fix typo --- .github/workflows/branchtest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index f3bfe54f..4699d09f 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -15,7 +15,7 @@ jobs: - id: skip uses: fkirc/skip-duplicate-actions@v5 with: - concurrent_skiping: 'always' + concurrent_skipping: 'always' getbranch: runs-on: ubuntu-latest needs: skip-check From 3262990d7c4f305fc14bb7517a56db7455f821a9 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Wed, 29 Mar 2023 14:06:52 -0400 Subject: [PATCH 9/9] use head_ref --- .github/workflows/branchtest.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/branchtest.yml b/.github/workflows/branchtest.yml index 4699d09f..a2659fd6 100644 --- a/.github/workflows/branchtest.yml +++ b/.github/workflows/branchtest.yml @@ -31,9 +31,9 @@ jobs: - name: check if branch exists id: checkbranch run: | - if git show-ref ${{ github.ref_name}}; then + if git show-ref ${{ github.head_ref}}; then echo branch exists - echo "netclientbranch=${{ github.ref_name }}" >> $GITHUB_OUTPUT + echo "netclientbranch=${{ github.head_ref }}" >> $GITHUB_OUTPUT else echo branch does not exist echo "netclientbranch=develop" >> $GITHUB_OUTPUT @@ -43,7 +43,7 @@ jobs: needs: getbranch uses: gravitl/devops/.github/workflows/terraform.yml@master with: - netmakerbranch: ${{ github.ref_name }} + netmakerbranch: ${{ github.head_ref }} netclientbranch: ${{ needs.getbranch.outputs.netclientbranch }} secrets: inherit