Skip to content

Commit

Permalink
[TASK] GitHub Actions to build Slicer
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Jan 12, 2024
1 parent dff602b commit 4f48292
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build_all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build all

on:
push:
branches:
- boss
- release/*
paths:
- 'deps/**'
- 'src/**'
- '**/CMakeLists.txt'
- 'version.inc'
- 'resources/**'
- ".github/workflows/build_*.yml"

pull_request:
branches:
- boss
- release/*
paths:
- 'deps/**'
- 'src/**'
- '**/CMakeLists.txt'
- 'version.inc'
- ".github/workflows/build_*.yml"

workflow_dispatch: # allows for manual dispatch
inputs:
build-deps-only:
description: 'Only build dependencies (bypasses caching)'
type: boolean
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true


jobs:
build_all:
name: Build All
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
- os: windows-latest
- os: macos-12
arch: x86_64
- os: macos-12
arch: arm64
uses: ./.github/workflows/build_check_cache.yml
with:
os: ${{ matrix.os }}
arch: ${{ matrix.arch }}
build-deps-only: ${{ inputs.build-deps-only || false }}
secrets: inherit
58 changes: 58 additions & 0 deletions .github/workflows/build_check_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Check Cache

on:
workflow_call:
inputs:
os:
required: true
type: string
arch:
required: false
type: string
build-deps-only:
required: false
type: boolean

jobs:
check_cache: # determines if there is a cache and outputs variables used in caching process
name: Check Cache
runs-on: ${{ inputs.os }}
outputs:
cache-key: ${{ steps.set_outputs.outputs.cache-key }}
cache-path: ${{ steps.set_outputs.outputs.cache-path }}
valid-cache: ${{ steps.cache_deps.outputs.cache-hit }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: set outputs
id: set_outputs
env:
underscore-arch: ${{ inputs.os == 'macos-12' && '_' || ''}}${{ inputs.os == 'macos-12' && inputs.arch || '' }} # if is macos, make a string that does "_{arch}", else output nothing
dash-arch: ${{ inputs.os == 'macos-12' && '-' || ''}}${{ inputs.os == 'macos-12' && inputs.arch || '' }} # if is macos, make a string that does "-{arch}", else output nothing
dep-folder-name: ${{ (inputs.os == 'windows-latest' || inputs.os == 'macos-12') && 'PrusaSlicer_dep' || 'destdir' }}
output-cmd: ${{ inputs.os == 'windows-latest' && '$env:GITHUB_OUTPUT' || '"$GITHUB_OUTPUT"'}}
run: |
echo cache-key=${{ runner.os }}${{ env.dash-arch }}-cache-Prusaslicer_deps-build-${{ hashFiles('deps/**') }} >> ${{ env.output-cmd }}
echo cache-path=${{ github.workspace }}/deps/build${{ env.underscore-arch }}/${{ env.dep-folder-name }}${{ env.underscore-arch }} >> ${{ env.output-cmd }}
- name: load cache
id: cache_deps
uses: actions/cache@v3
with:
path: ${{ steps.set_outputs.outputs.cache-path }}
key: ${{ steps.set_outputs.outputs.cache-key }}
lookup-only: true

build_deps: # call next step
name: Build Deps
needs: [check_cache]
uses: ./.github/workflows/build_deps.yml
with:
cache-key: ${{ needs.check_cache.outputs.cache-key }}
cache-path: ${{ needs.check_cache.outputs.cache-path }}
valid-cache: ${{ needs.check_cache.outputs.valid-cache == 'true' }}
os: ${{ inputs.os }}
arch: ${{ inputs.arch }}
build-deps-only: ${{ inputs.build-deps-only }}
secrets: inherit
106 changes: 106 additions & 0 deletions .github/workflows/build_deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
on:
workflow_call:
inputs:
cache-key:
required: true
type: string
cache-path:
required: true
type: string
valid-cache:
required: true
type: boolean
os:
required: true
type: string
arch:
required: false
type: string
build-deps-only:
required: false
type: boolean

jobs:
build_deps:
name: Build Deps
if: inputs.build-deps-only || inputs.valid-cache != true
runs-on: ${{ inputs.os }}
env:
date:
steps:

# Setup the environment
- name: Checkout
uses: actions/checkout@v3

- name: load cached deps
uses: actions/cache@v3
with:
path: ${{ inputs.cache-path }}
key: ${{ inputs.cache-key }}

- name: setup dev on Windows
if: inputs.os == 'windows-latest'
uses: microsoft/setup-msbuild@v1.1

- name: Get the date on Ubuntu and macOS
if: inputs.os != 'windows-latest'
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV
shell: bash

- name: Get the date on Windows
if: inputs.os == 'windows-latest'
run: echo "date=$(Get-Date -Format 'yyyyMMdd')" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
shell: pwsh


# Build Dependencies
- name: Build on Windows
if: inputs.os == 'windows-latest'
working-directory: ${{ github.workspace }}
run: |
choco install strawberryperl
mkdir ${{ github.workspace }}/deps/build
mkdir ${{ github.workspace }}/deps/build/PrusaSlicer_dep
.\build_release_vs2022.bat deps
.\build_release_vs2022.bat pack
cd ${{ github.workspace }}/deps/build
- name: Build on Mac ${{ inputs.arch }}
if: inputs.os == 'macos-12'
working-directory: ${{ github.workspace }}
run: |
brew install cmake git gettext automake texinfo
brew list
mkdir -p ${{ github.workspace }}/deps/build_${{ inputs.arch }}
mkdir -p ${{ github.workspace }}/deps/build_${{ inputs.arch }}/PrusaSlicer_dep_${{ inputs.arch }}
brew uninstall --ignore-dependencies zstd
./build_release_macos.sh -dp -a ${{ inputs.arch }} -t 10.15
brew install zstd
# Upload Artifacts
- name: Upload Mac ${{ inputs.arch }} artifacts
if: inputs.os == 'macos-12'
uses: actions/upload-artifact@v3
with:
name: PrusaSlicer_dep_mac_${{ inputs.arch }}_${{ env.date }}
path: ${{ github.workspace }}/deps/build_${{ inputs.arch }}/PrusaSlicer_dep*.tar.gz

- name: Upload Windows artifacts
if: inputs.os == 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: PrusaSlicer_dep_win64_${{ env.date }}
path: ${{ github.workspace }}/deps/build/PrusaSlicer_dep*.zip

build_prusa:
name: Build PrusaSlicer
needs: [build_deps]
if: ${{ !cancelled() && !inputs.build-deps-only && (inputs.valid-cache == true && needs.build_deps.result == 'skipped') || (inputs.valid-cache != true && success()) }}
uses: ./.github/workflows/build_prusa.yml
with:
cache-key: ${{ inputs.cache-key }}
cache-path: ${{ inputs.cache-path }}
os: ${{ inputs.os }}
arch: ${{ inputs.arch }}
secrets: inherit
146 changes: 146 additions & 0 deletions .github/workflows/build_prusa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
on:
workflow_call:
inputs:
cache-key:
required: true
type: string
cache-path:
required: true
type: string
os:
required: true
type: string
arch:
required: false
type: string

jobs:
build_prusa:
name: Build PrusaSlicer
runs-on: ${{ inputs.os }}
env:
date:
ver:

steps:
- name: Checkout
uses: actions/checkout@v3

- name: load cached deps
uses: actions/cache@v3
with:
path: ${{ inputs.cache-path }}
key: ${{ inputs.cache-key }}
fail-on-cache-miss: true

- name: Get the version and date on Ubuntu and macOS
if: inputs.os != 'windows-latest'
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
ver="nightly$(date +'%y%m%d')"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
ver="PR${{ github.event.number }}"
else
ver=$(grep 'set(SoftFever_VERSION' version.inc | cut -d '"' -f2)
ver=V$ver
fi
echo "ver=$ver" >> $GITHUB_ENV
echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV
shell: bash

- name: Get the version and date on Windows
if: inputs.os == 'windows-latest'
run: |
$date = Get-Date -Format 'yyyyMMdd'
$ref = "${{ github.ref }}"
$eventName = "${{ github.event_name }}"
$prNumber = "${{ github.event.number }}"
if ($ref -eq 'refs/heads/main') {
$ver = "nightly" + $date.Substring(2)
} elseif ($eventName -eq 'pull_request') {
$ver = "PR" + $prNumber
} else {
$versionContent = Get-Content version.inc -Raw
if ($versionContent -match 'set\(SoftFever_VERSION "(.*?)"\)') {
$ver = $matches[1]
}
$ver = "V$ver"
}
echo "ver=$ver" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
echo "date=$date" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
echo "date: ${{ env.date }} version: ${{ env.ver }}"
shell: pwsh

# Mac
- name: Install tools mac
if: inputs.os == 'macos-12'
run: |
brew install cmake git gettext tree
brew list
mkdir -p ${{ github.workspace }}/deps/build_${{inputs.arch}}
mkdir -p ${{ github.workspace }}/deps/build_${{inputs.arch}}/PrusaSlicer_dep_${{inputs.arch}}
tree ${{ github.workspace }}/deps/build_${{inputs.arch}}/PrusaSlicer_dep_${{inputs.arch}}
- name: Build slicer mac
if: inputs.os == 'macos-12'
working-directory: ${{ github.workspace }}
run: |
./build_release_macos.sh -s -n -a ${{inputs.arch}} -t 10.15
- name: Create DMG without notary
if: github.ref != 'refs/heads/main' && inputs.os == 'macos-12'
working-directory: ${{ github.workspace }}
run: |
ln -s /Applications ${{ github.workspace }}/build_${{inputs.arch}}/PrusaSlicer/Applications
hdiutil create -volname "PrusaSlicer" -srcfolder ${{ github.workspace }}/build_${{inputs.arch}}/PrusaSlicer -ov -format UDZO PrusaSlicer_Mac_${{inputs.arch}}_${{ env.ver }}.dmg
- name: Upload artifacts mac
if: inputs.os == 'macos-12'
uses: actions/upload-artifact@v3
with:
name: PrusaSlicer_Mac_${{inputs.arch}}_${{ env.ver }}
path: ${{ github.workspace }}/PrusaSlicer_Mac_${{inputs.arch}}_${{ env.ver }}.dmg

# Windows
- name: setup MSVC
if: inputs.os == 'windows-latest'
uses: microsoft/setup-msbuild@v1.1

- name: Install nsis
if: inputs.os == 'windows-latest'
run: |
dir "C:/Program Files (x86)/Windows Kits/10/Include"
choco install nsis
- name: Build slicer Win
if: inputs.os == 'windows-latest'
working-directory: ${{ github.workspace }}
run: .\build_release_vs2022.bat slicer

- name: Create installer Win
if: inputs.os == 'windows-latest'
working-directory: ${{ github.workspace }}/build
run: |
cpack -G NSIS
- name: Pack app
if: inputs.os == 'windows-latest'
working-directory: ${{ github.workspace }}/build
shell: cmd
run: '"C:/Program Files/7-Zip/7z.exe" a -tzip PrusaSlicer_Windows_${{ env.ver }}_portable.zip ${{ github.workspace }}/build/PrusaSlicer'

- name: Upload artifacts Win zip
if: inputs.os == 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: PrusaSlicer_Windows_${{ env.ver }}_portable
path: ${{ github.workspace }}/build/PrusaSlicer_Windows_${{ env.ver }}_portable.zip

- name: Upload artifacts Win installer
if: inputs.os == 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: PrusaSlicer_Windows_${{ env.ver }}
path: ${{ github.workspace }}/build/PrusaSlicer*.exe

0 comments on commit 4f48292

Please sign in to comment.