Skip to content

...

... #21

name: Build and Test
on:
push:
branches: [main]
tags:
- "v*.*.*"
pull_request:
branches: [main]
jobs:
build:
name: Build and Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
build_type: [Release]
include:
- os: ubuntu-latest
cc: gcc
artifact_name: pHash-Linux
shared_lib_ext: "*.so*"
- os: macos-latest
cc: clang
artifact_name: pHash-macOS
shared_lib_ext: "*.dylib"
steps:
- uses: actions/checkout@v4
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: Configure CMake (Shared Library + Executable + Tests)
working-directory: ${{github.workspace}}/build
env:
CC: ${{ matrix.cc }}
run: |
cmake .. \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DBUILD_SHARED_LIB=ON \
-DBUILD_EXECUTABLE=ON \
-DBUILD_TESTS=ON
- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --config ${{ matrix.build_type }} -j $(nproc 2>/dev/null || sysctl -n hw.ncpu)
- name: Run Tests (Ephemeral)
working-directory: ${{github.workspace}}/build
run: ./test_phash
- name: Install
working-directory: ${{github.workspace}}/build
run: sudo cmake --install .
- name: Prepare Artifacts
run: |
mkdir -p artifacts/bin artifacts/lib artifacts/include
# Copy executable
cp $(which pHash_exec) artifacts/bin/
# Copy shared library
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
cp /usr/local/lib/libpHash${{ matrix.shared_lib_ext }} artifacts/lib/
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
cp /usr/local/lib/libpHash${{ matrix.shared_lib_ext }} artifacts/lib/
fi
# Copy header files
cp pHash.h artifacts/include/
# Create archive
cd artifacts
tar -czf ../${{ matrix.artifact_name }}.tar.gz *
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_name }}.tar.gz
retention-days: 7
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
files: |
artifacts/**/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Display Release URL
run: |
echo "Release created at: ${{ steps.create_release.outputs.url }}"