-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Split workflow/shared workflow
To support building PRs with same pipeline
- Loading branch information
Showing
5 changed files
with
299 additions
and
221 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
name: Shared Docker Build | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
version: | ||
required: true | ||
type: string | ||
build_all: | ||
type: boolean | ||
default: false | ||
build_base: | ||
type: boolean | ||
default: false | ||
build_build: | ||
type: boolean | ||
default: false | ||
build_sm: | ||
type: boolean | ||
default: false | ||
skip_release_main_build: | ||
type: boolean | ||
default: false | ||
release_as_latest: | ||
type: boolean | ||
default: false | ||
secrets: | ||
token: | ||
required: true | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
BASE_IMAGE_NAME: ${{ github.repository_owner }}/streammaster-builds | ||
FINAL_IMAGE_NAME: ${{ github.repository_owner }}/streammaster | ||
|
||
jobs: | ||
setup: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.gitversion.outputs.semVer }} | ||
branchName: ${{ steps.gitversion.outputs.branchName }} | ||
buildMeta: ${{ steps.gitversion.outputs.buildMetadata }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install GitVersion | ||
uses: gittools/actions/gitversion/setup@v0 | ||
with: | ||
versionSpec: "5.x" | ||
|
||
- name: Determine Version | ||
id: gitversion | ||
uses: gittools/actions/gitversion/execute@v0 | ||
|
||
test: | ||
needs: [setup] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Generate code hash | ||
id: hash | ||
run: | | ||
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 | ||
echo "code_hash=$(cat code_hash.txt)" >> $GITHUB_OUTPUT | ||
- name: Check code hash cache | ||
id: cache-hash | ||
uses: actions/cache@v4 | ||
with: | ||
path: code_hash.txt | ||
key: ${{ runner.os }}-code-${{ steps.hash.outputs.code_hash }} | ||
|
||
- name: Set up Docker Buildx | ||
if: steps.cache-hash.outputs.cache-hit != 'true' | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Run Tests | ||
run: | | ||
docker buildx build \ | ||
--platform linux/amd64 \ | ||
-f Dockerfile.tests \ | ||
--progress=plain \ | ||
--no-cache \ | ||
. | ||
build: | ||
needs: [setup, test] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GHCR | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.token }} | ||
|
||
- name: Base - Build and Push | ||
if: ${{ inputs.build_base || inputs.build_all }} | ||
run: | | ||
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-base -f Dockerfile.base --push . | ||
- name: Build - Build and Push | ||
if: ${{ inputs.build_build || inputs.build_all }} | ||
run: | | ||
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-build -f Dockerfile.build --push . | ||
- name: SM - Build and Push | ||
if: ${{ inputs.build_sm || inputs.build_all }} | ||
run: | | ||
set -e | ||
echo "FROM --platform=\$BUILDPLATFORM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-build AS build" > Dockerfile.sm | ||
cat Dockerfile.sm.template >> Dockerfile.sm | ||
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-sm -f Dockerfile.sm --push . | ||
- name: Final - Build and Push | ||
if: ${{ !inputs.skip_release_main_build }} | ||
run: | | ||
set -e | ||
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-sm AS sm" > Dockerfile | ||
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-base AS base" >> Dockerfile | ||
cat Dockerfile.template >> Dockerfile | ||
docker buildx build --platform linux/amd64,linux/arm64 \ | ||
-t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:${{ inputs.version }} \ | ||
-t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:$(echo "${{ needs.setup.outputs.branchName }}" | tr '/' '-') \ | ||
-f Dockerfile --push . | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: PR Docker Build | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/docker-build-shared.yml | ||
with: | ||
version: pr-${{ github.event.pull_request.number }} | ||
build_all: true | ||
release_as_latest: false | ||
secrets: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
Oops, something went wrong.