Skip to content

Commit

Permalink
Ãci: add build-binaries.yml to build lib C binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Dafyh committed Aug 7, 2024
1 parent 9a57c9c commit 027b317
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Build Node.js Artifact

on:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]

jobs:
push_on_main:
if: github.event_name == 'push'
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
platform: linuxmusl-x64
- os: ubuntu-22.04
platform: linux-x64
- os: macos-12
platform: darwin-x64
- os: windows-latest
platform: win32-x64
- os: windows-latest
platform: win32-ia32

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies and test
run: |
npm install
npm run test
pull_request:
if: github.event_name == 'pull_request'
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
platform: linuxmusl-x64
- os: ubuntu-22.04
platform: linux-x64
- os: macos-12
platform: darwin-x64
- os: windows-latest
platform: win32-x64
- os: windows-latest
platform: win32-ia32

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Create a folder for the tarball
run: mkdir -p release/${{ matrix.PLATFORM }}/lib

- name: Build and run Docker container
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'windows')
run: |
# Build image
docker build --build-arg PLATFORM=${{ matrix.PLATFORM }} -t ${{ matrix.PLATFORM }} . -f ./.github/Dockerfile
# Run container and copy the built file
docker run --name ${{ matrix.PLATFORM }} ${{ matrix.PLATFORM }}
# Copy .node file from the container
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/converter.node ./release/${{ matrix.PLATFORM }}/lib/converter.${{ matrix.PLATFORM }}.node
- name: Copy .dll files from the container (Windows)
if: contains(matrix.os, 'windows')
run: |
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/heif.dll ./release/${{ matrix.PLATFORM }}/lib/heif.dll
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/turbojpeg.dll ./release/${{ matrix.PLATFORM }}/lib/turbojpeg.dll
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/jpeg62.dll ./release/${{ matrix.PLATFORM }}/lib/jpeg62.dll
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/libde265.dll ./release/${{ matrix.PLATFORM }}/lib/libde265.dll
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/libx265.dll ./release/${{ matrix.PLATFORM }}/lib/libx265.dll
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/libpng16.dll ./release/${{ matrix.PLATFORM }}/lib/libpng16.dll
docker cp ${{ matrix.PLATFORM }}:/heif-converter/src/build/Release/zlib1.dll ./release/${{ matrix.PLATFORM }}/lib/zlib1.dll
- name: Clean up the Docker container (Windows and Linux)
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'windows')
run: docker container rm ${{ matrix.PLATFORM }}

- name: Configure and Build on OSX
if: contains(matrix.os, 'mac')
run: |
# Build project
npm install --omit-optional
npm run configure
npm run build
# Run tests
npm run test
# Copy .node in the release folder
cp ./src/build/Release/converter.node ./release/${{ matrix.PLATFORM }}/lib/converter.${{ matrix.PLATFORM }}.node
- name: Create tarball of the release folder
run: |
cd ./release
tar -czf ${{ matrix.platform }}.tar.gz *
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: release
path: ./release/${{ matrix.platform }}.tar.gz
101 changes: 101 additions & 0 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build lib C binaries

on:
push:
branches:
- platform

jobs:
push_on_main:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
platform: linuxmusl-x64
arch: x64
- os: ubuntu-22.04
platform: linux-x64
arch: x64
- os: windows-latest
platform: win32-x64
arch: x64
- os: windows-latest
platform: win32-ia32
arch: x86

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create folders for the tarball
run: |
mkdir -p binaries/${{ matrix.CONVERTER-PLATFORM }}/lib
mkdir binaries/${{ matrix.CONVERTER-PLATFORM }}/include
- name: Build and run Docker container
run: |
# Build image
docker build -t ${{ matrix.CONVERTER-PLATFORM }} . -f ./platform/${{ matrix.CONVERTER-PLATFORM }}/Dockerfile
# Run container
docker run --name ${{ matrix.CONVERTER-PLATFORM }} ${{ matrix.CONVERTER-PLATFORM }}
- name: Copy binary and include files (Windows)
if: contains(matrix.os, 'windows')
env:
source: ${{ matrix.PLATFORM }}:/vcpkg/installed/windows-${{ matrix.ARCH }}
destination: binaries/${{ matrix.PLATFORM }}
run : |
# Create the necessary folder
mkdir binaries/${{ matrix.CONVERTER-PLATFORM }}/bin
# Copy .dll files
docker cp $source/bin/heif.dll $destination/bin/heif.dll
docker cp $source/bin/turbojpeg.dll $destination/bin/turbojpeg.dll
docker cp $source/bin/libde265.dll $destination/bin/libde265.dll
docker cp $source/bin/libx265.dll $destination/bin/libx265.dll
docker cp $source/bin/libpng16.dll $destination/bin/libpng16.dll
# Copy lib files
docker cp $source/lib/heif.lib $destination/lib/heif.lib
docker cp $source/lib/turbojpeg.lib $destination/lib/turbojpeg.lib
docker cp $source/lib/libpng16.lib $destination/lib/libpng16.lib
# Copy includes files
docker cp $source/include/libheif $destination/include/libheif
docker cp $source/include/png.h $destination/include/png.h
docker cp $source/include/png.h $destination/include/pngconf.h
docker cp $source/include/png.h $destination/include/pnglibconf.h
docker cp $source/include/png.h $destination/include/turbojpeg.h
- name: Copy binary and include files (Linux)
if: contains(matrix.os, 'ubuntu')
env:
source: ${{ matrix.PLATFORM }}:/vcpkg/installed/linux-${{ matrix.ARCH }}
destination: binaries/${{ matrix.PLATFORM }}
run : |
# Copy lib files
docker cp $source/lib/libheif.a $destination/lib/libheif.a
docker cp $source/lib/libturbojpeg.a $destination/lib/libturbojpeg.a
docker cp $source/lib/libpng16.a $destination/lib/libpng16.a
docker cp $source/lib/libde265.a $destination/lib/libde265.a
docker cp $source/lib/libx265.a $destination/lib/libx265.a
# Copy includes files
docker cp $source/include/libheif $destination/include/libheif
docker cp $source/include/png.h $destination/include/png.h
docker cp $source/include/pngconf.h $destination/include/pngconf.h
docker cp $source/include/pnglibconf.h $destination/include/pnglibconf.h
docker cp $source/include/turbojpeg.h $destination/include/turbojpeg.h
- name: Create tarball of the binaries folder
run: |
cd ./binaries
tar -czf ${{ matrix.platform }}.tar.gz *
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: binaries
path: ./binaries/${{ matrix.platform }}.tar.gz

0 comments on commit 027b317

Please sign in to comment.