-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (38 loc) · 1.4 KB
/
cicd-publish-api-image-pr.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: Publish container image for API using PR head commit SHA as an image tag during PR
on: workflow_dispatch # run maually
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-api
jobs:
build-and-publish-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # This dynamically references the branch you trigger the workflow from
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get short SHA from PR head commit
id: get_sha
# if: ${{ github.event_name == 'pull_request' }}
run: echo "SHORT_SHA=$(echo '${{ github.event.pull_request.head.sha }}' | cut -c1-7)" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile.api
push: true
tags: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.SHORT_SHA }}
cache-from: type=gha
cache-to: type=gha,mode=max