Skip to main content

2 posts tagged with "swift"

View All Tags

· 2 min read
zach wick

Genie is a tool for assigning arbitrary tags to file paths, and then performing search operations on those tags.

Like any person, I organize my files in a standard way on the machines that I use regularly:

~/Users/
├── Desktop
├── Documents
│   ├── Personal
│   ├── Work
├── Downloads
├── Documents
├── Repos
│   ├── APL
│   ├── C
│   ├── CPP
│   ├── Go
│   ├── Guile
│   ├── JS
.
.
.

This has its advantages, such as knowing where to go when looking for some particular project. This structure falls over for projects with components in multiple languages however, such as a Swift API with a JS client. In that case, this kind of file structure relies on naming conventions to indicate that two directory trees at Repos/Swift/projectx-server and Repos/JS/projectx-client are part of the same project.

This is where genie comes in handy, because the Swift API's directory and the JS client's directory can be assigned the same tag of "projectX" and then use genie search projectX to see all of the filepaths that are associated with that project's tag.

The other times where genie is useful is remembering every few months where exactly in a large codebase some change needs to be made. This is where genie really shines in my day job where I seem to do many semi-regular drive-by pull requests in the same area of the monorepo and can tag some deeply nested file with a self-evident tag.

genie is essentially a very small command line tool written in Swift that wraps some sqlite queries, but it serves its purpose well.

You can read more about genie in the very nascent docs.

· 3 min read
zach wick

This set of steps is the result of a weekend poking at how to get Travis-CI and GitHub configured to provide a CI pipeline for Swift packages. It is mostly for future reference for when I next start another Swift project.

Steps

  1. Create a new directory and navigate to it
mkdir Hello
cd Hello
  1. Every package must have a manifest file called Package.swift in its root directory. You can create a minimal package named Hello using:
swift package init
  1. Build your library with:
swift build
  1. Run your tests with:
swift test
  1. Initialize your package as a git repo
git init
  1. Create a new repository in your GitHub account

  2. Commit your local changes

git add *
git add .gitignore
git commit -sm "Initial Commit"
  1. Add your GitHub repo as a remote repo
git remote add origin git@github.com:zachwick/SwiftHello.git
git push -u origin master
  1. Navigate to https://travis-ci.org/ and connect it to your GitHub account

  2. Activate your new repo in Travis-CI (https://travis-ci.org/zachwick/SwiftHello)

  3. Create .travis.yml and populate it as below:

if: tag IS blank
branches:
only:
- master
env:
global:
- SWIFT_BRANCH=swift-5.0.1-release
- SWIFT_VERSION=swift-5.0.1-RELEASE
- PACKAGE_VERSION=0.0.1
jobs:
include:
- stage: Linux test
os: linux
language: generic
dist: xenial
sudo: required
install:
- sudo apt-get install clang libcurl3 libcurl4-openssl-dev libpython2.7 libpython2.7-dev
libicu-dev libstdc++6
- curl https://swift.org/builds/$SWIFT_BRANCH/ubuntu1604/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu16.04.tar.gz
> $SWIFT_VERSION-ubuntu16.04.tar.gz
- tar xzf $SWIFT_VERSION-ubuntu16.04.tar.gz
- export PATH="$(pwd)/$SWIFT_VERSION-ubuntu16.04/usr/bin:$PATH"
script:
- swift package update
- swift test
- stage: OSX test
os: osx
osx_image: xcode10.2
language: swift
sudo: required
install:
- wget https://swift.org/builds/$SWIFT_BRANCH/xcode/$SWIFT_VERSION/$SWIFT_VERSION-osx.pkg
- sudo installer -pkg $SWIFT_VERSION-osx.pkg -target /
- export PATH="/Library/Developer/Toolchains/$SWIFT_VERSION.xctoolchain/usr/bin:$PATH"
script:
- swift package update
- swift test
- stage: Set tag
script:
- git config --global user.email "builds@travis-ci.com"
- git config --global user.name "Travis CI"
- git tag $PACKAGE_VERSION
- git push --quiet https://$GH_TOKEN@github.com/zachwick/SwiftHello --tag > /dev/null 2>&1
  1. Commit .travis.yml and push to GitHub

  2. Create a Personal Access Token in your GitHub account

  3. Install the Travis CLI tools by either

brew install travis

or

gem install travis -v 1.8.9 --no-rdoc --no-ri
  1. Set up and configure the travis CLI tool
travis login --auto
travis branches

The first command authenticates your CLI tool with your Travis-CI account using your local GitHub credentials. The second command ensures that the travis CLI tool is using your Swift project as its current project.

  1. Use the Travis CLI to add your GitHub Personal Access Token as an encrypted environment variable
echo GH_TOKEN=<YOUR TOKEN> | travis encrypt --add
  1. Add a Travis-CI build status badge to your project's README file by following the steps at https://docs.travis-ci.com/user/status-images/.

Now, everytime that you want to push a new version of your Swift project if all of your tests pass, you simply need to bump the version defined as PACKAGE_VERSION, in .travis.yml and them commit and push your changes.