1+ name : DEV - Build and Push to GHCR
2+
3+ on :
4+ pull_request :
5+ types :
6+ - closed
7+ branches :
8+ - dev
9+
10+ permissions :
11+ contents : write
12+ pull-requests : write
13+ packages : write
14+
15+ env :
16+ IMAGE_NAME : coordinatecore
17+ ENV_TYPE : dev
18+
19+ jobs :
20+ build-and-push :
21+ name : Build and Push Docker Image
22+ if : ${{ github.event.pull_request.merged == true }}
23+ runs-on : governance-testenv-github-self-hosted
24+
25+ steps :
26+ - name : Checkout Code
27+ uses : actions/checkout@v4
28+
29+ - name : Cache CMake build
30+ uses : actions/cache@v3
31+ with :
32+ path : |
33+ build
34+ ~/.cache
35+ key : ${{ runner.os }}-cmake-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp', '**/*.h') }}
36+ restore-keys : |
37+ ${{ runner.os }}-cmake-${{ hashFiles('**/CMakeLists.txt') }}-
38+ ${{ runner.os }}-cmake-
39+
40+ - name : Cache apt packages
41+ uses : actions/cache@v3
42+ with :
43+ path : /var/cache/apt/archives
44+ key : ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/*.yml') }}
45+ restore-keys : |
46+ ${{ runner.os }}-apt-
47+
48+ - name : Create new tag (semantic versioning)
49+ id : tag
50+ uses :
mathieudutour/[email protected] 51+ with :
52+ github_token : ${{ secrets.GITHUB_TOKEN }}
53+ release_branches : dev,main
54+ default_bump : patch # can be major/minor/patch
55+
56+ - name : Set lowercase owner name
57+ id : lowercase
58+ run : |
59+ echo "owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
60+
61+ - name : Install Dependencies
62+ run : |
63+ # Wait for apt lock to be released
64+ while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do
65+ echo "Waiting for other apt processes to finish..."
66+ sleep 5
67+ done
68+
69+ sudo apt-get update && sudo apt-get install -y \
70+ build-essential \
71+ cmake \
72+ libtool \
73+ autotools-dev \
74+ automake \
75+ pkg-config \
76+ bsdmainutils \
77+ python3 \
78+ libevent-dev \
79+ libboost-dev \
80+ libsqlite3-dev \
81+ libminiupnpc-dev \
82+ libnatpmp-dev \
83+ libzmq3-dev \
84+ systemtap-sdt-dev \
85+ curl
86+
87+ - name : Configure with CMake
88+ run : cmake -B build -DWITH_ZMQ=ON
89+
90+ - name : Build with CMake
91+ run : cmake --build build
92+
93+ - name : Verify build artifacts
94+ run : ls -la build/bin/
95+
96+ - name : Fix Docker socket permissions
97+ run : |
98+ sudo chmod 666 /var/run/docker.sock
99+
100+ - name : Set up Docker Buildx
101+ uses : docker/setup-buildx-action@v3
102+
103+ - name : Log in to GitHub Container Registry
104+ uses : docker/login-action@v3
105+ with :
106+ registry : ghcr.io
107+ username : ${{ github.actor }}
108+ password : ${{ secrets.GITHUB_TOKEN }}
109+
110+ - name : Extract metadata (tags, labels) for Docker
111+ id : meta
112+ uses : docker/metadata-action@v5
113+ with :
114+ images : ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ env.IMAGE_NAME }}
115+ tags : |
116+ type=raw,value=${{ steps.tag.outputs.new_tag }}
117+ type=raw,value=latest
118+ type=ref,event=branch
119+
120+ - name : Build and Push Docker Image
121+ uses : docker/build-push-action@v5
122+ with :
123+ context : .
124+ push : true
125+ tags : ${{ steps.meta.outputs.tags }}
126+ labels : ${{ steps.meta.outputs.labels }}
127+ cache-from : type=registry,ref=ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ env.IMAGE_NAME }}:buildcache
128+ cache-to : type=registry,ref=ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
0 commit comments