Skip to content

Commit

Permalink
feat: add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ktokto313 committed Jun 6, 2024
1 parent ac9e6e9 commit 3133315
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Continuous Integration

on:
push:
branches:
- main

jobs:
release-github-artifact:
name: Release Packaging
env:
PROJECT_NAME_UNDERSCORE: rust-server
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [ cargo-check, fmt-check, test-and-coverage ]
steps:
- name: Check out from Git
uses: actions/checkout@v4

- name: Grant permission to run command
run: echo 'ACTIONS_ALLOW_UNSECURE_COMMANDS=true' >> $GITHUB_ENV

- name: Check if Git tag exists
run: echo "::set-env name=HEAD_TAG::$(git tag --points-at HEAD)"

- name: Skip if Git tag does not exist
if: steps.check-tag.outputs.HEAD_TAG == ''
run: exit 0 # Exit with success, effectively skipping subsequent steps

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Release Build
run: cargo build --release --all

- name: "Upload Artifact"
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME_UNDERSCORE }}
path: target/release/cli

release-docker-image:
env:
DOCKER_HUB_REPOSITORY: ckbrollup/zkp_ckb_toolkit
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [cargo-check, fmt-check, test-and-coverage]
steps:
- name: Check out from Git
uses: actions/checkout@v4

- name: Grant permission to run command
run: echo 'ACTIONS_ALLOW_UNSECURE_COMMANDS=true' >> $GITHUB_ENV

- name: Check if Git tag exists
run: echo "::set-env name=HEAD_TAG::$(git tag --points-at HEAD)"

- name: Skip if Git tag does not exist
if: steps.check-tag.outputs.HEAD_TAG == ''
run: exit 0 # Exit with success, effectively skipping subsequent steps

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push docker image
run: |
docker build . --tag ${{ env.DOCKER_HUB_REPOSITORY }}:latest
docker push ${{ env.DOCKER_HUB_REPOSITORY }}:latest
55 changes: 55 additions & 0 deletions .github/workflows/clippy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# rust-clippy is a tool that runs a bunch of lints to catch common
# mistakes in your Rust code and help improve your Rust code.
# More details at https://github.com/rust-lang/rust-clippy
# and https://rust-lang.github.io/rust-clippy/

name: Rust Clippy Analyzer

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '27 4 * * 6'

jobs:
rust-clippy-analyze:
name: Run Rust Clippy Analyzer
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
with:
profile: minimal
toolchain: nightly
components: clippy
override: true

- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt

- name: Run rust-clippy
run:
cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
71 changes: 71 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Docker build

on:
pull_request:
branches:
- main

jobs:
cargo-check:
name: Cargo check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
command: check

fmt-check:
name: Rust fmt
runs-on:
group: Default
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

test-and-coverage:
name: Test and Coverage
runs-on:
group: Default
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Install dependencies
run: |
# apt install libssl-dev
rustup self update
rustup update
cargo install cargo-tarpaulin
- name: Run tests with coverage
run: cargo tarpaulin --all-features --verbose
build-docker-image:
runs-on: ubuntu-latest
steps:
- name: Check out from Git
uses: actions/checkout@v4

- name: Build docker image
run: |
docker build .

0 comments on commit 3133315

Please sign in to comment.