From 27ae5bcb32b5d99d2e8422548b33a583e0f792c9 Mon Sep 17 00:00:00 2001 From: Andreas Hnida Date: Mon, 29 Jul 2024 12:51:59 +0200 Subject: [PATCH 1/2] exchanged env variable evaluation for making the build dependent on the pushed branch using"github.ref == " --- .../workflows/build-and-deploy-pipeline.yaml | 107 ++++++++++++++++-- 1 file changed, 95 insertions(+), 12 deletions(-) diff --git a/.gitea/workflows/build-and-deploy-pipeline.yaml b/.gitea/workflows/build-and-deploy-pipeline.yaml index 3711e72..38d0284 100644 --- a/.gitea/workflows/build-and-deploy-pipeline.yaml +++ b/.gitea/workflows/build-and-deploy-pipeline.yaml @@ -4,8 +4,7 @@ on: push: branches: - main - - kontaktformular-filter-spam - + - dev env: PROD_USER: verua.swiss @@ -23,15 +22,15 @@ jobs: steps: - uses: actions/checkout@v2.4.0 - - name: env-toml-file - uses: SebRollen/toml-action@v1.2.0 - id: read_toml - with: - file: 'hugo.toml' - field: 'params.environment' + # - name: env-toml-file + # uses: SebRollen/toml-action@v1.2.0 + # id: read_toml + # with: + # file: 'hugo.toml' + # field: 'params.environment' - - name: Echo environment - run: echo "Environment is ${{ steps.read_toml.outputs.value }}" + # - name: Echo environment + # run: echo "Environment is ${{ steps.read_toml.outputs.value }}" - name: Set up Go uses: actions/setup-go@v5.0.0 @@ -68,7 +67,7 @@ jobs: ssh-private-key: ${{ secrets.VFO_SSH_KEY }} - name: Deploy to Development - if: steps.read_toml.outputs.value == 'development' + if: github.ref == 'refs/heads/dev' run: | echo "Running steps for Development Environment" echo "user: $DEV_USER host: $DEV_HOST path: $DEV_PATH" @@ -77,9 +76,93 @@ jobs: RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no' - name: Deploy to Production - if: steps.read_toml.outputs.value == 'production' + if: github.ref == 'refs/heads/main' run: | echo "Running steps for Production Environment" rsync -avz ./public/ $PROD_USER@$PROD_HOST:$PROD_PATH env: RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no' +# name: Build and Deploy Hugo Site + +# on: +# push: +# branches: +# - main +# - kontaktformular-filter-spam + +# env: +# PROD_USER: verua.swiss +# PROD_HOST: verua.swiss +# PROD_PATH: httpdocs +# DEV_USER: verua.info +# DEV_HOST: verua.info +# DEV_PATH: preview/httpdocs + +# jobs: +# buildAndDeploy: +# env: +# RUNNER_TOOL_CACHE: /toolcache +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2.4.0 + +# - name: env-toml-file +# uses: SebRollen/toml-action@v1.2.0 +# id: read_toml +# with: +# file: 'hugo.toml' +# field: 'params.environment' + +# - name: Echo environment +# run: echo "Environment is ${{ steps.read_toml.outputs.value }}" + +# - name: Set up Go +# uses: actions/setup-go@v5.0.0 +# with: +# go-version: '1.20.5' + +# - name: Set up Node.js +# uses: actions/setup-node@v4.0.2 +# with: +# node-version: '20' +# cache: 'npm' + +# - name: Setup Project +# run: npm run project-setup + +# - name: Install npm dependencies +# run: npm install + +# - name: Set up Hugo Extended +# uses: peaceiris/actions-hugo@v3.0.0 +# with: +# hugo-version: '0.121.2' +# extended: true + +# - name: Build Hugo site +# run: hugo --minify + +# - name: Setup rsync +# run: apt-get update && apt-get install -y rsync + +# - name: Setup SSH Key +# uses: webfactory/ssh-agent@v0.5.3 +# with: +# ssh-private-key: ${{ secrets.VFO_SSH_KEY }} + +# - name: Deploy to Development +# if: steps.read_toml.outputs.value == 'development' +# run: | +# echo "Running steps for Development Environment" +# echo "user: $DEV_USER host: $DEV_HOST path: $DEV_PATH" +# rsync -avz ./public/ $DEV_USER@$DEV_HOST:$DEV_PATH +# env: +# RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no' + +# - name: Deploy to Production +# if: steps.read_toml.outputs.value == 'production' +# run: | +# echo "Running steps for Production Environment" +# rsync -avz ./public/ $PROD_USER@$PROD_HOST:$PROD_PATH +# env: +# RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no' From 9e14138c3bc399073cfce1ee3f18e8964527c3a9 Mon Sep 17 00:00:00 2001 From: Andreas Hnida Date: Mon, 29 Jul 2024 12:54:54 +0200 Subject: [PATCH 2/2] cleaned up commented code --- .../workflows/build-and-deploy-pipeline.yaml | 94 ------------------- 1 file changed, 94 deletions(-) diff --git a/.gitea/workflows/build-and-deploy-pipeline.yaml b/.gitea/workflows/build-and-deploy-pipeline.yaml index 38d0284..9e2b580 100644 --- a/.gitea/workflows/build-and-deploy-pipeline.yaml +++ b/.gitea/workflows/build-and-deploy-pipeline.yaml @@ -22,16 +22,6 @@ jobs: steps: - uses: actions/checkout@v2.4.0 - # - name: env-toml-file - # uses: SebRollen/toml-action@v1.2.0 - # id: read_toml - # with: - # file: 'hugo.toml' - # field: 'params.environment' - - # - name: Echo environment - # run: echo "Environment is ${{ steps.read_toml.outputs.value }}" - - name: Set up Go uses: actions/setup-go@v5.0.0 with: @@ -82,87 +72,3 @@ jobs: rsync -avz ./public/ $PROD_USER@$PROD_HOST:$PROD_PATH env: RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no' -# name: Build and Deploy Hugo Site - -# on: -# push: -# branches: -# - main -# - kontaktformular-filter-spam - -# env: -# PROD_USER: verua.swiss -# PROD_HOST: verua.swiss -# PROD_PATH: httpdocs -# DEV_USER: verua.info -# DEV_HOST: verua.info -# DEV_PATH: preview/httpdocs - -# jobs: -# buildAndDeploy: -# env: -# RUNNER_TOOL_CACHE: /toolcache -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v2.4.0 - -# - name: env-toml-file -# uses: SebRollen/toml-action@v1.2.0 -# id: read_toml -# with: -# file: 'hugo.toml' -# field: 'params.environment' - -# - name: Echo environment -# run: echo "Environment is ${{ steps.read_toml.outputs.value }}" - -# - name: Set up Go -# uses: actions/setup-go@v5.0.0 -# with: -# go-version: '1.20.5' - -# - name: Set up Node.js -# uses: actions/setup-node@v4.0.2 -# with: -# node-version: '20' -# cache: 'npm' - -# - name: Setup Project -# run: npm run project-setup - -# - name: Install npm dependencies -# run: npm install - -# - name: Set up Hugo Extended -# uses: peaceiris/actions-hugo@v3.0.0 -# with: -# hugo-version: '0.121.2' -# extended: true - -# - name: Build Hugo site -# run: hugo --minify - -# - name: Setup rsync -# run: apt-get update && apt-get install -y rsync - -# - name: Setup SSH Key -# uses: webfactory/ssh-agent@v0.5.3 -# with: -# ssh-private-key: ${{ secrets.VFO_SSH_KEY }} - -# - name: Deploy to Development -# if: steps.read_toml.outputs.value == 'development' -# run: | -# echo "Running steps for Development Environment" -# echo "user: $DEV_USER host: $DEV_HOST path: $DEV_PATH" -# rsync -avz ./public/ $DEV_USER@$DEV_HOST:$DEV_PATH -# env: -# RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no' - -# - name: Deploy to Production -# if: steps.read_toml.outputs.value == 'production' -# run: | -# echo "Running steps for Production Environment" -# rsync -avz ./public/ $PROD_USER@$PROD_HOST:$PROD_PATH -# env: -# RSYNC_RSH: 'ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no'