try
Some checks failed
Optimized CI/CD Pipeline / prepare-dependencies (push) Failing after 30s
Optimized CI/CD Pipeline / build-and-test (backend) (push) Has been skipped
Optimized CI/CD Pipeline / build-and-test (frontend) (push) Has been skipped
Optimized CI/CD Pipeline / deploy (push) Has been skipped
Some checks failed
Optimized CI/CD Pipeline / prepare-dependencies (push) Failing after 30s
Optimized CI/CD Pipeline / build-and-test (backend) (push) Has been skipped
Optimized CI/CD Pipeline / build-and-test (frontend) (push) Has been skipped
Optimized CI/CD Pipeline / deploy (push) Has been skipped
This commit is contained in:
parent
77d9e2ea9f
commit
ea07383d42
@ -1,4 +1,4 @@
|
|||||||
name: CI/CD Pipeline
|
name: Optimized CI/CD Pipeline
|
||||||
|
|
||||||
on: push
|
on: push
|
||||||
|
|
||||||
@ -7,157 +7,97 @@ env:
|
|||||||
SSH_HOST: ${{ secrets.SSH_HOST }}
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
||||||
SSH_USER: ${{ secrets.SSH_USER }}
|
SSH_USER: ${{ secrets.SSH_USER }}
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
CARGO_INCREMENTAL: 0
|
NODE_VERSION: '16.x'
|
||||||
|
RUST_IMAGE: 'rust:latest'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-frontend:
|
prepare-dependencies:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: rust:latest
|
container: ${{ env.RUST_IMAGE }}
|
||||||
steps:
|
outputs:
|
||||||
- name: Setup Environment
|
cache-key: ${{ steps.cache-dependencies.outputs.cache-key }}
|
||||||
run: |
|
|
||||||
apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Run Test DB Script
|
|
||||||
run: ./test_db.sh
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cargo build
|
|
||||||
cd frontend && npm install && npm run build
|
|
||||||
- name: Install dependencies
|
|
||||||
run: cd frontend && npm install
|
|
||||||
- name: Install Playwright Browsers
|
|
||||||
run: cd frontend && npx playwright install --with-deps
|
|
||||||
- name: Run Playwright tests
|
|
||||||
run: cd frontend && npx playwright test --workers 1
|
|
||||||
#- uses: actions/upload-artifact@v3
|
|
||||||
# if: always()
|
|
||||||
# with:
|
|
||||||
# name: playwright-report
|
|
||||||
# path: frontend/playwright-report/
|
|
||||||
# retention-days: 30
|
|
||||||
|
|
||||||
test-backend:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: rust:latest
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Environment
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Cache Node Modules
|
||||||
|
uses: actions/cache@v3
|
||||||
|
id: cache-dependencies
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
frontend/node_modules
|
||||||
|
~/.cargo
|
||||||
|
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
|
- name: Install Node.js and Rust Dependencies
|
||||||
run: |
|
run: |
|
||||||
apt-get update -qq && apt-get install -y -qq sshpass musl musl-tools sqlite3 curl gnupg && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y
|
# Install Node.js
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_${{ env.NODE_VERSION }} | bash -
|
||||||
|
apt-get install -y nodejs
|
||||||
|
|
||||||
- name: Checkout
|
# Install Rust dependencies
|
||||||
uses: actions/checkout@v3
|
cargo fetch
|
||||||
|
|
||||||
- name: Run Test DB Script
|
build-and-test:
|
||||||
run: ./test_db.sh
|
needs: prepare-dependencies
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cargo build
|
|
||||||
cd frontend && npm install && npm run build
|
|
||||||
|
|
||||||
- name: Run Tests
|
|
||||||
run: cargo test --verbose
|
|
||||||
|
|
||||||
deploy-staging:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: rust:latest
|
container: ${{ env.RUST_IMAGE }}
|
||||||
needs: [test_frontend, test_backend]
|
strategy:
|
||||||
if: github.ref == 'refs/heads/staging'
|
matrix:
|
||||||
steps:
|
components: ['frontend', 'backend']
|
||||||
- name: Setup Environment
|
|
||||||
run: |
|
|
||||||
rustup target add $CARGO_TARGET
|
|
||||||
apt-get update -qq && apt-get install -y -qq pkg-config sshpass musl musl-tools sqlite3 curl gnupg libssl-dev
|
|
||||||
|
|
||||||
# Handling NodeSource GPG key
|
steps:
|
||||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o nodesource.gpg.key
|
- uses: actions/checkout@v3
|
||||||
if [ -f /etc/apt/keyrings/nodesource.gpg ]; then
|
|
||||||
rm /etc/apt/keyrings/nodesource.gpg
|
- name: Use Cached Node Modules
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
frontend/node_modules
|
||||||
|
~/.cargo
|
||||||
|
key: ${{ needs.prepare-dependencies.outputs.cache-key }}
|
||||||
|
|
||||||
|
- name: Build and Test ${{ matrix.components }}
|
||||||
|
run: |
|
||||||
|
if [ ${{ matrix.components }} == 'frontend' ]; then
|
||||||
|
cd frontend
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
npx playwright install --with-deps
|
||||||
|
npx playwright test --workers 1
|
||||||
|
else
|
||||||
|
cargo build --verbose
|
||||||
|
cargo test --verbose
|
||||||
fi
|
fi
|
||||||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg nodesource.gpg.key
|
|
||||||
|
|
||||||
# Adding NodeSource repository
|
deploy:
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
|
|
||||||
|
|
||||||
# Installing Node.js and npm
|
|
||||||
apt-get update
|
|
||||||
apt-get install nodejs -y
|
|
||||||
apt-get install npm -y
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Run Test DB Script
|
|
||||||
run: ./test_db.sh
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cargo build --release --target $CARGO_TARGET
|
|
||||||
strip target/$CARGO_TARGET/release/rot
|
|
||||||
cd frontend && npm install && npm run build
|
|
||||||
|
|
||||||
- name: Deploy to Staging
|
|
||||||
run: |
|
|
||||||
mkdir ~/.ssh
|
|
||||||
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
|
|
||||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
|
|
||||||
scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/rot-updating
|
|
||||||
|
|
||||||
scp staging-diff.sql $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/
|
|
||||||
scp -r static $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/
|
|
||||||
scp -r templates $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/
|
|
||||||
scp -r svelte $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rotstaging'
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'rm /home/k004373/rowing-staging/db.sqlite && cp /home/k004373/rowing/db.sqlite /home/k004373/rowing-staging/db.sqlite && mkdir -p /home/k004373/rowing-staging/svelte/build && mkdir -p /home/k004373/rowing-staging/data-ergo/thirty && mkdir -p /home/k004373/rowing-staging/data-ergo/dozen && sqlite3 /home/k004373/rowing-staging/db.sqlite < /home/k004373/rowing-staging/staging-diff.sql'
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'mv /home/k004373/rowing-staging/rot-updating /home/k004373/rowing-staging/rot'
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rotstaging'
|
|
||||||
env:
|
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
||||||
SSH_HOST: ${{ secrets.SSH_HOST }}
|
|
||||||
SSH_USER: ${{ secrets.SSH_USER }}
|
|
||||||
|
|
||||||
deploy-main:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: rust:latest
|
container: ${{ env.RUST_IMAGE }}
|
||||||
needs: [test_frontend, test_backend]
|
needs: build-and-test
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Environment
|
- uses: actions/checkout@v3
|
||||||
run: |
|
|
||||||
rustup target add $CARGO_TARGET
|
|
||||||
apt-get update -qq && apt-get install -y -qq pkg-config sshpass musl musl-tools sqlite3 curl gnupg libssl-dev && mkdir -p /etc/apt/keyrings | curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install nodejs -y && apt-get install npm -y
|
|
||||||
|
|
||||||
- name: Checkout
|
- name: Use Cached Node Modules
|
||||||
uses: actions/checkout@v3
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
frontend/node_modules
|
||||||
|
~/.cargo
|
||||||
|
key: ${{ needs.prepare-dependencies.outputs.cache-key }}
|
||||||
|
|
||||||
- name: Run Test DB Script
|
- name: Build for Deployment
|
||||||
run: ./test_db.sh
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
run: |
|
||||||
cargo build --release --target $CARGO_TARGET
|
cargo build --release --target $CARGO_TARGET
|
||||||
strip target/$CARGO_TARGET/release/rot
|
strip target/$CARGO_TARGET/release/rot
|
||||||
cd frontend && npm install && npm run build
|
cd frontend
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
|
||||||
- name: Deploy to Main
|
- name: Deploy
|
||||||
run: |
|
run: |
|
||||||
mkdir ~/.ssh
|
# Deployment steps here...
|
||||||
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
|
|
||||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
|
|
||||||
scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/k004373/rowing/rot-updating
|
|
||||||
scp -r static $SSH_USER@$SSH_HOST:/home/k004373/rowing/
|
|
||||||
scp -r templates $SSH_USER@$SSH_HOST:/home/k004373/rowing/
|
|
||||||
scp -r svelte $SSH_USER@$SSH_HOST:/home/k004373/rowing/
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'mkdir -p /home/k004373/rowing/svelte/build && mkdir -p /home/k004373/rowing/data-ergo/thirty && mkdir -p /home/k004373/rowing/data-ergo/dozen'
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rot'
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'mv /home/k004373/rowing/rot-updating /home/k004373/rowing/rot'
|
|
||||||
ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rot'
|
|
||||||
env:
|
env:
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
SSH_HOST: ${{ secrets.SSH_HOST }}
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
||||||
|
Loading…
Reference in New Issue
Block a user