Skip to content

Commit

Permalink
Store strikes locally (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbsklg authored Aug 18, 2024
1 parent 38fda63 commit 0919a64
Show file tree
Hide file tree
Showing 19 changed files with 1,200 additions and 78 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/cli-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Cli-client
defaults:
run:
shell: bash
working-directory: cli-client

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

- name: Run tests
run: cargo test

fmt:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

- name: Enforce formatting
run: cargo fmt -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Linting
run: cargo clippy -- -D warnings

coverage:
name: Code coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

- name: Install tarpaulin
run: cargo install cargo-tarpaulin

- name: Generate code coverage
run: cargo tarpaulin --verbose --workspace

Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
name: Infrastructure
defaults:
run:
shell: bash
working-directory: infrastructure
name: Deploy
on: [pull_request]

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
id-token: write
contents: read
pull-requests: write

jobs:
deploy-infrastructure:
infrastructure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -42,7 +51,7 @@ jobs:

- name: Terraform Plan
id: plan
if: github.event == 'pull_request'
if: github.event_name == 'pull_request'
run: terraform plan

- name: Terraform Apply
Expand Down
137 changes: 137 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Release

defaults:
run:
shell: bash

permissions:
contents: write

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+-*"

jobs:
build:
name: Build artifact
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
rust: stable
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
rust: stable
- target: x86_64-apple-darwin
os: macos-latest
rust: stable

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}

- name: Get release version number
if: env.VERSION == ''
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
working-directory: cli-client

- name: Check that tag version and Cargo.toml version are the same
shell: bash
run: |
if ! grep -q "version = \"$VERSION\"" Cargo.toml; then
echo "version does not match Cargo.toml" >&2
exit 1
fi
working-directory: cli-client

- name: Install C compilation tooling (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update -y
sudo apt-get install clang gcc-aarch64-linux-gnu musl-tools -y
working-directory: cli-client

- name: Add rustup target
run: rustup target add ${{ matrix.target }}
working-directory: cli-client

- uses: taiki-e/install-action@v2
with:
tool: cross

- name: Build release
run: cross build --release --target ${{ matrix.target }}
working-directory: cli-client

- name: Create release directory
run: mkdir -p artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }}
working-directory: cli-client

- name: Move binary to release directory
run: mv target/${{ matrix.target }}/release/strikes artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }}
working-directory: cli-client

- name: Create tarball
run: tar -czf ./artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }}.tar.gz -C artifacts strikes-${{ env.VERSION }}-${{ matrix.target }}
working-directory: cli-client

- name: Upload tarball
uses: actions/upload-artifact@v4
with:
name: strikes-${{ env.VERSION }}-${{ matrix.target }}
path: ./cli-client/artifacts/strikes-${{ env.VERSION }}-${{ matrix.target }}.tar.gz

release:
name: Release artifacts
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4

- name: Get release version number
if: env.VERSION == ''
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV

- name: Debug
uses: actions/download-artifact@v4

- name: List files
run: ls -R

- name: Download arm64 tarball
uses: actions/download-artifact@v4
with:
name: strikes-${{ env.VERSION }}-aarch64-unknown-linux-musl

- name: Download x86_64_apple_darwin tarball
uses: actions/download-artifact@v4
with:
name: strikes-${{ env.VERSION }}-x86_64-apple-darwin

- name: Download x86_64 tarball
uses: actions/download-artifact@v4
with:
name: strikes-${{ env.VERSION }}-x86_64-unknown-linux-musl

- name: Release arm64 tarball
uses: softprops/action-gh-release@v1
with:
files: |
strikes-${{ env.VERSION }}-aarch64-unknown-linux-musl.tar.gz
- name: Release x86_64_apple_darwin tarball
uses: softprops/action-gh-release@v1
with:
files: |
strikes-${{ env.VERSION }}-x86_64-apple-darwin.tar.gz
- name: Release x86_64 tarball
uses: softprops/action-gh-release@v1
with:
files: |
strikes-${{ env.VERSION }}-x86_64-unknown-linux-musl.tar.gz
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# Strikes

## Usage
- Add a strike to a user
```bash
strikes strike <user>
```

- List all strikes
```bash
strikes ls
```

## Use locally only
You can use the local client without a remote server.
It will generate a JSON file where the strikes are stored.
The default path is in your home directory at '.strikes/db.json'.
You can configure a different location by using the '--db-path' argument or by providing a configuration file.
The argument has precedence over the configuration file.

### Configuration file
The configuration file needs to be a yaml file.

```yaml
db_path: /path/to/db.json
```
The following command will create a database (db.json) in the current directory.
```bash
strikes --db-path ./my-db.json strike <user>
```

Loading

0 comments on commit 0919a64

Please sign in to comment.