Skip to content

Commit

Permalink
74 - Add pre-push hooks to repo and readme for instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
darricksee committed Sep 19, 2022
1 parent 53ecd74 commit 60326cc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# An example hook script to verify what is about to be pushed. Called by "git
# push" after it has checked the remote status, but before anything has been
# pushed. If this script exits with a non-zero status nothing will be pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
#
# If pushing without using a named remote those arguments will be equal.
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <local ref> <local oid> <remote ref> <remote oid>
#

set -xe

remote="$1"
url="$2"
act --job sv2_header_check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest
act --job fmt --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest
act --job clippy-check --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest
act --job ci --reuse -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-latest
8 changes: 3 additions & 5 deletions .github/workflows/clippy-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ jobs:
target: x86_64-unknown-linux-musl

steps:
- name: Install stable toolchain & components
uses: actions/checkout@v2
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.57.0
override: true
components: clippy

- name: Cargo clippy lint
uses: actions-rs/cargo@v1
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings -A dead-code
5 changes: 3 additions & 2 deletions .github/workflows/sv2-header-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
push:
branches: [ main ]
pull_request:
brances: [ main ]
branches: [ main ]

# Check sv2.h file is up to date with commit
name: sv2.h Header Check
Expand All @@ -20,11 +20,12 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1

with:
profile: minimal
toolchain: 1.57.0
override: true

- name: Check sv2 header file is up to date with commit
run: |
echo Check sv2 header file is up to date with commit
Expand Down
18 changes: 18 additions & 0 deletions README-DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Pushing to the repository
The repository is hosted on GitHub. To push changes to the repository, you need to have a GitHub account and be added
as a collaborator to the repository. You can then push changes to the repository.

To push to the repository a pre-push hook needs to be run locally to ensure that the code is formatted correctly and
tests pass. To install the pre-push hook run the following command from the root of the repo:

This tells git where the githooks are located
`# git config core.hooksPath .githooks`

The githooks rely on the following being install beforehand:

1. [act](https://github.com/nektos/act) - Github actions local runner.
2. [docker](https://docs.docker.com/get-docker/) - Docker is used to run the act runner.

Once these are installed the first time you try to push your source to the repo it'll run
./githooks/pre-push script which executes the `sv2_header_check`, `fmt`, `clippy-lint` and `ci` jobs found in the
`.github/workflows` directory.
2 changes: 1 addition & 1 deletion sv2-header-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

cargo install --version 0.20.0 cbindgen

set -e
set -ex
# cargo install cbindgen --force bts
# cbindgen -V

Expand Down

0 comments on commit 60326cc

Please sign in to comment.