rowt/.gitea/workflows/action.yml

121 lines
4.4 KiB
YAML
Raw Normal View History

2023-11-18 20:02:23 +01:00
name: CI/CD Pipeline
2024-01-17 19:52:54 +01:00
on: push
2023-11-18 20:02:23 +01:00
env:
2024-02-17 12:48:25 +01:00
CARGO_TARGET: x86_64-unknown-linux-musl
2023-11-18 20:02:23 +01:00
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
jobs:
2024-02-17 12:48:25 +01:00
test:
runs-on: ubuntu-latest
2024-04-19 12:27:06 +02:00
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240419
2024-02-17 12:48:25 +01:00
steps:
- uses: actions/checkout@v3
- name: Run Test DB Script
run: ./test_db.sh
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@v2
2024-02-17 12:48:25 +01:00
- name: Build
run: |
cargo build
cd frontend && npm install && npm run build
- name: Frontend tests
2024-05-12 22:38:25 +02:00
run: cd frontend && npx playwright install && npx playwright test --workers 1 --reporter line
2024-02-17 12:48:25 +01:00
- name: Backend tests
run: cargo test --verbose
#- uses: actions/upload-artifact@v3
# if: always()
# with:
# name: playwright-report
# path: frontend/playwright-report/
# retention-days: 30
deploy-staging:
runs-on: ubuntu-latest
2024-04-19 12:27:06 +02:00
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240419
2024-02-17 12:48:25 +01:00
needs: [test]
if: github.ref == 'refs/heads/staging'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run Test DB Script
run: ./test_db.sh
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@v2
2024-02-17 12:48:25 +01:00
- 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 -p ~/.ssh
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
2024-10-14 14:23:01 +02:00
scp -C target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/rowing-staging/rot-updating
2024-02-17 12:48:25 +01:00
2024-10-14 14:23:01 +02:00
scp -C staging-diff.sql $SSH_USER@$SSH_HOST:/home/rowing-staging/
scp -C -r static $SSH_USER@$SSH_HOST:/home/rowing-staging/
scp -C -r templates $SSH_USER@$SSH_HOST:/home/rowing-staging/
scp -C -r svelte $SSH_USER@$SSH_HOST:/home/rowing-staging/
2024-02-17 12:48:25 +01:00
ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rotstaging'
2024-03-15 09:10:56 +01:00
ssh $SSH_USER@$SSH_HOST 'rm /home/rowing-staging/db.sqlite && cp /home/rowing/db.sqlite /home/rowing-staging/db.sqlite && mkdir -p /home/rowing-staging/svelte/build && mkdir -p /home/rowing-staging/data-ergo/thirty && mkdir -p /home/rowing-staging/data-ergo/dozen && sqlite3 /home/rowing-staging/db.sqlite < /home/rowing-staging/staging-diff.sql'
ssh $SSH_USER@$SSH_HOST 'mv /home/rowing-staging/rot-updating /home/rowing-staging/rot'
2024-02-17 12:48:25 +01:00
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 }}
2023-11-18 20:02:23 +01:00
deploy-main:
runs-on: ubuntu-latest
2024-04-19 12:27:06 +02:00
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240419
2024-02-17 12:48:25 +01:00
needs: [test]
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 20:02:23 +01:00
- name: Checkout
uses: actions/checkout@v3
2024-02-17 12:48:25 +01:00
- name: Run Test DB Script
run: ./test_db.sh
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@v2
2024-02-17 12:48:25 +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
2024-01-17 23:23:58 +01:00
- name: Deploy to production
2023-11-18 20:02:23 +01:00
run: |
2024-01-17 23:23:58 +01:00
mkdir -p ~/.ssh
2023-11-19 22:01:14 +01:00
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
2024-10-14 14:23:01 +02:00
scp -C target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/rowing/rot-updating
scp -C -r static $SSH_USER@$SSH_HOST:/home/rowing/
scp -C -r templates $SSH_USER@$SSH_HOST:/home/rowing/
scp -C -r svelte $SSH_USER@$SSH_HOST:/home/rowing/
2024-03-15 09:10:56 +01:00
ssh $SSH_USER@$SSH_HOST 'mkdir -p /home/rowing/svelte/build && mkdir -p /home/rowing/data-ergo/thirty && mkdir -p /home/rowing/data-ergo/dozen'
2024-02-17 12:48:25 +01:00
ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rot'
2024-03-15 09:10:56 +01:00
ssh $SSH_USER@$SSH_HOST 'mv /home/rowing/rot-updating /home/rowing/rot'
2024-02-17 12:48:25 +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 }}