Skip to content

Update IMAGE_TAG handling in GitHub Actions workflows #44

Update IMAGE_TAG handling in GitHub Actions workflows

Update IMAGE_TAG handling in GitHub Actions workflows #44

Workflow file for this run

name: Build and Push to Registry
on:
push:
branches:
- live
release:
types: [published]
env:
IMAGE_TAG: ${{ github.ref_type == 'tag' && github.ref || contains(github.event.head_commit.message, 'latest') && 'latest' || 'dev' }}
jobs:
build-and-push:
if: contains(github.event.head_commit.message, 'BUILD') || github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go 1.22.x
uses: actions/setup-go@v4
with:
go-version: "1.22.x"
- name: Install Go dependencies
run: go mod download
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Replace "refs/tags/" in IMAGE_TAG
uses: bhaidar/string-replace-action@v0.2.0
with:
file: ${{ github.workflow_path }}
find: 'IMAGE_TAG: "refs/tags/"'
replace: 'IMAGE_TAG: ""'
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG