Skip to content

Commit

Permalink
CI: Update FFmpeg build workflow and action for native Windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
PatTheMav committed May 24, 2023
1 parent 30395b9 commit 1eefd41
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 52 deletions.
60 changes: 55 additions & 5 deletions .github/actions/build-ffmpeg/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,27 @@ runs:
- name: Environment Setup
id: ffmpeg-env-setup
shell: bash
working-directory: ${{ github.workspace }}
run: |
case "${{ runner.os }}" in
case "${RUNNER_OS}" in
Linux)
if ! type zsh > /dev/null 2>&1; then
sudo apt update
sudo apt install zsh
fi
ffmpeg_dep_hash=$(cat ${PWD}/deps.ffmpeg/*.zsh | sha256sum | cut -d " " -f 1)
;;
macOS)
if ! type sha256sum > /dev/null 2>&1; then
brew install coreutils
fi
ffmpeg_dep_hash=$(cat ${PWD}/deps.ffmpeg/*.zsh | sha256sum | cut -d " " -f 1)
;;
Windows)
ffmpeg_dep_hash=$(cat ${PWD}/deps.ffmpeg/*.ps1 | sha256sum | cut -d " " -f 1)
;;
esac
ffmpeg_dep_hash=$(cat ${{ github.workspace }}/deps.ffmpeg/*.zsh | sha256sum | cut -d " " -f 1)
echo "hash=${ffmpeg_dep_hash}" >> $GITHUB_OUTPUT
- name: Restore FFmpeg Dependencies from Cache
Expand All @@ -54,10 +60,25 @@ runs:
key: ${{ inputs.target }}-ffmpeg-deps-${{ inputs.type }}-${{ steps.ffmpeg-env-setup.outputs.hash }}-${{ inputs.cacheRevision }}

- name: Build and Install FFmpeg Dependencies
if: ${{ steps.ffmpeg-deps-cache.outputs.cache-hit != 'true' }}
if: runner.os != 'Windows' && steps.ffmpeg-deps-cache.outputs.cache-hit != 'true'
shell: zsh {0}
run: ./build-ffmpeg.zsh '*~ffmpeg' --target ${{ inputs.target }} --config ${{ inputs.config }} --${{ inputs.type }}


- name: Build and Install FFmpeg Dependencies (Windows)
if: runner.os == 'Windows' && steps.ffmpeg-deps-cache.outputs.cache-hit != 'true'
shell: pwsh
run: |
$BuildArgs = @{
Package = 'ffmpeg'
Target = $(('${{ inputs.target }}' -split '-')[1])
Config = '${{ inputs.config }}'
Shared = $(if ( '${{ inputs.type }}' -eq 'shared' ) { $true } else { $false })
Dependencies = (Get-ChildItem deps.ffmpeg -filter '*.ps1' | Where-Object { $_.Name -ne '99-ffmpeg.ps1' } | ForEach-Object { $_.Name -replace "[0-9]+-(.+).ps1",'$1' })
}
./Build-Dependencies.ps1 @BuildArgs
- name: Restore FFmpeg from Cache
id: ffmpeg-cache
uses: actions/cache@v3
Expand All @@ -68,11 +89,40 @@ runs:
key: ${{ inputs.target }}-ffmpeg-${{ inputs.type }}-${{ steps.ffmpeg-env-setup.outputs.hash }}-${{ inputs.cacheRevision }}

- name: Install FFmpeg
if: ${{ steps.ffmpeg-cache.outputs.cache-hit == 'true' }}
if: runner.os != 'Windows' && steps.ffmpeg-cache.outputs.cache-hit == 'true'
shell: zsh {0}
run: ./build-ffmpeg.zsh --skip-build --skip-unpack --target ${{ inputs.target }} --config ${{ inputs.config }} --${{ inputs.type }}

- name: Install FFmpeg (Windows)
if: runner.os == 'Windows' && steps.ffmpeg-cache.outputs.cache-hit == 'true'
shell: pwsh
run: |
$BuildArgs = @{
Package = 'ffmpeg'
Target = $(('${{ inputs.target }}' -split '-')[1])
Config = '${{ inputs.config }}'
Shared = $(if ( '${{ inputs.type }}' -eq 'shared' ) { $true } else { $false })
SkipBuild = $true
SkipUnpack = $true
}
./Build-Dependencies.ps1 @BuildArgs
- name: Build and Install FFmpeg
if: ${{ steps.ffmpeg-cache.outputs.cache-hit != 'true' }}
if: runner.os != 'Windows' && steps.ffmpeg-cache.outputs.cache-hit != 'true'
shell: zsh {0}
run: ./build-ffmpeg.zsh --target ${{ inputs.target }} --config ${{ inputs.config }} --${{ inputs.type }}

- name: Build and Install FFmpeg (Windows)
if: runner.os == 'Windows' && steps.ffmpeg-cache.outputs.cache-hit != 'true'
shell: pwsh
run: |
$BuildArgs = @{
Package = 'ffmpeg'
Target = $(('${{ inputs.target }}' -split '-')[1])
Config = '${{ inputs.config }}'
Shared = $(if ( '${{ inputs.type }}' -eq 'shared' ) { $true } else { $false })
Dependencies = 'ffmpeg'
}
./Build-Dependencies.ps1 @BuildArgs
1 change: 1 addition & 0 deletions .github/actions/build-windows-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ runs:
$Params = @{
Target = '${{ inputs.target }}'
Configuration = '${{ inputs.config }}'
Package = 'dependencies'
}
if ( '${{ inputs.type }}' -eq 'shared' ) { $Params += @{Shared = $true} }
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/build-windows-qt/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ runs:
- name: Install Windows Qt
if: ${{ steps.deps-cache.outputs.cache-hit == 'true' }}
shell: pwsh
run: ./Build-Dependencies.ps1 -Dependencies "Qt${{ inputs.qtVersion }}" -SkipBuild -SkipUnpack -Target ${{ inputs.target }} -Configuration ${{ inputs.config }} -Shared
run: ./Build-Dependencies.ps1 -Dependencies "Qt${{ inputs.qtVersion }}" -SkipBuild -SkipUnpack -Target ${{ inputs.target }} -Configuration ${{ inputs.config }} -Shared -Package qt

- name: Build and Install Windows Qt
if: ${{ steps.deps-cache.outputs.cache-hit != 'true' }}
shell: pwsh
run: ./Build-Dependencies.ps1 -Dependencies "Qt${{ inputs.qtVersion }}" -Target ${{ inputs.target }} -Configuration ${{ inputs.config }} -Shared
run: ./Build-Dependencies.ps1 -Dependencies "Qt${{ inputs.qtVersion }}" -Target ${{ inputs.target }} -Configuration ${{ inputs.config }} -Shared -Package qt
127 changes: 82 additions & 45 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ on:

jobs:
ffmpeg-build:
name: 'Build FFmpeg'
name: 'Build FFmpeg for macOS'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
target: [macos-arm64, macos-x86_64, linux-x86_64, windows-x64, windows-x86]
target: [macos-arm64, macos-x86_64]
include:
- target: macos-arm64
os: 'macos-12'
Expand All @@ -31,21 +31,6 @@ jobs:
config: 'Release'
type: 'static'
revision: 9
- target: linux-x86_64
os: 'ubuntu-20.04'
config: 'Release'
type: 'static'
revision: 9
- target: windows-x64
os: 'ubuntu-20.04'
config: 'Release'
type: 'static'
revision: 8
- target: windows-x86
os: 'ubuntu-20.04'
config: 'Release'
type: 'static'
revision: 8
env:
CACHE_REVISION: ${{ matrix.revision }}
defaults:
Expand All @@ -58,26 +43,18 @@ jobs:
- name: Setup Environment
id: setup
run: |
case "${{ runner.os }}" in
Linux)
sudo apt update
sudo apt install zsh
;;
macOS)
to_remove=()
for formula in llvm gcc postgresql openjdk sox libsndfile flac libvorbis opusfile \
libogg composer php gd freetype fontconfig webp libpng lame libtiff opus kotlin \
sbt libxft libxcb; do
if [[ -d /usr/local/opt/"${formula}" ]]; then
to_remove+=(${formula})
fi
done
if [[ ${#to_remove} -gt 0 ]]; then
brew uninstall --ignore-dependencies ${to_remove[@]}
fi
;;
esac
to_remove=()
for formula in llvm gcc postgresql openjdk sox libsndfile flac libvorbis opusfile \
libogg composer php gd freetype fontconfig webp libpng lame libtiff opus kotlin \
sbt libxft libxcb; do
if [[ -d /usr/local/opt/"${formula}" ]]; then
to_remove+=(${formula})
fi
done
if [[ ${#to_remove} -gt 0 ]]; then
brew uninstall --ignore-dependencies ${to_remove[@]}
fi
target='${{ matrix.target }}'
artifact_name="ffmpeg-${target}-${{ github.sha }}"
Expand All @@ -98,9 +75,12 @@ jobs:
- name: Check for GitHub Labels
id: seekingTesters
if: ${{ github.event_name == 'pull_request' }}
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ -n "$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -s "${{ github.event.pull_request.url }}" | jq -e '.labels[] | select(.name == "Seeking Testers")')" ]]; then
if gh pr view ${{ github.event.number }} --json labels \
| jq -e -r '.labels[] | select(.name == "Seeking Testers")' > /dev/null; then
echo "found=true" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
Expand All @@ -115,7 +95,7 @@ jobs:
cacheRevision: ${{ env.CACHE_REVISION }}

- name: Publish Build Artifacts
if: ${{ success() && (github.event_name != 'pull_request' || steps.seekingTesters.outputs.found == 'true') }}
if: github.event_name != 'pull_request' || fromJSON(steps.seekingTesters.outputs.found)
uses: actions/upload-artifact@v3
with:
name: ${{ steps.setup.outputs.artifactName }}
Expand Down Expand Up @@ -147,6 +127,63 @@ jobs:
x86_64: 'ffmpeg-macos-x86_64-${{ github.sha }}'
outputName: 'ffmpeg-macos-universal-${{ github.sha }}'

ffmpeg-windows-build:
name: 'Build FFmpeg for Windows'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
target: [windows-x64]
include:
- target: windows-x64
os: 'windows-2022'
config: 'Release'
type: 'static'
revision: 1
defaults:
run:
shell: pwsh
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set Up Environment
id: setup
run: |
$Target = '${{ matrix.target }}'
$ArtifactName = "ffmpeg-${Target}-${Env:GITHUB_SHA}"
$FileName = "$(($Target -split '-')[0])-ffmpeg-$(Date +"%Y-%m-%d")-$(($Target -split '-')[1]).zip"
"artifactName=${ArtifactName}" >> $Env:GITHUB_OUTPUT
"artifactFileName=${FileName}" >> $Env:GITHUB_OUTPUT
- name: Check For GitHub Labels
id: seekingTesters
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
if ( (gh pr view ${{ github.event.number }} --json labels | ConvertFrom-Json).labels | Where-Object { $_.name -eq 'Seeking Testers' } ) {
"found=true" >> $Env:GITHUB_OUTPUT
} else {
"found=false" >> $Env:GITHUB_OUTPUT
}
- name: Build FFmpeg
uses: ./.github/actions/build-ffmpeg
with:
target: ${{ matrix.target }}
type: ${{ matrix.type }}
config: ${{ matrix.config }}
cacheRevision: ${{ matrix.revision }}

- name: Publish Build Artifacts
if: github.event_name != 'pull_request' || fromJSON(steps.seekingTesters.outputs.found)
uses: actions/upload-artifact@v3
with:
name: ${{ steps.setup.outputs.artifactName }}
path: ${{ github.workspace }}/${{ matrix.target }}/${{ steps.setup.outputs.artifactFileName }}

macos-build:
name: 'Build macOS Dependencies'
runs-on: macos-12
Expand Down Expand Up @@ -477,7 +514,7 @@ jobs:
run: |
$Target='${{ matrix.target }}'
$ArtifactName="deps-windows-${Target}-${{ github.sha }}"
$FileName="windows-deps-$(Get-Date -Format 'yyyy-MM-dd')-${Target}.zip"
$FileName="windows-dependencies-$(Get-Date -Format 'yyyy-MM-dd')-${Target}.zip"
"artifactName=${ArtifactName}" >> $env:GITHUB_OUTPUT
"artifactFileName=${FileName}" >> $env:GITHUB_OUTPUT
Expand Down Expand Up @@ -527,7 +564,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: ${{ steps.setup.outputs.artifactName }}
path: ${{ github.workspace }}\windows\${{ steps.setup.outputs.artifactFileName }}
path: ${{ github.workspace }}\windows-${{ matrix.target }}\${{ steps.setup.outputs.artifactFileName }}

windows-qt-build:
name: 'Build Windows Qt'
Expand Down Expand Up @@ -585,7 +622,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: ${{ steps.setup.outputs.artifactName }}
path: ${{ github.workspace }}/windows/${{ steps.setup.outputs.artifactFileName }}
path: ${{ github.workspace }}/windows-${{ matrix.target }}/${{ steps.setup.outputs.artifactFileName }}

windows-qt-package:
name: 'Package Windows Qt (${{ matrix.qtVersion }}, ${{ matrix.target }})'
Expand Down Expand Up @@ -630,7 +667,7 @@ jobs:
name: 'Create and upload release'
runs-on: ubuntu-20.04
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: [ffmpeg-package-universal, macos-package-universal, macos-qt5-package-universal, macos-qt6-package, windows-build, windows-qt-package]
needs: [ffmpeg-package-universal, ffmpeg-windows-build, macos-package-universal, macos-qt5-package-universal, macos-qt6-package, windows-build, windows-qt-package]
defaults:
run:
shell: bash
Expand All @@ -652,7 +689,7 @@ jobs:
_temp=$(mktemp -d)
pushd "${_temp}" > /dev/null
for artifact in ${{ github.workspace }}/**/windows-@(deps|ffmpeg)-!(qt5*|qt6*)-${arch}.*; do
for artifact in ${{ github.workspace }}/**/windows-@(deps|dependencies|ffmpeg)-!(qt5*|qt6*)-${arch}.*; do
case ${artifact} in
*.zip) unzip ${artifact} > /dev/null ;;
*.tar.xz) XZ_OPT=-T0 tar -xJf ${artifact} ;;
Expand Down

0 comments on commit 1eefd41

Please sign in to comment.