| 
 | 1 | +name: Build and Push Docker Image  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  push:  | 
 | 5 | +    branches:  | 
 | 6 | +      - main  | 
 | 7 | +    tags:  | 
 | 8 | +      - 'v*'  | 
 | 9 | +  pull_request:  | 
 | 10 | +    branches:  | 
 | 11 | +      - main  | 
 | 12 | + | 
 | 13 | +env:  | 
 | 14 | +  ECR_REGISTRY: ${{ vars.ECR_REGISTRY }}  | 
 | 15 | +  ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }}  | 
 | 16 | +  AWS_REGION: ${{ vars.AWS_REGION }}  | 
 | 17 | + | 
 | 18 | +permissions:  | 
 | 19 | +  id-token: write  | 
 | 20 | +  contents: read  | 
 | 21 | +  actions: read  | 
 | 22 | + | 
 | 23 | +jobs:  | 
 | 24 | +  build-and-test:  | 
 | 25 | +    runs-on: [mend-self-hosted, profile=sast-qa]  | 
 | 26 | + | 
 | 27 | +    steps:  | 
 | 28 | +      - name: Checkout code  | 
 | 29 | +        uses: actions/checkout@v4  | 
 | 30 | + | 
 | 31 | +      - name: Setup Go  | 
 | 32 | +        uses: actions/setup-go@v5  | 
 | 33 | +        with:  | 
 | 34 | +          go-version: '1.24.4'  | 
 | 35 | + | 
 | 36 | +      - name: Install Task  | 
 | 37 | +        uses: arduino/setup-task@v2  | 
 | 38 | + | 
 | 39 | +      - name: Run unit tests  | 
 | 40 | +        run: task test  | 
 | 41 | + | 
 | 42 | +      - name: Run build (local Go binary)  | 
 | 43 | +        run: task app:build  | 
 | 44 | + | 
 | 45 | +      - name: Configure AWS credentials  | 
 | 46 | +        uses: aws-actions/configure-aws-credentials@v4  | 
 | 47 | +        with:  | 
 | 48 | +          role-to-assume: ${{ vars.AWS_IAM_ROLE_ARN }}  | 
 | 49 | +          role-session-name: GitHubActionsSession  | 
 | 50 | +          aws-region: ${{ env.AWS_REGION }}  | 
 | 51 | + | 
 | 52 | +      - name: Login to Amazon ECR  | 
 | 53 | +        id: login-ecr  | 
 | 54 | +        uses: aws-actions/amazon-ecr-login@v2  | 
 | 55 | + | 
 | 56 | +      - name: Extract metadata  | 
 | 57 | +        id: meta  | 
 | 58 | +        uses: docker/metadata-action@v5  | 
 | 59 | +        with:  | 
 | 60 | +          images: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}  | 
 | 61 | +          tags: |  | 
 | 62 | +            type=ref,event=branch  | 
 | 63 | +            type=ref,event=pr  | 
 | 64 | +            type=sha,prefix=sha-,format=short  | 
 | 65 | +            type=raw,value=latest,enable={{is_default_branch}}  | 
 | 66 | +
  | 
 | 67 | +      - name: Build and push Docker image  | 
 | 68 | +        uses: docker/build-push-action@v5  | 
 | 69 | +        with:  | 
 | 70 | +          context: .  | 
 | 71 | +          push: ${{ github.event_name != 'pull_request' }}  | 
 | 72 | +          tags: ${{ steps.meta.outputs.tags }}  | 
 | 73 | +          labels: ${{ steps.meta.outputs.labels }}  | 
0 commit comments