Skip to content

Added new modules (#6) #28

Added new modules (#6)

Added new modules (#6) #28

Workflow file for this run

name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
ports:
- 5100:5432 # Map port 5100 on the host to 5432 in the container
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: test_db
options: >-
--health-cmd="pg_isready -h localhost -p 5432 -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
# Install the dotenv CLI tool to load the .env file
- name: Install dotenv CLI
run: sudo apt-get install -y dotenv
# Install sqlx-cli to manage database and migrations
- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features postgres
# Wait for PostgreSQL to be ready on the host's port 5100
- name: Wait for PostgreSQL
run: |
until pg_isready -h localhost -p 5100 -U postgres; do
echo "Waiting for PostgreSQL to be ready on port 5100..."
sleep 2
done
# Set up environment variables for PostgreSQL and from the .env file
- name: Load environment variables from .env
run: dotenv -f .env | tee -a $GITHUB_ENV
# Set up PostgreSQL environment variable for testing on port 5100
- name: Set up PostgreSQL environment variables
run: echo "DATABASE_URL=postgres://postgres:password@localhost:5100/test_db" >> $GITHUB_ENV
# Create the test_db database using sqlx-cli
- name: Create database
run: sqlx database create
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
# Run migrations using sqlx-cli
- name: Run migrations
run: sqlx migrate run
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
# Build project
- name: Build project
run: cargo build --verbose
# Run tests
- name: Run tests
run: cargo test
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
# Run linter
- name: Run linter
run: cargo clippy -- -D warnings
# Generate documentation
- name: Generate documentation
run: cargo doc --no-deps --document-private-items
# Increment version
- name: Increment version
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
cargo install cargo-bump
cargo bump patch
NEW_VERSION=$(grep -m1 version Cargo.toml | cut -d '"' -f2)
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
# Update README.md with new version
- name: Update README.md
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
sed -i 's/img.shields.io\/crates\/v\/isotopes.svg/img.shields.io\/badge\/version-'"$NEW_VERSION"'-blue/' README.md
# Commit and push changes
- name: Commit and push changes
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add Cargo.toml README.md
git commit -m "Bump version to $NEW_VERSION"
git push