From 652edcb2a20bff3d2ec3f92397f6a8cdf06d5f42 Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Fri, 20 Sep 2024 22:23:08 -0700 Subject: [PATCH] Task A-6: Switching to step outputs instead of GITHUB_ENV Refer to details in cleanup issue: Task A-6: https://github.com/e-mission/e-mission-docs/issues/1082#issuecomment-2364335425 --- .github/workflows/image_build_push.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/image_build_push.yml b/.github/workflows/image_build_push.yml index 2b780f8..c3c63e5 100644 --- a/.github/workflows/image_build_push.yml +++ b/.github/workflows/image_build_push.yml @@ -18,22 +18,21 @@ jobs: build: runs-on: ubuntu-latest - env: - DOCKER_TAG_FROM_WORKFLOW_DISPATCH: ${{ github.event.inputs.docker_image_tag }} - steps: - uses: actions/checkout@v4 - - name: Set docker image tag from .env file + - name: Set docker image tags + id: set-tags run: | set -a; source .env; set +a - echo "DOCKER_TAG_FROM_PUSH=${SERVER_IMAGE_TAG}" >> $GITHUB_ENV + echo "DOCKER_TAG_FROM_PUSH=${SERVER_IMAGE_TAG}" >> "$GITHUB_OUTPUT" + echo "DOCKER_TAG_FROM_WORKFLOW_DISPATCH=${{ github.event.inputs.docker_image_tag }}" >> "$GITHUB_OUTPUT" - name: Print input docker image tag run: | echo "Event name: ${{ github.event_name }}" - echo "Latest docker image tag (push): ${{ env.DOCKER_TAG_FROM_PUSH }}" - echo "Latest docker image tag (workflow_dispatch): ${{ env.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" + echo "Latest docker image tag (push): ${{ steps.set-tags.outputs.DOCKER_TAG_FROM_PUSH }}" + echo "Latest docker image tag (workflow_dispatch): ${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" - name: docker login run: | # log into docker hub account @@ -41,7 +40,7 @@ jobs: - name: Get current date # get the date of the build id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d--%M-%S')" + run: echo "date=$(date +'%Y-%m-%d--%M-%S')" >> "$GITHUB_OUTPUT" - name: Run a one-line script run: echo running in repo ${GITHUB_REPOSITORY#*/} branch ${GITHUB_REF##*/} on ${{ steps.date.outputs.date }} @@ -49,9 +48,9 @@ jobs: - name: build docker image run: | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then - SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_WORKFLOW_DISPATCH docker compose -f docker-compose-prod.yml build + SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }} docker compose -f docker-compose-prod.yml build else - SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_PUSH docker compose -f docker-compose-prod.yml build + SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_PUSH }} docker compose -f docker-compose-prod.yml build fi docker images @@ -67,7 +66,7 @@ jobs: run: | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then echo "Workflow_dispatch: New server image built and pushed, Updating image tag in .env" - echo "SERVER_IMAGE_TAG=$DOCKER_TAG_FROM_WORKFLOW_DISPATCH" > .env + echo "SERVER_IMAGE_TAG=${{ steps.set-tags.outputs.DOCKER_TAG_FROM_WORKFLOW_DISPATCH }}" > .env else echo "Push event: Restoring latest server image tag from .env" fi