From dac012a169a64818038e1744b35f83716b22ca97 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Mon, 2 Dec 2024 23:00:46 +0200 Subject: [PATCH] conan --- .github/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++ conan/conanfile.py | 55 +++++++++++++++++++++++++++++++++ conan/test_package/conanfile.py | 12 +++++++ 3 files changed, 118 insertions(+) create mode 100644 conan/conanfile.py create mode 100644 conan/test_package/conanfile.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd0b358..4bc2c69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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/') diff --git a/conan/conanfile.py b/conan/conanfile.py new file mode 100644 index 0000000..7f60ced --- /dev/null +++ b/conan/conanfile.py @@ -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 " + 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 diff --git a/conan/test_package/conanfile.py b/conan/test_package/conanfile.py new file mode 100644 index 0000000..c0e543b --- /dev/null +++ b/conan/test_package/conanfile.py @@ -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