-
Notifications
You must be signed in to change notification settings - Fork 12
104 lines (89 loc) · 2.95 KB
/
push-to-registry.yml
File metadata and controls
104 lines (89 loc) · 2.95 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# yaml-language-server: $schema=https://www.schemastore.org/github-workflow.json
---
name: Push to registry
on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*.*.*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install node 24
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Install latest npm
run: npm install -g [email protected]
- name: Install project modules
run: npm ci
- name: Compile project
run: npm run compile
- name: Determine package version
id: version
run: |
if [[ "${GITHUB_REF}" =~ refs/tags/ ]]; then
# Release tag
VERSION="${GITHUB_REF#refs/tags/v}"
EA_BUILD=false
elif [ "${GITHUB_REF}" = "refs/heads/main" ]; then
# EA build for main
BASE=$(node -p "require('./package.json').version" | sed -E 's/-ea[.-][0-9]+$//')
SHORT_SHA=$(git rev-parse --short "${GITHUB_SHA}")
VERSION="${BASE}-ea.${SHORT_SHA}"
EA_BUILD=true
else
echo "Not building image for this branch"
exit 0
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "ea_build=$EA_BUILD" >> $GITHUB_OUTPUT
- name: Get image metadata
id: image-meta
run: |
echo "revision=${{ github.sha }}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ steps.version.outputs.ea_build == 'true' }}
type=raw,value=${{ steps.version.outputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./docker-image/Dockerfiles/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
IMAGE_VERSION=${{ steps.version.outputs.version }}
IMAGE_REVISION=${{ steps.image-meta.outputs.revision }}
IMAGE_CREATED=${{ steps.image-meta.outputs.created }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true