From 8f0aad998bf1072a4f06977f3c4f3a336cb69a1c Mon Sep 17 00:00:00 2001 From: Vincent Vatelot Date: Fri, 24 Nov 2023 10:20:37 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=91=B7=20ci(deploy):=20Split=20produc?= =?UTF-8?q?tion=20and=20preprod=20environment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-preproduction.yml | 29 +++++++++++++++++++ .../{deploy.yml => deploy-production.yml} | 5 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy-preproduction.yml rename .github/workflows/{deploy.yml => deploy-production.yml} (90%) diff --git a/.github/workflows/deploy-preproduction.yml b/.github/workflows/deploy-preproduction.yml new file mode 100644 index 00000000..b85b5ab2 --- /dev/null +++ b/.github/workflows/deploy-preproduction.yml @@ -0,0 +1,29 @@ +name: Déploiement RSYNC en preproduction + +on: + push: + tags: + - "v*.*.*-preproduction" + +jobs: + deploy: + environment: preproduction + runs-on: ubuntu-latest + steps: + - name: 🛒 Checkout + uses: actions/checkout@v3 + - name: ✨ Setup Hugo + uses: peaceiris/actions-hugo@v2 + with: + hugo-version: "latest" + - name: ✨ Setup NPM + uses: bahmutov/npm-install@v1 + - name: 🛠️ Build + run: hugo + - name: 🔑 Install SSH Key + run: | + install -m 600 -D /dev/null ~/.ssh/id_rsa + echo "${{ secrets.RSYNC_PRIVATE_SSH_KEY }}" > ~/.ssh/id_rsa + echo "${{ secrets.RSYNC_KNOWN_HOSTS }}" > ~/.ssh/known_hosts + - name: 🚀 Deploy + run: rsync -rpzv --exclude="screenshots" -e 'ssh -p ${{ secrets.RSYNC_REMOTE_PORT }}' './public/' ${{ secrets.RSYNC_REMOTE_USER }}@${{ secrets.RSYNC_REMOTE_HOST }}:${{ secrets.RSYNC_REMOTE_FOLDER }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy-production.yml similarity index 90% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy-production.yml index ee8a37ce..234c3d49 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy-production.yml @@ -1,12 +1,13 @@ -name: Deploy rsync +name: Déploiement RSYNC en production on: push: tags: - - "v*.*.*" + - "v*.*.*-production" jobs: deploy: + environment: production runs-on: ubuntu-latest environment: production steps: From 58c412f435c9220bcef3cebdcedaa1c449f62214 Mon Sep 17 00:00:00 2001 From: Vincent Vatelot Date: Fri, 24 Nov 2023 10:33:13 +0100 Subject: [PATCH 2/3] ci: refactor deploy action to mutualize environment --- .github/workflows/deploy-production.yml | 30 ------------------- .../{deploy-preproduction.yml => deploy.yml} | 26 ++++++++++++++-- 2 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 .github/workflows/deploy-production.yml rename .github/workflows/{deploy-preproduction.yml => deploy.yml} (54%) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml deleted file mode 100644 index 234c3d49..00000000 --- a/.github/workflows/deploy-production.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Déploiement RSYNC en production - -on: - push: - tags: - - "v*.*.*-production" - -jobs: - deploy: - environment: production - runs-on: ubuntu-latest - environment: production - steps: - - name: 🛒 Checkout - uses: actions/checkout@v3 - - name: ✨ Setup Hugo - uses: peaceiris/actions-hugo@v2 - with: - hugo-version: "latest" - - name: ✨ Setup NPM - uses: bahmutov/npm-install@v1 - - name: 🛠️ Build - run: hugo - - name: 🔑 Install SSH Key - run: | - install -m 600 -D /dev/null ~/.ssh/id_rsa - echo "${{ secrets.RSYNC_PRIVATE_SSH_KEY }}" > ~/.ssh/id_rsa - echo "${{ secrets.RSYNC_KNOWN_HOSTS }}" > ~/.ssh/known_hosts - - name: 🚀 Deploy - run: rsync -rpzv --exclude="screenshots" -e 'ssh -p ${{ secrets.RSYNC_REMOTE_PORT }}' './public/' ${{ secrets.RSYNC_REMOTE_USER }}@${{ secrets.RSYNC_REMOTE_HOST }}:${{ secrets.RSYNC_REMOTE_FOLDER }} diff --git a/.github/workflows/deploy-preproduction.yml b/.github/workflows/deploy.yml similarity index 54% rename from .github/workflows/deploy-preproduction.yml rename to .github/workflows/deploy.yml index b85b5ab2..88e6a2a8 100644 --- a/.github/workflows/deploy-preproduction.yml +++ b/.github/workflows/deploy.yml @@ -1,13 +1,33 @@ -name: Déploiement RSYNC en preproduction +name: RSYNC Deploy on: push: tags: - - "v*.*.*-preproduction" + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+]" jobs: + env: + name: Get deploy environment based on tag suffix + runs-on: ubuntu-latest + outputs: + target-env: ${{ steps.get_environment.outputs.target-env }} + steps: + - name: 🛒 Checkout + uses: actions/checkout@v3 + - name: 🚀 Get Environment + id: get_environment + run: | + if [[ ${{ github.ref }} == *"rc"* ]]; then + echo "target-env: preproduction" > $GITHUB_OUTPUT + else + echo "target-env: production" > $GITHUB_OUTPUT + fi + deploy: - environment: preproduction + needs: env + environment: + name: ${{ needs.env.outputs.target-env }} runs-on: ubuntu-latest steps: - name: 🛒 Checkout From c1592d78d826f3eff71022ae16f8c7d8bff86d59 Mon Sep 17 00:00:00 2001 From: Vincent Vatelot Date: Fri, 24 Nov 2023 10:39:26 +0100 Subject: [PATCH 3/3] ci: simplify trigger for rsync deploy --- .github/workflows/deploy.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 88e6a2a8..81049b89 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,8 +3,7 @@ name: RSYNC Deploy on: push: tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+]" + - "v*.*.*" jobs: env: @@ -18,9 +17,9 @@ jobs: - name: 🚀 Get Environment id: get_environment run: | - if [[ ${{ github.ref }} == *"rc"* ]]; then + if [[ ${{ github.ref }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$ ]]; then echo "target-env: preproduction" > $GITHUB_OUTPUT - else + elif [[ ${{ github.ref }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "target-env: production" > $GITHUB_OUTPUT fi