Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.

Commit e7f757a

Browse files
committed
feat: Split workflow/shared workflow
To support building PRs with same pipeline
1 parent bd60a1d commit e7f757a

File tree

5 files changed

+286
-221
lines changed

5 files changed

+286
-221
lines changed

.github/workflows/Manual_Publish_Docker.yml

Lines changed: 0 additions & 221 deletions
This file was deleted.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Shared Docker Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
required: true
8+
type: string
9+
build_all:
10+
type: boolean
11+
default: false
12+
build_base:
13+
type: boolean
14+
default: false
15+
build_build:
16+
type: boolean
17+
default: false
18+
build_sm:
19+
type: boolean
20+
default: false
21+
skip_release_main_build:
22+
type: boolean
23+
default: false
24+
release_as_latest:
25+
type: boolean
26+
default: false
27+
secrets:
28+
GITHUB_TOKEN:
29+
required: true
30+
31+
permissions:
32+
contents: read
33+
packages: write
34+
35+
env:
36+
REGISTRY: ghcr.io
37+
BASE_IMAGE_NAME: ${{ github.repository_owner }}/streammaster-builds
38+
FINAL_IMAGE_NAME: ${{ github.repository_owner }}/streammaster
39+
40+
jobs:
41+
setup:
42+
runs-on: ubuntu-latest
43+
outputs:
44+
version: ${{ steps.gitversion.outputs.semVer }}
45+
branchName: ${{ steps.gitversion.outputs.branchName }}
46+
buildMeta: ${{ steps.gitversion.outputs.buildMetadata }}
47+
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- name: Install GitVersion
54+
uses: gittools/actions/gitversion/setup@v0
55+
with:
56+
versionSpec: "5.x"
57+
58+
- name: Determine Version
59+
id: gitversion
60+
uses: gittools/actions/gitversion/execute@v0
61+
62+
test:
63+
needs: [setup]
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v4
67+
68+
- name: Generate code hash
69+
id: hash
70+
run: |
71+
find src -type f \( -name "*.cs" -o -name "*.csproj" -o -name "*.json" -o -name "*.xml" \) -print0 | sort -z | xargs -0 sha256sum | sha256sum | cut -d' ' -f1 > code_hash.txt
72+
echo "code_hash=$(cat code_hash.txt)" >> $GITHUB_OUTPUT
73+
74+
- name: Check code hash cache
75+
id: cache-hash
76+
uses: actions/cache@v4
77+
with:
78+
path: code_hash.txt
79+
key: ${{ runner.os }}-code-${{ steps.hash.outputs.code_hash }}
80+
81+
- name: Set up Docker Buildx
82+
if: steps.cache-hash.outputs.cache-hit != 'true'
83+
uses: docker/setup-buildx-action@v2
84+
85+
- name: Run Tests
86+
run: |
87+
docker buildx build \
88+
--platform linux/amd64 \
89+
-f Dockerfile.tests \
90+
--progress=plain \
91+
--no-cache \
92+
.
93+
94+
build:
95+
needs: [setup, test]
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@v4
99+
100+
- name: Set up Docker Buildx
101+
uses: docker/setup-buildx-action@v2
102+
103+
- name: Login to GHCR
104+
uses: docker/login-action@v2
105+
with:
106+
registry: ${{ env.REGISTRY }}
107+
username: ${{ github.actor }}
108+
password: ${{ secrets.GITHUB_TOKEN }}
109+
110+
- name: Base - Build and Push
111+
if: ${{ inputs.build_base || inputs.build_all }}
112+
run: |
113+
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-base -f Dockerfile.base --push .
114+
115+
- name: Build - Build and Push
116+
if: ${{ inputs.build_build || inputs.build_all }}
117+
run: |
118+
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-build -f Dockerfile.build --push .
119+
120+
- name: SM - Build and Push
121+
if: ${{ inputs.build_sm || inputs.build_all }}
122+
run: |
123+
set -e
124+
echo "FROM --platform=\$BUILDPLATFORM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-build AS build" > Dockerfile.sm
125+
cat Dockerfile.sm.template >> Dockerfile.sm
126+
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-sm -f Dockerfile.sm --push .
127+
128+
- name: Final - Build and Push
129+
if: ${{ !inputs.skip_release_main_build }}
130+
run: |
131+
set -e
132+
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-sm AS sm" > Dockerfile
133+
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-base AS base" >> Dockerfile
134+
cat Dockerfile.template >> Dockerfile
135+
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:${{ inputs.version }} -t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:${{ inputs.release_as_latest && 'latest' || needs.setup.outputs.branchName }} -f Dockerfile --push .

.github/workflows/pr-build.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: PR Docker Build
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
build:
9+
uses: ./.github/workflows/docker-build-shared.yml
10+
with:
11+
version: pr-${{ github.event.pull_request.number }}
12+
build_all: true
13+
release_as_latest: false
14+
secrets:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)