Skip to content

Commit

Permalink
Task A-6: Switching to step outputs instead of GITHUB_ENV
Browse files Browse the repository at this point in the history
Refer to details in cleanup issue:
Task A-6: e-mission/e-mission-docs#1082 (comment)
  • Loading branch information
Mahadik, Mukul Chandrakant authored and Mahadik, Mukul Chandrakant committed Sep 21, 2024
1 parent 072a363 commit 652edcb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/image_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,39 @@ 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
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- 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 }}

- 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
Expand All @@ -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
Expand Down

0 comments on commit 652edcb

Please sign in to comment.