-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (112 loc) · 3.92 KB
/
cicd.yml
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Build and Push bilbomd-backend Docker Images
on:
push:
branches:
- main
tags:
- 'v*'
paths-ignore:
- '**/*.md'
pull_request:
branches:
- main
paths-ignore:
- '**/*.md'
jobs:
build-and-push-images:
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Debug GitHub Event
run: |
echo "Actor: ${{ github.actor }}"
echo "Event Name: ${{ github.event_name }}"
echo "Event Payload: ${{ toJSON(github.event) }}"
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Configure npm registry
run: |
echo "@bl1231:registry=https://npm.pkg.github.com" >> .npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
- name: Install npm dependencies
run: npm ci
- name: Run npm build to test Typescript transpilation
run: npm run build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}/bilbomd-backend
tags: |
type=raw,value=latest
labels: ${{ steps.meta.outputs.labels }}
- name: Generate version from tag
id: version
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Get version from package.json
id: get_version
run: echo "BILBOMD_BACKEND_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
- name: Determine commit hash
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "GIT_HASH=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-7)" >> $GITHUB_ENV
else
echo "GIT_HASH=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
fi
- name: Build and push bilbomd-backend Docker image (latest)
uses: docker/build-push-action@v5
with:
context: .
file: bilbomd-backend.dockerfile
push: true
platforms: linux/amd64
tags: |
ghcr.io/${{ github.repository }}:latest
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
USER_ID=${{ vars.USER_ID }}
GROUP_ID=${{ vars.GROUP_ID }}
BILBOMD_BACKEND_GIT_HASH=${{ env.GIT_HASH }}
BILBOMD_BACKEND_VERSION=${{ env.BILBOMD_BACKEND_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push bilbomd-backend Docker image (versioned)
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v5
with:
context: .
file: bilbomd-backend.dockerfile
push: true
platforms: linux/amd64
tags: |
ghcr.io/${{ github.repository }}:${{ env.BILBOMD_BACKEND_VERSION }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
USER_ID=${{ vars.USER_ID }}
GROUP_ID=${{ vars.GROUP_ID }}
BILBOMD_BACKEND_GIT_HASH=${{ env.GIT_HASH }}
BILBOMD_BACKEND_VERSION=${{ env.BILBOMD_BACKEND_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max