-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (95 loc) · 3.48 KB
/
general_build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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