Skip to content

Commit

Permalink
conan
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Dec 2, 2024
1 parent 1786ea0 commit dac012a
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ on:
pull_request:
env:
PACKAGE_NAME: ${{ github.event.repository.name }}
PACKAGE_VERSION: ${{ github.sha }}
MYCI_GIT_USERNAME: igagis
MYCI_GIT_PASSWORD: ${{ secrets.MYCI_GIT_ACCESS_TOKEN }}
MYCI_CONAN_REMOTE: https://gagis.hopto.org/conan
MYCI_CONAN_USER: cppfw
MYCI_CONAN_PASSWORD: ${{ secrets.MYCI_CONAN_PASSWORD }}
jobs:
##### deb #####
deb:
Expand Down Expand Up @@ -192,3 +196,50 @@ jobs:
run: |
cd msys2
PKGEXT='.pkg.tar.xz' makepkg-mingw --syncdeps --noconfirm --skipinteg
##### conan - linux #####
conan-linux:
strategy:
fail-fast: false
matrix:
include:
- {os: debian, codename: bookworm, image_owner: }
# - {os: debian, codename: bookworm, image_owner: i386/, labels: [i386,docker]}
# - {os: debian, codename: bookworm, image_owner: , labels: [arm32,docker]}
# - {os: debian, codename: bookworm, image_owner: , labels: [arm64,docker]}
runs-on: ${{ (matrix.labels == '' && 'ubuntu-latest') || matrix.labels }}
container: ${{ matrix.image_owner }}${{ matrix.os }}:${{ matrix.codename }}
name: conan - linux | ${{ matrix.labels[0] }}
steps:
- name: add cppfw deb repo
uses: myci-actions/add-deb-repo@main
with:
repo: deb https://gagis.hopto.org/repo/cppfw/${{ matrix.os }} ${{ matrix.codename }} main
repo-name: cppfw
keys-asc: https://gagis.hopto.org/repo/cppfw/pubkey.gpg
install: devscripts equivs pipx cmake git
- name: add ~/.local/bin to PATH
uses: myci-actions/export-env-var@main
with: {name: PATH, value: "$PATH:$HOME/.local/bin"}
- name: install conan
run: pipx install conan
- name: create default conan profile
run: |
conan profile detect --name default
sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default
- name: git clone
uses: myci-actions/checkout@main
- name: install myci
run: make install
- name: set PACKAGE_VERSION
uses: myci-actions/export-env-var@main
with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)}
if: startsWith(github.ref, 'refs/tags/')
- name: build
run: |
conan remote add cppfw $MYCI_CONAN_REMOTE
conan create conan --build-require --build=missing --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION
- name: deploy conan package
run: |
conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER
conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
if: startsWith(github.ref, 'refs/tags/')
55 changes: 55 additions & 0 deletions conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.files import load, update_conandata, copy
from conan.tools.layout import basic_layout

class MyciConan(ConanFile):
name = "myci"
license = "MIT"
author = "Ivan Gagis <igagis@gmail.com>"
url = "http://github.com/cppfw/" + name
description = "myci build scripts"
settings = "os", "compiler", "build_type", "arch"
package_type = "build-scripts"

# def requirements(self):
# self.tool_requires("make/[>=4.4.1]")

# save commit and remote URL to conandata.yml for packaging
def export(self):
git = Git(self)
scm_url = git.get_remote_url()
# NOTE: Git.get_commit() doesn't work properly,
# it gets latest commit of the folder in which conanfile.py resides.
# So, we use "git rev-parse HEAD" instead as it gets the actual HEAD
# commit regardless of the current working directory within the repo.
scm_commit = git.run("rev-parse HEAD") # get current commit
update_conandata(self, {"sources": {"commit": scm_commit, "url": scm_url}})

def source(self):
git = Git(self)
sources = self.conan_data["sources"]
# shallow fetch commit
git.fetch_commit(url=sources["url"], commit=sources['commit'])
# shallow clone submodules
git.run("submodule update --init --remote --depth 1")

def package(self):
src_dir = os.path.join(self.build_folder, "src")
dst_dir = os.path.join(self.package_folder, "bin")

copy(conanfile=self, pattern="*.sh", dst=dst_dir, src=src_dir, keep_path=True)

# def package_info(self):
# self.buildenv_info.append("MAKE_INCLUDE_DIRS_ARG", "--include-dir=" + os.path.join(self.package_folder, "include"))

def package_id(self):
# change package id only when minor or major version changes, i.e. when ABI breaks
self.info.requires.minor_mode()

# bash scripts do not depend on any of os, arch, compiler, build_type
del self.info.settings.os
del self.info.settings.arch
del self.info.settings.compiler
del self.info.settings.build_type
12 changes: 12 additions & 0 deletions conan/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

from conan import ConanFile, tools

class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"

def requirements(self):
self.tool_requires(self.tested_reference_str)

def test(self):
self.run("myci-passed.sh", env="conanbuild") # env sets LD_LIBRARY_PATH etc. to find dependency libs

0 comments on commit dac012a

Please sign in to comment.