Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.travis.yml and appveyor.yml templates, snaps and badges #4

Closed
konstin opened this issue Aug 21, 2018 · 2 comments
Closed

.travis.yml and appveyor.yml templates, snaps and badges #4

konstin opened this issue Aug 21, 2018 · 2 comments

Comments

@konstin
Copy link

konstin commented Aug 21, 2018

Trying to get binary releases automatically for pyo3-pack, I had to do look into many existing projects and do much experimenting. That's why I thought I might eventually want to make a template out of this and have created a template-like configuration. I also thought about a CLI for configuring everything (maybe even with ability to add/remove features such as coverage in existing projects), so I'm pretty excited about this project!

I had a slightly different focus, which is that I wanted a minimal configuration without any extra files, but don't need real cross compilation. I still think that crossgen could profit from merging those configurations in.

Since you mentioned snap on twitter: Ubuntu has there own ci-like service for building snaps. Unfortunately the rust plugin is completely broken and apparently unmaintained, see https://forum.snapcraft.io/t/the-rust-plugin-sets-an-invalid-manifest-path/6565 and the issue tracker.

.travis.yml
language: rust

env:
  global:
    # Change this to the name of your binary
    - BINARY_NAME="pyo3-pack"

addons:
  apt:
    packages: [] # If your project needs any system packages add them here

matrix:
  fast_finish: true
  include:
    # These create deployments
    - os: linux
      rust: stable
      env: TARGET=x86_64-unknown-linux-gnu
    - os: osx
      rust: stable
      env: TARGET=x86_64-apple-darwin

    # Those are only tested
    - os: linux
      rust: beta
      env: TARGET=x86_64-unknown-linux-gnu
    - os: linux
      rust: nightly
      env: TARGET=x86_64-unknown-linux-gnu

    # Minimum Rust supported channel
    - os: linux
      rust: 1.27.0
      env: TARGET=x86_64-unknown-linux-gnu

script:
  - cargo test --target $TARGET

before_deploy:
  - cargo build --release
  - cd target/release/
  # You can add more file to the archive by adding them to this line
  - tar czf ../../${BINARY_NAME}-$TRAVIS_TAG-$TARGET.tar.gz ${BINARY_NAME}
  - cd ../..

deploy:
  # Add zipped binary to the github release
  provider: releases
  file: ${BINARY_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz
  skip_cleanup: true
  on:
    condition: $TRAVIS_RUST_VERSION = stable
    tags: true
  # - Create a `public_repo` GitHub token at https://github.com/settings/tokens/new
  # . If you haven't already, install the travis gem: `gem install TRAVIS_TAG`
  # - Encrypt it with `travis encrypt 0123456789012345678901234567890123456789`
  # - Paste the output down here
  api_key:
    secure: "bKY3J8FBwgit9inzp2CMxQC3icBVco+COcRnqM6NhaOWX3KefXYG/yWQ7htBkeTRAfQERlOkZZOPsOto2dAD49/Mo4Uin9wbRPjPDGPJpFcQofX5aKHqK1Xd1k96rtZKZRIEG5k5J2IKAzPso3GnA0FESAZlZbxEShSCBD6aOlVmjFXwB2kKzJDo9zECxCg84GSvR/7wQg4hwMaMBa79y3VJRCohGTMaISL22QJ0haG+gqZgTv/r9K8P9lwSMBIiTXX3wFJU871sqUNTSSwkmHlVLhVUOwluv+KQ2DI/V/gWfx2CuiZ/7OQlz4zkOB/Y56msH0G7vOwqbSHLwkMYC+zgDWvF0oI/Eb/mdY5VliQdsLDOkKwWm3EuoEUvCgyV9UB1POxxogIx1sAU+Vt9QUj5/cRIJc1zrtA3LdNlbg9M9rYG8jJ6JMbeYTFDTL6YNoHc2lPAdmAqQAZQy6vyR515vm76JfS7yDcLRXKKhLE4dEPUEpv0qU8vCA/FdaZaiW+GJZSS5rJoE0vHaMRsWkgFLqCNSDpUZBd2x60E+n6dQ7XX4DrJ1JmzcG+IZ6AfuIWyRD9s3jQBxRjtyM61ZGo3Nb4zwX2ML1PftNURNAo8rPlgIrqPaveic45hP6PAeX+iMIWzTckq8shlYngjBTw/3UmA8Z18udrRyKCbygs="

cache: cargo

branches:
  only:
    # Pushes to the master branch
    - master
    # Match release tags with a regex
    - /^v\d+\.\d+\.\d+.*$/

notifications:
  email:
    on_success: never
appveyor.yml
environment:
  # Change this to the name of your binary
  BINARY_NAME: "unnamed-ci-template.exe"
  CARGO_HOME: "c:\\cargo"
  RUSTUP_HOME: "c:\\rustup"
  global:
    RUST_BACKTRACE: full
  matrix:
    # 32-bit
    - TARGET: i686-pc-windows-gnu
      CHANNEL: stable
    - TARGET: i686-pc-windows-msvc
      CHANNEL: stable
    # 64-bit
    - TARGET: x86_64-pc-windows-gnu
      CHANNEL: stable
    - TARGET: x86_64-pc-windows-msvc
      CHANNEL: stable

matrix:
  fast_finish: true

# Install Rust and Cargo
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
install:
  - ps: |
      # For the gnu target we need gcc, provided by mingw. mingw which is already preinstalled,
      # but we need to add the right version (32-bit or 64-bit) to the PATH.
      # See https://www.appveyor.com/docs/build-environment/#mingw-msys-cygwin
      if ($env:target -like "*-gnu") {
        if ($env:target -like "x86_64-*") { # x86_64-pc-windows-gnu
          $env:path += ";C:\msys64\mingw64\bin"
        } else { # i686-pc-windows-gnu
          $env:path += ";C:\msys64\mingw32\bin"
        }
        gcc --version
      }
  - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
  - rustup-init.exe -yv --default-host %TARGET% --no-modify-path
  - SET PATH=%PATH%;%CARGO_HOME%\bin
  - rustc -V
  - cargo -V

test_script:
  - cargo test

before_deploy:
  - cargo build --release
  # Grab the binary and pack it into a zip archive
  - cd target\release\
  # You can add more file to the archive by adding them to this line
  - 7z a ../../%APPVEYOR_PROJECT_SLUG%-%APPVEYOR_REPO_TAG_NAME%-%TARGET%.zip %BINARY_NAME%
  - appveyor PushArtifact ../../%APPVEYOR_PROJECT_SLUG%-%APPVEYOR_REPO_TAG_NAME%-%TARGET%.zip

deploy:
  # Add zipped binary to the github release
  - artifact: /.*\.zip/
    # - Create a `public_repo` GitHub token at https://github.com/settings/tokens/new
    # - Encrypt it at https://ci.appveyor.com/tools/encrypt
    # - Paste the output down here
    auth_token:
      secure: PQ91ezDbGmow+5tjZCAQ2/Y/2bHFffmQZoa5lr09JQIwARsAa2jHtucVn9826lWG
    provider: GitHub
    on:
      # Deploy when a new tag is pushed and only on the stable channel
      # Make sure you only release *once* per target
      CHANNEL: stable
      appveyor_repo_tag: true

cache:
  - '%CARGO_HOME%\registry'
  - target
  - '%RUSTUP_HOME%'

branches:
  only:
    # Pushes to the master branch
    - master
    # Match release tags with a regex
    - /^v\d+\.\d+\.\d+.*$/

build: off # Otherwise appveyor assumes we're building a .NET project

I also wrote a few words about how to use those templates and how to add badges, which might be useful:

Setup

This assumes you already have project on github and now want to add CI to it.

Start by copying .travis.yml and appveyor.yml from this repository.

Travis

  • Sign up at https://travis-ci.org/.
  • Enable your repository at https://travis-ci.org/profile/
  • Create a public_repo GitHub token at https://github.com/settings/tokens/new
  • Install ruby, gem and the travis gem: gem install travis
  • Run travis encrypt {your-github-token}. You might need to pass -r {repo}/{owner} (warning: case sensitive).
  • Paste the encrypted token in the secure section in .travis.yml
  • Change the value of BINARY_NAME in .travis.yml to the name of your binary

Appveyor

Make a commit with your changes and push it. The first build will take loner than subsequent builds since the caches are not yet initialized.

You can easily add other targets, e.g. nightly rust on windows, by adding them in the respective matrix list. Just make sure that you the target that get attach to releases don't clash.

Badges

The following snippet adds travis, appveyor, crates.io and docs.rs badges to your readme. Those ci badges are for the master branch, meaning that a broken pull request won't show you ci as broken. Note that appveyor is a bit weird: You needd the project id, which you can find e.g. under settings -> badges, and also the link to the project doesn't use the project's organization's name, but the name of the user that registered at appveyor.

[![Linux and Mac Build Status](https://img.shields.io/travis/{org}/{repo}/master.svg?style=flat-square)](https://travis-ci.org/{org}/{repo})
[![Windows Build status](https://ci.appveyor.com/api/projects/status/github/{repo}/{repo}?branch=master&svg=true)](https://ci.appveyor.com/project/{username}/{repo}/branch/master)
[![Crates.io](https://img.shields.io/crates/v/{crate-name}.svg?style=flat-square)](https://crates.io/crates/pyo3-pack)
[![API Documentation on docs.rs](https://docs.rs/{crate-name}/badge.svg)](https://docs.rs/pyo3-pack)

Don't forget that you can also add those badges to your Cargo.toml:

[badges]
travis-ci = { repository = "konstin/unnamed-ci-template" }
appveyor = { repository = "konstin/unnamed-ci-template" }

Debugging

Credits

This project is based on many other projects configurations, specifically the following:

@yoshuawuyts
Copy link
Owner

@konstin thanks so much for sharing! Everything you've shared has been super helpful to know!

There's an issue specifically about packaging apps cross-platform here. It seems you've done a bit of research on it, and input would be greatly valued!

Regarding badges: perhaps we should add a flag to crossgen to generate them? Does that sound like something you would like to add to the project?

@konstin
Copy link
Author

konstin commented Aug 30, 2018

There's an issue specifically about packaging apps cross-platform here. It seems you've done a bit of research on it, and input would be greatly valued!

The research I've done is summarized in the post above, so I doubt I could contribute much there.

Regarding badges: perhaps we should add a flag to crossgen to generate them? Does that sound like something you would like to add to the project?

Thanks, but I don't want to start contributing to yet another project.

@konstin konstin closed this as completed Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants