From 72df0769b371ca8cfafd7f14fc9cd8e05ae1c83a Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sun, 27 Mar 2022 22:02:31 +0530 Subject: [PATCH] feat: setup CI --- .github/FUNDING.yml | 12 ++++ .github/workflows/clippy-fmt.yml | 43 ++++++++++++ .github/workflows/coverage.yml | 82 ++++++++++++++++++++++ .github/workflows/linux.yml | 117 +++++++++++++++++++++++++++++++ Makefile | 59 ++++++++++++++++ 5 files changed, 313 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/clippy-fmt.yml create mode 100644 .github/workflows/coverage.yml create mode 100644 .github/workflows/linux.yml create mode 100644 Makefile diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..fc20bf9 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +# github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +# patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +# ko_fi: # Replace with a single Ko-fi username +# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: realaravinth +issuehunt: # Replace with a single IssueHunt username +# otechie: # Replace with a single Otechie username +custom: ['https://batsense.net/donate'] diff --git a/.github/workflows/clippy-fmt.yml b/.github/workflows/clippy-fmt.yml new file mode 100644 index 0000000..325e539 --- /dev/null +++ b/.github/workflows/clippy-fmt.yml @@ -0,0 +1,43 @@ +name: Lint + +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + - name: Check with rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + override: true + + - name: Check with Clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --workspace --tests --all-features diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..4488b23 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,82 @@ +name: Coverage + +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master + +jobs: + build_and_test: + strategy: + fail-fast: false + matrix: + version: + - stable + + # services: + # postgres: + # image: postgres + # env: + # POSTGRES_PASSWORD: password + # POSTGRES_USER: postgres + # POSTGRES_DB: postgres + # options: >- + # --health-cmd pg_isready + # --health-interval 10s + # --health-timeout 5s + # --health-retries 5 + # ports: + # - 5432:5432 + + name: ${{ matrix.version }} - x86_64-unknown-linux-gnu + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: ⚡ Cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Install ${{ matrix.version }} + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.version }}-x86_64-unknown-linux-gnu + profile: minimal + override: true + + - name: load env + run: | + source .env-sample \ + && echo "POSTGRES_DATABASE_URL=$POSTGRES_DATABASE_URL" >> $GITHUB_ENV \ + && echo "SQLITE_DATABASE_URL=$SQLITE_DATABASE_URL" >> $GITHUB_ENV + + - name: run migrations + run: make migrate + # env: + # GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value + # POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + # SQLITE_DATABASE_URL: "${{ env.SQLITE_DATABASE_URL }}" + + - name: Generate coverage file + if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request') + uses: actions-rs/tarpaulin@v0.1 + # env: + # # GIT_HASH is dummy value. I guess build.rs is skipped in tarpaulin + # # execution so this value is required for preventing meta tests from + # # panicking + # GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 + # POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + # SQLITE_DATABASE_URL: "${{ env.SQLITE_DATABASE_URL }}" + with: + args: "--all-features --no-fail-fast --workspace=database/db-sqlx-postgres,database/db-sqlx-sqlite,. -t 1200" + + - name: Upload to Codecov + if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request') + uses: codecov/codecov-action@v2 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..3fcad64 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,117 @@ +name: Build + +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master + +jobs: + build_and_test: + strategy: + fail-fast: false + matrix: + version: + - stable + # - nightly + + name: ${{ matrix.version }} - x86_64-unknown-linux-gnu + runs-on: ubuntu-latest + + # services: + # postgres: + # image: postgres + # env: + # POSTGRES_PASSWORD: password + # POSTGRES_USER: postgres + # POSTGRES_DB: postgres + # options: >- + # --health-cmd pg_isready + # --health-interval 10s + # --health-timeout 5s + # --health-retries 5 + # ports: + # - 5432:5432 + # + steps: + - uses: actions/checkout@v2 + - name: ⚡ Cache + uses: actions/cache@v2 + with: + path: | + /var/lib/docker + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + # - name: Login to DockerHub + # if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'forgeflux-org/world' + # uses: docker/login-action@v1 + # with: + # username: ${{ secrets.DOCKERHUB_USERNAME }} + # password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Install ${{ matrix.version }} + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.version }}-x86_64-unknown-linux-gnu + profile: minimal + override: true + + # - name: load env + # run: | + # source .env-sample \ + # && echo "POSTGRES_DATABASE_URL=$POSTGRES_DATABASE_URL" >> $GITHUB_ENV \ + # && echo "SQLITE_DATABASE_URL=$SQLITE_DATABASE_URL" >> $GITHUB_ENV + # + - name: build + run: make + # env: + # POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + # SQLITE_DATABASE_URL: "${{ env.SQLITE_DATABASE_URL }}" + + # - name: build docker images + # if: matrix.version == 'stable' + # run: make docker + # + # - name: publish docker images + # if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'realaravinth/gitpad' + # run: make docker-publish + # + # - name: run migrations + # run: make migrate + # env: + # GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value + # POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + # SQLITE_DATABASE_URL: "${{ env.SQLITE_DATABASE_URL }}" + + - name: run tests + timeout-minutes: 40 + run: make test + # env: + # GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value + # POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + # SQLITE_DATABASE_URL: "${{ env.SQLITE_DATABASE_URL }}" + + - name: generate documentation + if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'realaravinth/gitpad' + run: make doc + # env: + # GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value + # POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + # SQLITE_DATABASE_URL: "${{ env.SQLITE_DATABASE_URL }}" + + - name: Deploy to GitHub Pages + if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'realaravinth/gitpad' + uses: JamesIves/github-pages-deploy-action@3.7.1 + with: + branch: gh-pages + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FOLDER: deploy-static + + # - name: deploy + # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'realaravinth/realaravinth' }} + # run: >- + # curl --location --request POST "https://deploy.batsense.net/api/v1/update" --header 'Content-Type: application/json' --data-raw "{ \"secret\": \"${{ secrets.DEPLOY_TOKEN }}\", \"branch\": \"gh-pages\" }" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8343f18 --- /dev/null +++ b/Makefile @@ -0,0 +1,59 @@ +default: ## Debug build + cargo build + +clean: ## Clean all build artifacts and dependencies + @-/bin/rm -rf target/ + @-/bin/rm -rf database/migrator/target/ + @-/bin/rm -rf database/*/target/ + @-/bin/rm -rf database/*/tmp/ + @cargo clean + +coverage: migrate ## Generate coverage report in HTML format + cargo tarpaulin -t 1200 --out Html --skip-clean --all-features --no-fail-fast --workspace=database/db-sqlx-postgres,database/db-sqlx-sqlite,. + +dev-env: ## Download development dependencies + cargo fetch + +doc: ## Prepare documentation + cargo doc --no-deps --workspace --all-features + +#docker: ## Build docker images +# docker build -t realaravinth/gitpad:master -t realaravinth/gitpad:latest . +# +#docker-publish: docker ## Build and publish docker images +# docker push realaravinth/gitpad:master +# docker push realaravinth/gitpad:latest + +lint: ## Lint codebase + cargo fmt -v --all -- --emit files + cargo clippy --workspace --tests --all-features + +release: ## Release build + cargo build --release + +run: default ## Run debug build + cargo run + +migrate: ## run migrations + echo TODO: add migrations +# @-rm -rf database/db-sqlx-sqlite/tmp && mkdir database/db-sqlx-sqlite/tmp +# cd database/migrator && cargo run + +sqlx-offline-data: ## prepare sqlx offline data + cargo sqlx prepare --database-url=${POSTGRES_DATABASE_URL} -- --bin gitpad \ + --all-features + +test: migrate ## Run tests + cd database/db-sqlx-postgres &&\ + DATABASE_URL=${POSTGRES_DATABASE_URL}\ + cargo test --no-fail-fast + cd database/db-sqlx-sqlite &&\ + DATABASE_URL=${SQLITE_DATABASE_URL}\ + cargo test --no-fail-fast + cargo test + +xml-test-coverage: migrate ## Generate cobertura.xml test coverage + cargo tarpaulin -t 1200 --out Xml --skip-clean --all-features --no-fail-fast --workspace=database/db-sqlx-postgres,database/db-sqlx-sqlite,. + +help: ## Prints help for targets with comments + @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'