From 266c0777ef32dfd789ae3002dcbdc93b2548be67 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Wed, 30 Jul 2025 22:42:45 +0200 Subject: [PATCH] ci: Make further steps conditional on the environment being changed --- .github/workflows/deploy.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index e98759f..bbae594 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -29,20 +29,23 @@ jobs: steps: - uses: actions/checkout@v4 - name: Exit if this environment wasn't changed + id: check run: | echo "Changed envs: '${{ needs.fact-finding.outputs.changed_envs }}'" if [[ ! " ${{ needs.fact-finding.outputs.changed_envs }} " =~ " ${{ matrix.env }} " ]]; then - echo "Environment '${{ matrix.env }}' was not modified. Skipping." - exit 0 + echo "should_deploy=true" >> $GITHUB_OUTPUT + else + echo "should_deploy=false" >> $GITHUB_OUTPUT fi + shell: bash - name: Build & push Nginx image to GHCR - if: steps.detect.outputs.changed_envs != '' + if: steps.check.outputs.should_deploy == 'true' run: | docker build -t ghcr.io/2martens/docker-nginx:${{ matrix.env }} docker/${{ matrix.env }}/nginx echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u 2martens --password-stdin docker push ghcr.io/2martens/docker-nginx:${{ matrix.env }} - name: Copy files to remote - if: steps.detect.outputs.changed_envs != '' + if: steps.check.outputs.should_deploy == 'true' uses: burnett01/rsync-deployments@7.0.2 with: switches: -az -r --del @@ -53,6 +56,7 @@ jobs: remote_user: ${{ secrets.DEPLOY_USER }} remote_key: ${{ secrets.DEPLOY_KEY }} - name: Deploy applications + if: steps.check.outputs.should_deploy == 'true' uses: appleboy/ssh-action@v1 with: host: ${{ secrets.DEPLOY_HOST }}