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:
|
|
|
|
CARGO_TARGET: x86_64-unknown-linux-musl
|
|
|
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
|
|
|
SSH_USER: ${{ secrets.SSH_USER }}
|
|
|
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
|
|
|
|
|
|
jobs:
|
2024-01-17 22:56:33 +01:00
|
|
|
test:
|
2024-01-16 16:00:02 +01:00
|
|
|
runs-on: ubuntu-latest
|
2024-02-15 12:01:28 +01:00
|
|
|
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215
|
2024-01-16 16:00:02 +01:00
|
|
|
steps:
|
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-17 19:52:54 +01:00
|
|
|
|
2024-01-17 22:56:33 +01:00
|
|
|
- name: Set up cargo cache
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: |
|
|
|
|
~/.cargo/bin/
|
|
|
|
~/.cargo/registry/index/
|
|
|
|
~/.cargo/registry/cache/
|
|
|
|
~/.cargo/git/db/
|
2024-01-17 19:52:54 +01:00
|
|
|
target/
|
2024-01-17 23:08:28 +01:00
|
|
|
key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.lock') }}
|
2024-01-17 23:34:39 +01:00
|
|
|
restore-keys: ${{ runner.os }}-cargo-debug-
|
2024-01-17 19:52:54 +01:00
|
|
|
|
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-17 22:56:33 +01:00
|
|
|
- name: Frontend tests
|
2024-01-16 22:29:57 +01:00
|
|
|
run: cd frontend && npx playwright test --workers 1
|
2024-01-17 22:56:33 +01:00
|
|
|
- name: Backend tests
|
|
|
|
run: cargo test --verbose
|
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
|
|
|
|
2023-11-18 20:02:23 +01:00
|
|
|
deploy-staging:
|
|
|
|
runs-on: ubuntu-latest
|
2024-02-15 12:01:28 +01:00
|
|
|
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215
|
2024-01-17 22:56:33 +01:00
|
|
|
needs: [test]
|
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 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
|
|
|
|
|
2024-01-17 22:56:33 +01:00
|
|
|
- name: Set up cargo cache
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: |
|
|
|
|
~/.cargo/bin/
|
|
|
|
~/.cargo/registry/index/
|
|
|
|
~/.cargo/registry/cache/
|
|
|
|
~/.cargo/git/db/
|
2024-01-17 23:34:39 +01:00
|
|
|
target/
|
|
|
|
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
|
|
|
|
restore-keys: ${{ runner.os }}-cargo-release-
|
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: |
|
2024-01-17 23:23:58 +01:00
|
|
|
mkdir -p ~/.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
|
|
|
|
|
2024-02-06 16:01:34 +01:00
|
|
|
scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/rot-updating
|
2023-11-19 18:03:14 +01:00
|
|
|
|
2024-02-06 16:01:34 +01:00
|
|
|
scp staging-diff.sql $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/
|
|
|
|
scp -r static $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/
|
|
|
|
scp -r templates $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/
|
|
|
|
scp -r svelte $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/
|
2024-02-06 16:12:10 +01:00
|
|
|
ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rotstaging'
|
2024-02-06 16:01:34 +01:00
|
|
|
ssh $SSH_USER@$SSH_HOST 'rm /home/philipp/rowing-staging/db.sqlite && cp /home/philipp/rowing/db.sqlite /home/philipp/rowing-staging/db.sqlite && mkdir -p /home/philipp/rowing-staging/svelte/build && mkdir -p /home/philipp/rowing-staging/data-ergo/thirty && mkdir -p /home/philipp/rowing-staging/data-ergo/dozen && sqlite3 /home/philipp/rowing-staging/db.sqlite < /home/philipp/rowing-staging/staging-diff.sql'
|
|
|
|
ssh $SSH_USER@$SSH_HOST 'mv /home/philipp/rowing-staging/rot-updating /home/philipp/rowing-staging/rot'
|
2024-02-06 16:12:10 +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
|
2024-02-15 12:01:28 +01:00
|
|
|
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215
|
2024-01-17 22:56:33 +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
|
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
|
2024-01-17 22:56:33 +01:00
|
|
|
|
|
|
|
- name: Set up cargo cache
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: |
|
|
|
|
~/.cargo/bin/
|
|
|
|
~/.cargo/registry/index/
|
|
|
|
~/.cargo/registry/cache/
|
|
|
|
~/.cargo/git/db/
|
|
|
|
target/
|
2024-01-17 23:08:28 +01:00
|
|
|
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
|
2024-01-17 23:34:39 +01:00
|
|
|
restore-keys: ${{ runner.os }}-cargo-release-
|
2023-11-19 09:47:08 +01:00
|
|
|
|
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
|
|
|
|
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-02-06 16:01:34 +01:00
|
|
|
scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/philipp/rowing/rot-updating
|
|
|
|
scp -r static $SSH_USER@$SSH_HOST:/home/philipp/rowing/
|
|
|
|
scp -r templates $SSH_USER@$SSH_HOST:/home/philipp/rowing/
|
|
|
|
scp -r svelte $SSH_USER@$SSH_HOST:/home/philipp/rowing/
|
|
|
|
ssh $SSH_USER@$SSH_HOST 'mkdir -p /home/philipp/rowing/svelte/build && mkdir -p /home/philipp/rowing/data-ergo/thirty && mkdir -p /home/philipp/rowing/data-ergo/dozen'
|
2024-02-06 16:12:10 +01:00
|
|
|
ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rot'
|
2024-02-06 16:01:34 +01:00
|
|
|
ssh $SSH_USER@$SSH_HOST 'mv /home/philipp/rowing/rot-updating /home/philipp/rowing/rot'
|
2024-02-06 16:12:10 +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 }}
|