Skip to content

Commit

Permalink
Setup CI (#5)
Browse files Browse the repository at this point in the history
Setups CI via github actions
  • Loading branch information
JosephMoniz committed Oct 4, 2023
1 parent 5e8defe commit 3204210
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests
on:
pull_request:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Deps
id: cache-deps
uses: actions/cache@v3
with:
path: build-cache
key: ${{ runner.os }}-${{ hashFiles('Cargo.toml', 'front-line*/Cargo.toml', '.pre-commit-config.yaml', 'dev.docker') }}
- name: Pull and build deps
if: steps.cache-deps.outputs.cache-hit != 'true'
run: make build-ci
test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Restore cache
uses: actions/cache/restore@v3
with:
path: build-cache
key: ${{ runner.os }}-${{ hashFiles('Cargo.toml', 'front-line*/Cargo.toml', '.pre-commit-config.yaml', 'dev.docker') }}
- name: Run tests
run: make test-ci
pre-commit:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Restore cache
uses: actions/cache/restore@v3
with:
path: build-cache
key: ${{ runner.os }}-${{ hashFiles('Cargo.toml', 'front-line*/Cargo.toml', '.pre-commit-config.yaml', 'dev.docker') }}
- name: Run pre-commit
run: make pre-commit-ci
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ repos:
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- repo: local
hooks:
- id: doctoc
Expand Down
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ build-image:

.PHONY: build-dev
build-dev: build-image
@cp ./docker/pre-commit-hook.sh .git/hooks/pre-commit
@IMAGE=$(IMAGE) ./docker/run.sh cargo build
cp ./docker/pre-commit-hook.sh .git/hooks/pre-commit
@IMAGE=$(IMAGE) ./docker/run.sh pre-commit install-hooks

.PHONY: test
test: build-dev
Expand All @@ -24,3 +24,21 @@ pre-commit-all: build-dev
.PHONY: shell
shell: build-dev
@IMAGE=$(IMAGE) ./docker/run.sh bash

.PHONY: build-ci
build-ci: build-dev
IMAGE=$(IMAGE) ./docker/run.sh cargo build
sudo chmod -R ugo+rwx ./build-cache
docker save "$(IMAGE)" | gzip > ./build-cache/docker-image.tar.gz

.PHONY: load-ci
load-ci:
@gunzip -c ./build-cache/docker-image.tar.gz | docker load

.PHONY: test-ci
test-ci: load-ci
@IMAGE=$(IMAGE) ./docker/run.sh cargo test

.PHONY: pre-commit-ci
pre-commit-ci: load-ci
@IMAGE=$(IMAGE) ./docker/run.sh pre-commit run --all-files --color=always
3 changes: 3 additions & 0 deletions dev.docker
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs/ | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup install 1.72.1

# Mark the git mount as safe
RUN git config --global --add safe.directory /opt/front-line

# Copy the docker utility scripts and set the entrypoint to the proxy script
COPY docker /opt/docker
ENTRYPOINT ["/opt/docker/entrypoint.sh"]
3 changes: 2 additions & 1 deletion docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fi
DIR="$( cd "$( dirname "$0" )" && pwd )"
PARENT_DIR="$(dirname "$DIR")"
MOUNT_CMD="-v ${PARENT_DIR}:/opt/front-line -v ${PARENT_DIR}/build-cache:/root/.cache"

ENV_VARS="-e CARGO_TARGET_DIR=/root/.cache/rust -e CARGO_HOME=/root/.cache/cargo"

docker run --rm ${TTY_FLAG} ${ENV_VARS} ${MOUNT_CMD} ${IMAGE} "$@"
docker run --rm ${TTY_FLAG} ${ENV_VARS} ${MOUNT_CMD} ${IMAGE} "$@"

0 comments on commit 3204210

Please sign in to comment.