From 1026762190f8118405537648978c08b2c7a2c101 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 1 Feb 2024 21:04:08 +0100 Subject: [PATCH 1/7] Test calling build script from passing pipeline --- .gitea/workflows/ci-pipeline.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index f7d4633..6154ab1 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -69,3 +69,17 @@ jobs: source venv/bin/activate python manage.py test + + deploy: + needs: test + runs-on: self-hosted + steps: + - uses: actions/checkout@v4 + - name: Trigger Remote Script + run: | + response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://your-server-ip:5000/trigger-script -H "Authorization: SecretToken") + if [ "$response" -ne 200 ]; then + echo "Script execution failed with HTTP status $response" + exit 1 + fi + if: success() && github.ref == 'refs/heads/main' From 186d7e33a660e7c0540e48ec302cb57a15674cfa Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 1 Feb 2024 21:05:28 +0100 Subject: [PATCH 2/7] Fix script step --- .gitea/workflows/ci-pipeline.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index 6154ab1..ef60af2 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -77,9 +77,9 @@ jobs: - uses: actions/checkout@v4 - name: Trigger Remote Script run: | - response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://your-server-ip:5000/trigger-script -H "Authorization: SecretToken") - if [ "$response" -ne 200 ]; then + response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://your-server-ip:5000/trigger-script -H "Authorization: SecretToken") + if [ "$response" -ne 200 ]; then echo "Script execution failed with HTTP status $response" exit 1 - fi - if: success() && github.ref == 'refs/heads/main' + fi + if: success() && github.ref == 'refs/heads/main' From 2c720e80ab62625d374deaf708418d21d9e93a76 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 1 Feb 2024 21:21:10 +0100 Subject: [PATCH 3/7] Fix deploy job exit codes and webhook ip --- .gitea/workflows/ci-pipeline.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index ef60af2..4cf964f 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -77,9 +77,12 @@ jobs: - uses: actions/checkout@v4 - name: Trigger Remote Script run: | - response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://your-server-ip:5000/trigger-script -H "Authorization: SecretToken") + response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://45.150.187.54:5000/trigger-script -H "Authorization: SecretToken") if [ "$response" -ne 200 ]; then echo "Script execution failed with HTTP status $response" exit 1 + else + echo "Script execution successful" + exit 0 fi if: success() && github.ref == 'refs/heads/main' From 3d7741f3dffed5827f6f9d856c5c6548a17443e7 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 2 Feb 2024 09:21:19 +0100 Subject: [PATCH 4/7] Print git refs to check if the deploy job is entering the if statement --- .gitea/workflows/ci-pipeline.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index 4cf964f..3b62690 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -75,6 +75,13 @@ jobs: runs-on: self-hosted steps: - uses: actions/checkout@v4 + + - name: Check refs + run: | + echo $GITHUB_REF_NAME + echo $GITHUB_REF + echo $GITHUB_REF_TYPE + - name: Trigger Remote Script run: | response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://45.150.187.54:5000/trigger-script -H "Authorization: SecretToken") From 8c21ae3b1eda93719ae7a69da8bfda2f34ebea8e Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 2 Feb 2024 09:25:44 +0100 Subject: [PATCH 5/7] Add dummy if statement to ensure it works --- .gitea/workflows/ci-pipeline.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index 3b62690..f69fe5f 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -81,6 +81,7 @@ jobs: echo $GITHUB_REF_NAME echo $GITHUB_REF echo $GITHUB_REF_TYPE + if: success() && github.ref == 'refs/heads/testing-pipeline' - name: Trigger Remote Script run: | From bc46ca851efd17e71ad079db1212244dcff2c413 Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 2 Feb 2024 09:36:04 +0100 Subject: [PATCH 6/7] Remove main branch check to test webhook --- .gitea/workflows/ci-pipeline.yaml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index f69fe5f..844c50f 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -76,13 +76,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Check refs - run: | - echo $GITHUB_REF_NAME - echo $GITHUB_REF - echo $GITHUB_REF_TYPE - if: success() && github.ref == 'refs/heads/testing-pipeline' - - name: Trigger Remote Script run: | response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://45.150.187.54:5000/trigger-script -H "Authorization: SecretToken") @@ -93,4 +86,4 @@ jobs: echo "Script execution successful" exit 0 fi - if: success() && github.ref == 'refs/heads/main' + #if: success() && github.ref == 'refs/heads/main' From 0e0bad18fba34007d0d75fd6146e9eeef2485259 Mon Sep 17 00:00:00 2001 From: Elijah Date: Tue, 6 Feb 2024 11:10:13 +0100 Subject: [PATCH 7/7] Added main check to only deploy on the main branch --- .gitea/workflows/ci-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index 844c50f..13fbcaf 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -86,4 +86,4 @@ jobs: echo "Script execution successful" exit 0 fi - #if: success() && github.ref == 'refs/heads/main' + if: success() && github.ref == 'refs/heads/main'