forked from ministryofjustice/fb-user-datastore
-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (45 loc) · 1.29 KB
/
build_image.yaml
File metadata and controls
54 lines (45 loc) · 1.29 KB
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
48
49
50
51
52
53
54
name: Build and Push Image
on:
push:
branches:
- '**'
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: cabinetoffice/fb-user-datastore-api
jobs:
build-fb-user-datastore-api:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Compute tag
id: tag
shell: bash
run: |
set -euo pipefail
sha="${GITHUB_SHA}"
short_sha="${sha:0:7}"
ref="${GITHUB_REF_NAME}"
if [[ "$ref" == "main" ]]; then
tag="main-${short_sha}"
else
# Sanitize branch name for Docker tag compatibility.
safe_ref="$(echo "$ref" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_.-]/-/g')"
tag="branch-${safe_ref}-${short_sha}"
fi
echo "value=$tag" >> "$GITHUB_OUTPUT"
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.value }}