From 2b58901510ea5e8664d4bacbc89c8a43a4577be8 Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Sat, 11 Nov 2023 21:38:12 +0100 Subject: [PATCH] ci: refactor steps --- .github/workflows/cd.yml | 40 ------------- .github/workflows/ci.yml | 115 +++++++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 48 ---------------- 3 files changed, 115 insertions(+), 88 deletions(-) delete mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml deleted file mode 100644 index 106efcf..0000000 --- a/.github/workflows/cd.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Continous Deployment - -on: - workflow_dispatch: - push: - branches: - - "master" - - "devnet*" - -jobs: - docker: - runs-on: ubuntu-latest - - 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 }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..363bb04 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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/ssh-action@v0.0.7 + 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/ssh-action@v0.0.7 + with: + host: ${{ secrets.SSH_HOST }} + username: deploy + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_KEY }} + script: ./deploy-blobscan.sh diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index f4b8998..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Rust - -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: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose