From 904bc6ed0326ab1b4049f408b4e413f63ebd600e Mon Sep 17 00:00:00 2001 From: DanVanAtta Date: Tue, 9 Jul 2024 17:44:43 -0700 Subject: [PATCH] Build files, cleanup if statements with an env variable Inspired by this blog post: https://kevsoft.net/2020/06/10/running-github-action-steps-and-jobs-only-on-push-to-master.html --- .github/workflows/master.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 6649519..104a8e4 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -10,6 +10,8 @@ on: - master jobs: build: + env: + IS_MASTER_BUILD: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -26,19 +28,19 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Login to GitHub Container Registry - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ env.IS_MASTER_BUILD }} uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: build database docker container - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ env.IS_MASTER_BUILD }} run: | docker build database/sql --tag ghcr.io/triplea-game/lobby/flyway:latest docker push ghcr.io/triplea-game/lobby/flyway:latest - name: build server docker container - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ env.IS_MASTER_BUILD }} run: | docker build . --tag ghcr.io/triplea-game/lobby/server:latest docker push ghcr.io/triplea-game/lobby/server:latest