Skip to content

Reworked CI #883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Audit

on:
push:
pull_request:
paths:
- "**/Cargo.toml"
- "**/Cargo.lock"
Expand Down
136 changes: 95 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
on: [push, pull_request]
name: CI

on: [push, pull_request]

env:
RUST_BACKTRACE: 1

Expand All @@ -10,38 +10,43 @@ jobs:
name: Test
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- uses: actions/checkout@master
- id: install
uses: actions-rs/toolchain@v1
with:
fetch-depth: 2

- name: Install stable Rust
run: rustup update stable && rustup default stable

- name: Set rustc version
run: echo "::set-env name=CURRENT_RUSTC_VERSION::$(rustc -V)"
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: install
args: cargo-sweep

# Caching
- name: Cache Cargo directories
- name: Cache directories
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/bin
~/.cargo/git
~/.cargo/registry
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Cargo Build
key: cargo-test-dirs-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-test-dirs-
- name: Cache build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ env.CURRENT_RUSTC_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
key: cargo-test-build-${{ steps.install.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-target-${{ env.CURRENT_RUSTC_VERSION }}-
cargo-test-build-${{ steps.install.outputs.rustc_hash }}-
cargo-test-build-

- name: Register artifacts
uses: actions-rs/cargo@v1
with:
command: sweep
args: --stamp

- name: Launch the postgres and min.io images
- name: Launch postgres and min.io
run: |
cp .env.sample .env
. .env
Expand All @@ -52,38 +57,87 @@ jobs:
# Make sure the database is actually working
psql "${CRATESFYI_DATABASE_URL}"

- name: Run rustfmt
run: cargo fmt -- --check

- name: Run clippy
run: cargo clippy --locked -- -D warnings

- name: Build docs.rs
- name: Build
run: cargo build --locked

- name: Test docs.rs
- name: Test
run: cargo test --locked -- --test-threads=1

- name: Clean up the database
run: docker-compose down --volumes

docker:
name: Docker
- name: Clean unused artifacts
uses: actions-rs/cargo@v1
with:
command: sweep
args: --file

fmt:
name: Rustfmt
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- id: install
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt

- uses: actions-rs/cargo@v1
with:
fetch-depth: 2
command: fmt
args: -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest

- name: Build the Docker image
run: docker build -t docs-rs -f dockerfiles/Dockerfile .
steps:
- uses: actions/checkout@master
- id: install
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: clippy
- uses: actions-rs/cargo@v1
with:
command: install
args: cargo-sweep

- name: Cache directories
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/bin
~/.cargo/git
key: cargo-clippy-dirs-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-clippy-dirs-
- name: Cache build
uses: actions/cache@v2
with:
path: target
key: cargo-clippy-${{ steps.install.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-clippy-${{ steps.install.outputs.rustc_hash }}-
cargo-clippy-

- name: Register artifacts
uses: actions-rs/cargo@v1
with:
command: sweep
args: --stamp

- uses: actions-rs/cargo@v1
with:
command: clippy
args: --locked -- -D warnings

- name: Upload the Docker image to ECR
uses: rust-lang/simpleinfra/github-actions/upload-docker-image@master
- name: Clean unused artifacts
uses: actions-rs/cargo@v1
with:
image: docs-rs
repository: staging-docs-rs
region: us-west-1
aws_access_key_id: "${{ secrets.aws_access_key_id }}"
aws_secret_access_key: "${{ secrets.aws_secret_access_key }}"
if: github.ref == 'refs/heads/master'
command: sweep
args: --file
23 changes: 23 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Docker

on: [push, pull_request]

jobs:
docker:
name: Build and upload docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Build the Docker image
run: docker build -t docs-rs -f dockerfiles/Dockerfile .

- name: Upload the Docker image to ECR
uses: rust-lang/simpleinfra/github-actions/upload-docker-image@master
with:
image: docs-rs
repository: staging-docs-rs
region: us-west-1
aws_access_key_id: "${{ secrets.aws_access_key_id }}"
aws_secret_access_key: "${{ secrets.aws_secret_access_key }}"
if: github.ref == 'refs/heads/master'
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ services:
AWS_SECRET_ACCESS_KEY: secret_key
env_file:
- .env
healthcheck:
test: ["CMD", "curl", "--silent", "--fail", "localhost:3000"]
interval: 10s
timeout: 5s
retries: 10

db:
build:
context: ./dockerfiles
Expand All @@ -35,6 +41,12 @@ services:
ports:
# Use a non-standard port on the host to avoid conflicting with existing postgres servers
- "15432:5432"
healthcheck:
test: ["CMD", "pg_isready"]
interval: 10s
timeout: 5s
retries: 10

s3:
image: minio/minio
entrypoint: >
Expand All @@ -49,12 +61,32 @@ services:
environment:
MINIO_ACCESS_KEY: cratesfyi
MINIO_SECRET_KEY: secret_key
healthcheck:
test:
[
"CMD",
"curl",
"--silent",
"--fail",
"localhost:9000/minio/health/ready",
]
interval: 10s
timeout: 5s
retries: 10

prometheus:
build:
context: ./dockerfiles
dockerfile: ./Dockerfile-prometheus
ports:
- "9090:9090"
healthcheck:
test:
["CMD", "curl", "--silent", "--fail", "localhost:9090/-/ready"]
interval: 10s
timeout: 5s
retries: 10

volumes:
postgres-data: {}
minio-data: {}
Expand Down