Password Manager

You can find source code and guidelines on Github.

Intention behind this project to learn:

  • How to build a CLI
  • How to use Github Actions to build CI pipelines
  • How to release your project for cross-platform
  • How to add a formula to Homebrew

Passman

To learn concepts described above, I have built a CLI that generates and manages password on your local computer.

It has the following functionality:

generate: generates a random password
get: retrieves an account and password information
create: saves a password and its associated account
update: updates a password and its associated account
delete: deletes a password and its associated account

Usage of each functionality is described on Github.

Part I: CLI

To build a CLI, I used this package which is a pretty popular CLI building package for Golang. It gives flexibility to use flags, subcommands and many other features with ease.

Part II: Actions

To automate the process after a commit push, you can do the following:

cd <YOUR_PROJECT_PATH>
mkdir .github
mkdir .github/workflows
touch .github/workflows/{action}.yaml

you can define the name of action however you want.

After an action file is created, you can define steps of process to automate.

For example, the following script checks if this project can be built succesfully on cross-platform

name: build

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - '**'

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        go-version: [ 1.17.x ]
        os: [ ubuntu-latest, macOS-latest, windows-latest ]

    steps:
      - name: Install Go
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go-version }}

      - name: Checkout code
        uses: actions/checkout@v2

      - name: Test
        timeout-minutes: 2
        run: |
                    go build cmd/passman/main.go

You can check other actions that I use here

Also, you can check full docs at here

PART III: Release

When a version of a project is done, i.e. it compiles and passes all tests successfully, you can get a release for that version.

Go provides a nice project with Github Actions integrations named Go Releaser. This project allows us to reduce release process to just define a single action file and a config file .goreleaser.yaml

You can check action file here

And, you can check .goreleaser.yaml here

After both files are created, I do the following:

git tag <version> # v1.0.1
git push origin <version> # v1.0.1

Then, on Github:

  • Go to your project page
  • Click Releases section on the right
  • Click New Release
  • Select the tag you just pushed
  • Publish release

After release action is done, it may took a few minutes, you can see changelog, executables and checksums on your release page.

Part IV: Homebrew Formula

This project is available on Homebrew to download as:

brew install harunsasmaz/tap/passman

To be able to do this, what you have to do is:

  • Create a public Github project named homebrew-tap
  • Create a directory named Formula
  • Create a file named your package, i.e. passman.rb
  • Define package name, where to find executables to download and their checksums for verification, see passman.rb

When you call:

brew tap harunsasmaz/tap
# or
brew install harunsasmaz/tap/passman

Homebrew reaches to this repository and identifies formulas inside Formula directory. If you install any of these formulas, it resolves your OS and Arch and downloads related binary.

Notes

To build something cross-platform with Go, be sure that you do not have any dependency on CGO.

To make sure, build your program with:

CGO_ENABLED=0 go build -o {app} cmd/{app}/main.go
./{app} # provide args if needed