Skip to content

Create testWebhook

Create testWebhook #12

name: Publish container image for API using PR head commit SHA as an image tag
on:
workflow_dispatch: # run manually
pull_request: # run on pull requests
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