From 4247e66e6d55267a9362148f1cf1d20aeef71334 Mon Sep 17 00:00:00 2001 From: Robin Candau Date: Fri, 15 Nov 2024 12:33:16 +0100 Subject: [PATCH] Update CD to automatically deploy the website after build --- .github/workflows/CD.yml | 25 ++++++++++++++++++++++++- content/blog/website-workflow.md | 4 +++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index d807db0..91812c4 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -1,8 +1,15 @@ name: CD -on: pull_request +on: + pull_request: + branches: + - main + push: + branches: + - main jobs: Build: + if: github.event_name == 'pull_request' runs-on: - self-hosted - CI-CD @@ -34,3 +41,19 @@ jobs: else echo "No changes to commit" fi + + Deploy: + runs-on: + - self-hosted + - CI-CD + + - name: Deploy website + run: | + if [ "$(git rev-parse --abbrev-ref HEAD)" == "dev" ]; then + /opt/github-runner/antiz.fr/deploy_website.sh dev + elif [ "$(git rev-parse --abbrev-ref HEAD)" == "main" ]; then + /opt/github-runner/antiz.fr/deploy_website.sh prod + else + echo "Invalid branch, make sure you opened your pull request from the 'dev' branch" + exit 1 + fi diff --git a/content/blog/website-workflow.md b/content/blog/website-workflow.md index f99cf41..e8e130a 100644 --- a/content/blog/website-workflow.md +++ b/content/blog/website-workflow.md @@ -4,6 +4,8 @@ date: 2023-07-24T13:20:26+02:00 draft: false --- +EDIT: This article is slitghly outdated as the workflow I use to maintain this website has evolved and improved over time (but it still gives a fairly good idea of a simple but effective CI / CD workflow one could apply to their projects). I'll eventually write a V2 of that article at some point. + ## The website This website is built with the [HUGO](https://gohugo.io/) static website generator using the [anatole](https://github.com/lxndrblz/anatole) theme. @@ -34,7 +36,7 @@ The [test job](https://github.com/Antiz96/antiz.fr/blob/main/.github/workflows/C ### CD -Once both of the above CI jobs succeeded (meaning the website has been successfully built, pushed to the dev branch of the repository, and the tests went through without any error), I launch a job on my [Jenkins](https://www.jenkins.io/) server targeting the dev environment: +Once both of the above CI jobs succeeded (meaning the website has been successfully built, pushed to the dev branch of the repository, and the tests went through without any error), I launch a job on my [Jenkins](https://www.jenkins.io/) server targeting the dev environment *(edit: the trigger of that job is now automated via GitHub actions as well): ![alt_text](../../images/Jenkins_Update_Website_Job_Dev.png "Jenkins - Update Website Job Dev")