Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
build/
out/
cmake-build-*/
.git/
.github/
.vscode/
.idea/
*.swp
*.swo
*~
vcpkg_installed/
conan_provider.cmake
conanbuildinfo.*
conaninfo.txt
graph_info.json
InstallationLog.txt
138 changes: 138 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: CD

on:
push:
tags: [ 'v*' ]

permissions:
contents: write

jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build release (Docker)
run: |
docker compose build
docker compose run build

- name: Package artifacts
run: |
docker compose run --rm build sh -c "
tar -czf /app/wrapsplash++-linux-x64.tar.gz \
-C /app/build lib/libwrapsplash++.a \
-C /app include/wrapsplash
"

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-x64
path: wrapsplash++-linux-x64.tar.gz

build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: brew install cmake curl nlohmann-json openssl

- name: Build
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DWRAPSLASH_BUILD_TESTS=OFF -DWRAPSLASH_BUILD_EXAMPLES=OFF
cmake --build build --config Release

- name: Package artifacts
run: |
tar -czf wrapsplash++-macos-arm64.tar.gz \
-C build lib/libwrapsplash++.a \
-C .. include/wrapsplash

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: macos-arm64
path: wrapsplash++-macos-arm64.tar.gz

build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Setup vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git C:\vcpkg
C:\vcpkg\bootstrap-vcpkg.bat
shell: cmd

- name: Build
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release ^
-DWRAPSLASH_BUILD_TESTS=OFF -DWRAPSLASH_BUILD_EXAMPLES=OFF ^
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
shell: cmd

- name: Package artifacts
run: |
Compress-Archive -Path build\Release\wrapsplash++.lib, include\wrapsplash\* `
-DestinationPath wrapsplash++-windows-x64.zip
shell: pwsh

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: windows-x64
path: wrapsplash++-windows-x64.zip

release:
needs: [build-linux, build-macos, build-windows]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Generate changelog
id: changelog
run: |
TAG="${GITHUB_REF#refs/tags/}"
PREV_TAG=$(git tag --sort=-v:refname | grep '^v' | sed -n '2p')
if [ -n "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s (%h)" "$PREV_TAG".."$TAG")
else
CHANGELOG=$(git log --pretty=format:"- %s (%h)" "$TAG")
fi
echo "changelog<<EOF" >> "$GITHUB_OUTPUT"
echo "$CHANGELOG" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

- name: Create release
uses: softprops/action-gh-release@v2
with:
name: WrapSplash++ ${{ github.ref_name }}
body: |
## What's Changed
${{ steps.changelog.outputs.changelog }}

## Downloads
| Platform | Archive |
|----------|---------|
| Linux x64 | `wrapsplash++-linux-x64.tar.gz` |
| macOS ARM64 | `wrapsplash++-macos-arm64.tar.gz` |
| Windows x64 | `wrapsplash++-windows-x64.zip` |
files: |
artifacts/linux-x64/*
artifacts/macos-arm64/*
artifacts/windows-x64/*
draft: false
prerelease: false
18 changes: 4 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential libcurl4-openssl-dev nlohmann-json3-dev libssl-dev

- name: Build
run: |
mkdir build && cd build
cmake -DWRAPSLASH_BUILD_TESTS=ON -DWRAPSLASH_BUILD_EXAMPLES=ON ..
cmake --build .

- name: Test
- name: Build and test (Docker)
run: |
cd build
ctest --output-on-failure
docker compose build
docker compose run build
docker compose run test

build-macos:
runs-on: macos-latest
Expand Down
119 changes: 119 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Publish

on:
release:
types: [published]

permissions:
contents: write
pull-requests: write

jobs:
publish-conan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install Conan
run: pip install conan

- name: Configure Conan
run: conan profile detect --force

- name: Export package
run: conan export . --version=${{ github.event.release.tag_name }}

- name: Upload to Conan Center
env:
CONAN_LOGIN_USERNAME: ${{ secrets.CONAN_USERNAME }}
CONAN_PASSWORD: ${{ secrets.CONAN_PASSWORD }}
run: |
conan upload "wrapsplash-cpp/${{ github.event.release.tag_name }}" \
--remote conancenter --confirm

publish-vcpkg:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: ${{ vars.VCPKG_COMMIT_ID }}

- name: Create vcpkg port
run: |
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
PORT_DIR="vcpkg-port"
mkdir -p "$PORT_DIR"

cat > "$PORT_DIR/vcpkg.json" << EOF
{
"name": "wrapsplash-cpp",
"version": "$VERSION",
"description": "A C++ wrapper for the Unsplash API",
"license": "MIT",
"supports": "!(uwp|arm)",
"dependencies": ["curl", "nlohmann-json", "openssl"]
}
EOF

cat > "$PORT_DIR/portfile.cmake" << 'PORTFILE'
set(VCPKG_BUILD_TYPE release)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO Sandeepv68/wrapsplash-cpp
REF ${{ github.event.release.tag_name }}
SHA512 0
HEAD_REF master
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DWRAPSLASH_BUILD_TESTS=OFF
-DWRAPSLASH_BUILD_EXAMPLES=OFF
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup(PACKAGE_NAME wrapsplash++ CONFIG_PATH lib/cmake/wrapsplash++)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
PORTFILE

- name: Submit PR to vcpkg
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
BRANCH="auto/wrapsplash-cpp-${VERSION}"

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git clone https://x-access-token:${GH_TOKEN}@github.com/microsoft/vcpkg.git /tmp/vcpkg
cd /tmp/vcpkg
git checkout -b "$BRANCH"

mkdir -p "ports/wrapsplash-cpp"
cp "${{ github.workspace }}/vcpkg-port/vcpkg.json" "ports/wrapsplash-cpp/"
cp "${{ github.workspace }}/vcpkg-port/portfile.cmake" "ports/wrapsplash-cpp/"

git add "ports/wrapsplash-cpp/"
git commit -m "wrapsplash-cpp: update to $VERSION"
git push origin "$BRANCH"

gh pr create \
--repo microsoft/vcpkg \
--title "wrapsplash-cpp: update to $VERSION" \
--body "Updates wrapsplash-cpp to $VERSION. Release: ${{ github.event.release.html_url }}" \
--base master \
--head "$BRANCH"
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:24.04 AS base

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
cmake \
make \
g++ \
pkg-config \
libcurl4-openssl-dev \
nlohmann-json3-dev \
libssl-dev \
libgtest-dev \
git \
&& rm -rf /var/lib/apt/lists/*

FROM base AS build

WORKDIR /app

COPY CMakeLists.txt ./
COPY cmake/ cmake/
COPY include/ include/
COPY src/ src/
COPY tests/ tests/

RUN cmake -B build -DWRAPSLASH_BUILD_TESTS=ON -DWRAPSLASH_BUILD_EXAMPLES=ON \
&& cmake --build build -j$(nproc)

FROM base AS test

WORKDIR /app

COPY --from=build /app/build build/

CMD ["ctest", "--test-dir", "build", "--output-on-failure"]
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Before using the Unsplash API, you need to **register as a developer** and **rea
* [Installation](#installation)
* [Sample Usage](#sample-usage)
* [Development](#development)
* [Docker](#docker)
* [New API aliases](#new-api-aliases)
* [Dependency](#dependency)
* [Changelog](#changelog)
Expand Down Expand Up @@ -137,6 +138,34 @@ cmake --build .
ctest
```

### Docker

You can build and test the project entirely inside Docker, which avoids installing dependencies on your host machine.

**Prerequisites:** [Docker Desktop](https://www.docker.com/products/docker-desktop/) must be running.

**Build the project:**
```sh
docker compose run build
```

**Run the tests:**
```sh
docker compose run test
```

**Build and test in one shot:**
```sh
docker compose up build test
```

On subsequent runs, Docker caches the dependency layer and preserves compiled objects in a named volume (`build-cache`), so only changed source files are recompiled.

**How it works:**
- `Dockerfile` installs all build dependencies (cmake, g++, curl, nlohmann-json, openssl, googletest) on Ubuntu 24.04.
- `docker-compose.yml` mounts your source code into the container and uses a `build-cache` volume for the build directory, enabling incremental builds.
- `.dockerignore` keeps the Docker build context small by excluding `build/`, `.git/`, IDE files, etc.

### New API aliases
The library includes more descriptive convenience methods such as `get_photo`, `get_random_photo`, `create_collection`, and `update_collection`. The original method names remain available for backward compatibility.

Expand Down
Loading
Loading