rowt/.gitea/workflows/action.yml

165 lines
7.2 KiB
YAML
Raw Normal View History

2023-11-18 20:02:23 +01:00
name: CI/CD Pipeline
2023-11-19 10:14:44 +01:00
on: push
2023-11-18 20:02:23 +01:00
env:
CARGO_TARGET: x86_64-unknown-linux-musl
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
2024-01-17 08:23:46 +01:00
CARGO_INCREMENTAL: 0
2023-11-18 20:02:23 +01:00
jobs:
2024-01-16 16:00:02 +01:00
test-frontend:
runs-on: ubuntu-latest
2024-01-16 16:10:13 +01:00
container: rust:latest
2024-01-16 16:00:02 +01:00
steps:
2024-01-16 16:09:09 +01:00
- name: Setup Environment
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
2024-01-16 16:09:45 +01:00
- uses: actions/checkout@v3
2024-01-16 16:55:47 +01:00
- name: Run Test DB Script
run: ./test_db.sh
2024-01-16 16:42:57 +01:00
- name: Build
2024-01-16 20:04:34 +01:00
run: |
2024-01-16 16:42:57 +01:00
cargo build
cd frontend && npm install && npm run build
2024-01-16 16:00:02 +01:00
- name: Install dependencies
2024-01-16 16:16:56 +01:00
run: cd frontend && npm install
2024-01-16 16:00:02 +01:00
- name: Install Playwright Browsers
2024-01-16 16:13:41 +01:00
run: cd frontend && npx playwright install --with-deps
2024-01-16 16:00:02 +01:00
- name: Run Playwright tests
2024-01-16 22:29:57 +01:00
run: cd frontend && npx playwright test --workers 1
2024-01-17 08:23:46 +01:00
#- uses: actions/upload-artifact@v3
# if: always()
# with:
# name: playwright-report
# path: frontend/playwright-report/
# retention-days: 30
2024-01-16 16:00:02 +01:00
test-backend:
2023-11-18 20:02:23 +01:00
runs-on: ubuntu-latest
2023-11-18 21:57:57 +01:00
container: rust:latest
2023-11-18 20:02:23 +01:00
steps:
2023-11-18 21:57:57 +01:00
- name: Setup Environment
2023-11-18 21:56:25 +01:00
run: |
2023-11-18 21:57:57 +01:00
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
2023-11-18 21:56:25 +01:00
2023-11-18 20:02:23 +01:00
- name: Checkout
uses: actions/checkout@v3
- name: Run Test DB Script
run: ./test_db.sh
- name: Build
run: |
2023-11-18 22:22:36 +01:00
cargo build
2023-11-18 20:02:23 +01:00
cd frontend && npm install && npm run build
- name: Run Tests
run: cargo test --verbose
deploy-staging:
runs-on: ubuntu-latest
2023-11-18 22:35:25 +01:00
container: rust:latest
2024-01-16 16:00:02 +01:00
needs: [test_frontend, test_backend]
2023-11-18 20:02:23 +01:00
if: github.ref == 'refs/heads/staging'
2023-11-18 21:46:00 +01:00
steps:
2023-11-18 21:57:57 +01:00
- name: Setup Environment
run: |
2023-11-19 09:04:51 +01:00
rustup target add $CARGO_TARGET
2024-01-01 17:53:00 +01:00
apt-get update -qq && apt-get install -y -qq pkg-config sshpass musl musl-tools sqlite3 curl gnupg libssl-dev
2023-11-19 18:56:29 +01:00
# Handling NodeSource GPG key
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o nodesource.gpg.key
if [ -f /etc/apt/keyrings/nodesource.gpg ]; then
rm /etc/apt/keyrings/nodesource.gpg
fi
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg nodesource.gpg.key
# Adding NodeSource repository
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
2023-11-18 21:57:57 +01:00
2023-11-18 20:02:23 +01:00
- name: Checkout
uses: actions/checkout@v3
2023-11-18 21:57:57 +01:00
2023-11-19 09:47:08 +01:00
- name: Run Test DB Script
run: ./test_db.sh
2023-11-18 22:22:36 +01:00
- name: Build
run: |
cargo build --release --target $CARGO_TARGET
strip target/$CARGO_TARGET/release/rot
cd frontend && npm install && npm run build
2023-11-18 20:02:23 +01:00
- name: Deploy to Staging
run: |
2023-11-19 20:14:08 +01:00
mkdir ~/.ssh
2023-11-19 18:03:14 +01:00
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
2023-11-19 21:13:50 +01:00
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
2023-11-18 20:02:23 +01:00
scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/k004373/rowing-staging/rot-updating
2023-11-19 18:03:14 +01:00
2023-11-18 20:02:23 +01:00
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'
2023-11-18 21:57:57 +01:00
ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rotstaging'
2023-11-18 20:02:23 +01:00
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
deploy-main:
runs-on: ubuntu-latest
2023-11-18 22:35:25 +01:00
container: rust:latest
2024-01-16 16:00:02 +01:00
needs: [test_frontend, test_backend]
2023-11-18 20:02:23 +01:00
if: github.ref == 'refs/heads/main'
2023-11-18 21:46:00 +01:00
steps:
2023-11-18 21:57:57 +01:00
- name: Setup Environment
run: |
2023-11-19 09:04:51 +01:00
rustup target add $CARGO_TARGET
2024-01-01 17:53:00 +01:00
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
2023-11-18 21:57:57 +01:00
2023-11-18 20:02:23 +01:00
- name: Checkout
uses: actions/checkout@v3
2023-11-18 21:57:57 +01:00
2023-11-19 09:47:08 +01:00
- name: Run Test DB Script
run: ./test_db.sh
2023-11-18 22:22:36 +01:00
- name: Build
run: |
cargo build --release --target $CARGO_TARGET
strip target/$CARGO_TARGET/release/rot
cd frontend && npm install && npm run build
2023-11-18 20:02:23 +01:00
- name: Deploy to Main
run: |
2023-11-19 22:01:14 +01:00
mkdir ~/.ssh
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
2023-11-18 20:02:23 +01:00
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'
2023-11-18 21:57:57 +01:00
ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rot'
2023-11-18 20:02:23 +01:00
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}