diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..926e4d5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daly" diff --git a/.github/workflows/build-checker.yml b/.github/workflows/build-checker.yml new file mode 100644 index 0000000..11e3e42 --- /dev/null +++ b/.github/workflows/build-checker.yml @@ -0,0 +1,41 @@ +name: binary build checker +on: + push: + branches: ["main","develop"] + +env: + CARGO_TERM_COLOR: always + RUST_LOG: info + +jobs: + check: + name: cargo check + runs-on: ubuntu-latest + env: + SQLX_OFFLINE: true + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + - name: Run cargo check + run: cargo check --tests diff --git a/.github/workflows/code-formater.yml b/.github/workflows/code-formater.yml new file mode 100644 index 0000000..38886e8 --- /dev/null +++ b/.github/workflows/code-formater.yml @@ -0,0 +1,24 @@ +name: format checker +on: + push: + branches: ["main","develop"] + +env: + CARGO_TERM_COLOR: always + RUST_LOG: info + +jobs: + fmt: + name: cargo fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + components: rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.github/workflows/code-linter.yml b/.github/workflows/code-linter.yml new file mode 100644 index 0000000..5b6a8fd --- /dev/null +++ b/.github/workflows/code-linter.yml @@ -0,0 +1,27 @@ +name: code linter +on: + push: + branches: ["main","develop"] + +env: + CARGO_TERM_COLOR: always + RUST_LOG: info + +jobs: + clippy: + name: cargo clippy + runs-on: ubuntu-latest + env: + SQLX_OFFLINE: true + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: clippy + override: true + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-features + diff --git a/.github/workflows/image-builder.yml b/.github/workflows/image-builder.yml new file mode 100644 index 0000000..f4dbf45 --- /dev/null +++ b/.github/workflows/image-builder.yml @@ -0,0 +1,41 @@ +name: build docker image + +on: + push: + branches: ["main"] + +env: + CARGO_TERM_COLOR: always + RUST_LOG: info + +jobs: + build: + name: build image + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository_owner }}/rustfulapi:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/security-checker.yml b/.github/workflows/security-checker.yml new file mode 100644 index 0000000..39afc08 --- /dev/null +++ b/.github/workflows/security-checker.yml @@ -0,0 +1,14 @@ +name: security checker +on: + push: + paths: + - "**/Cargo.toml" + - "**/Cargo.lock" +jobs: + security_audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/audit-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/spell-checker.yml b/.github/workflows/spell-checker.yml new file mode 100644 index 0000000..0722a2d --- /dev/null +++ b/.github/workflows/spell-checker.yml @@ -0,0 +1,17 @@ +name: spell checker +on: [pull_request] + +env: + CARGO_TERM_COLOR: always + RUST_LOG: info + +jobs: + typos: + name: typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v3 + + - name: Check spelling + uses: crate-ci/typos@master diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml new file mode 100644 index 0000000..e885bf9 --- /dev/null +++ b/.github/workflows/test-coverage.yml @@ -0,0 +1,108 @@ +name: test coverage + +on: + push: + branches: ["main"] + +jobs: + test: + name: coverage + runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres_user + POSTGRES_PASSWORD: postgres_pass + POSTGRES_DB: postgres_db + ports: + - 5432:5432 + redis: + image: redis:latest + ports: + - 6379:6379 + mailhog: + image: mailhog/mailhog:latest + ports: + - 1025:1025 + - 8025:8025 + mockserver: + image: mockserver/mockserver:latest + env: + MOCKSERVER_LOG_LEVEL: DEBUG + SERVER_PORT: 8026 + ports: + - 8026:8026 + env: + APP_PROFILE: test + SQLX_VERSION: 0.7.1 + SQLX_FEATURES: postgres + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + + - name: Cache sqlx-cli + uses: actions/cache@v3 + id: cache-sqlx + with: + path: | + ~/.cargo/bin/sqlx + ~/.cargo/bin/cargo-sqlx + key: ${{ runner.os }}-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES }} + + - name: Install sqlx-cli + uses: actions-rs/cargo@v1 + if: steps.cache-sqlx.outputs.cache-hit == false + with: + command: install + args: > + sqlx-cli + --force + --version=${{ env.SQLX_VERSION }} + --features=native-tls,${{ env.SQLX_FEATURES }} + --no-default-features + --locked + + - name: Cache tarpaulin + uses: actions/cache@v3 + id: cache-tarpaulin + with: + path: | + ~/.cargo/bin/cargo-tarpaulin + key: ${{ runner.os }}-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES }} + + - name: Install tarpaulin + uses: actions-rs/cargo@v1 + if: steps.cache-sqlx.outputs.cache-hit == false + with: + command: install + args: > + cargo-tarpaulin + + - name: Migrate database + run: | + sudo apt-get install -y libpq-dev + ./scripts/init_postgres.sh + + - name: Add mockserver expections + run: | + ./scripts/init_mockserver.sh + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Generate code coverage + run: | + cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out Xml + + - name: Upload to codecov.io + uses: codecov/codecov-action@v3 + with: + #token: ${{secrets.CODECOV_TOKEN}} # not required for public repos + fail_ci_if_error: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4a5184f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,131 @@ +name: test +on: + push: + branches: ["main","develop"] + +env: + CARGO_TERM_COLOR: always + RUST_LOG: info + +jobs: + test: + name: cargo test + runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres_user + POSTGRES_PASSWORD: postgres_pass + POSTGRES_DB: postgres_db + ports: + - 5432:5432 + redis: + image: redis:latest + ports: + - 6379:6379 + mailhog: + image: mailhog/mailhog:latest + ports: + - 1025:1025 + - 8025:8025 + mockserver: + image: mockserver/mockserver:latest + env: + MOCKSERVER_LOG_LEVEL: DEBUG + SERVER_PORT: 8026 + ports: + - 8026:8026 + env: + APP_PROFILE: test + SQLX_VERSION: 0.7.1 + SQLX_FEATURES: postgres + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Cache sqlx-cli + uses: actions/cache@v2 + id: cache-sqlx + with: + path: | + ~/.cargo/bin/sqlx + ~/.cargo/bin/cargo-sqlx + key: ${{ runner.os }}-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES }} + + - name: Install sqlx-cli + uses: actions-rs/cargo@v1 + if: steps.cache-sqlx.outputs.cache-hit == false + with: + command: install + args: > + sqlx-cli + --force + --version=${{ env.SQLX_VERSION }} + --features=native-tls,${{ env.SQLX_FEATURES }} + --no-default-features + --locked + + - name: Migrate database + run: | + sudo apt-get install libpq-dev -y + ./scripts/init_postgres.sh + + - name: Check .sqlx is up-to-date + run: | + cargo sqlx prepare --check --workspace + + - name: Add mockserver expections + run: | + ./scripts/init_mockserver.sh + + - name: Run cargo test + uses: actions-rs/cargo@v1 + with: + command: test + + # - name: Test Success + # uses: rjstone/discord-webhook-notify@v1 + # if: success() + # with: + # severity: info + # details: Test Succeeded! + # webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} + + # - name: Test Failure + # uses: rjstone/discord-webhook-notify@v1 + # if: failure() + # with: + # severity: error + # details: Test Failed! + # webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} + + # - name: Test Cancelled + # uses: rjstone/discord-webhook-notify@v1 + # if: cancelled() + # with: + # severity: warn + # details: Test Cancelled! + # webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} +