Skip to content

Commit

Permalink
ci: refactor steps
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloCastellano committed Nov 11, 2023
1 parent de64643 commit 2b58901
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 88 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/cd.yml

This file was deleted.

115 changes: 115 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Continuous Integration (build, test, docker, deploy)

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

env:
CARGO_TERM_COLOR: always

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustfmt, clippy
override: true

- name: cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check

- name: cargo clippy
uses: actions-rs/clippy-check@v1
with:
args: --all --all-features -- -D warnings
token: ${{ secrets.GITHUB_TOKEN }}

build-test:
runs-on: ubuntu-latest
needs: lint

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

docker:
runs-on: ubuntu-latest
needs: build-test

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: blossomlabs/blobscan-indexer
tags: |
type=ref,event=branch
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy_staging:
if: github.ref_name == 'next'
name: Deploy blobscan api (staging)
runs-on: ubuntu-latest
environment:
name: staging
url: https://staging.blobscan.com
needs: docker
steps:
- uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: deploy
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
script: ./deploy-blobscan.sh

deploy_prod:
if: github.ref_name == 'master'
name: Deploy blobscan api (prod)
runs-on: ubuntu-latest
environment:
name: production
url: https://blobscan.com
needs: docker
steps:
- uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: deploy
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
script: ./deploy-blobscan.sh
48 changes: 0 additions & 48 deletions .github/workflows/rust.yml

This file was deleted.

0 comments on commit 2b58901

Please sign in to comment.