forked from Ruderverein-Donau-Linz/rowt
		
	push
This commit is contained in:
		| @@ -3,18 +3,127 @@ name: CI/CD Pipeline | |||||||
| on: push | on: push | ||||||
|  |  | ||||||
| env: | env: | ||||||
|  |   CARGO_TARGET: x86_64-unknown-linux-musl | ||||||
|   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 }} | ||||||
|  |  | ||||||
| jobs: | jobs: | ||||||
|  |   test: | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  |     container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215 | ||||||
|  |     steps: | ||||||
|  |     - uses: actions/checkout@v3 | ||||||
|  |     - name: Run Test DB Script | ||||||
|  |       run: ./test_db.sh | ||||||
|  |  | ||||||
|  |     - name: Set up cargo cache | ||||||
|  |       uses: actions/cache@v3 | ||||||
|  |       with: | ||||||
|  |         path: | | ||||||
|  |           ~/.cargo/bin/ | ||||||
|  |           ~/.cargo/registry/index/ | ||||||
|  |           ~/.cargo/registry/cache/ | ||||||
|  |           ~/.cargo/git/db/ | ||||||
|  |           target/ | ||||||
|  |         key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.lock') }} | ||||||
|  |         restore-keys: ${{ runner.os }}-cargo-debug- | ||||||
|  |  | ||||||
|  |     - name: Build | ||||||
|  |       run: | | ||||||
|  |         cargo build  | ||||||
|  |         cd frontend && npm install && npm run build | ||||||
|  |     - name: Frontend tests | ||||||
|  |       run: cd frontend && npx playwright test --workers 1 | ||||||
|  |     - 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 | ||||||
|  |     container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215 | ||||||
|  |     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: Set up cargo cache | ||||||
|  |         uses: actions/cache@v3 | ||||||
|  |         with: | ||||||
|  |           path: | | ||||||
|  |             ~/.cargo/bin/ | ||||||
|  |             ~/.cargo/registry/index/ | ||||||
|  |             ~/.cargo/registry/cache/ | ||||||
|  |             ~/.cargo/git/db/ | ||||||
|  |             target/ | ||||||
|  |           key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} | ||||||
|  |           restore-keys: ${{ runner.os }}-cargo-release- | ||||||
|  |       - 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 | ||||||
|  |  | ||||||
|  |           scp target/$CARGO_TARGET/release/rot $SSH_USER@$SSH_HOST:/home/philipp/rowing-staging/rot-updating | ||||||
|  |      | ||||||
|  |           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/ | ||||||
|  |           ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rotstaging' | ||||||
|  |           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' | ||||||
|  |           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: |   deploy-main: | ||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240118 |     container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215 | ||||||
|  |     needs: [test] | ||||||
|     if: github.ref == 'refs/heads/main' |     if: github.ref == 'refs/heads/main' | ||||||
|     steps: |     steps: | ||||||
|       - name: Checkout |       - name: Checkout | ||||||
|         uses: actions/checkout@v3 |         uses: actions/checkout@v3 | ||||||
|  |        | ||||||
|  |       - name: Run Test DB Script | ||||||
|  |         run: ./test_db.sh | ||||||
|  |        | ||||||
|  |       - name: Set up cargo cache | ||||||
|  |         uses: actions/cache@v3 | ||||||
|  |         with: | ||||||
|  |           path: | | ||||||
|  |             ~/.cargo/bin/ | ||||||
|  |             ~/.cargo/registry/index/ | ||||||
|  |             ~/.cargo/registry/cache/ | ||||||
|  |             ~/.cargo/git/db/ | ||||||
|  |             target/ | ||||||
|  |           key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} | ||||||
|  |           restore-keys: ${{ runner.os }}-cargo-release- | ||||||
|  |  | ||||||
|  |       - 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 production  |       - name: Deploy to production  | ||||||
|         run: | |         run: | | ||||||
| @@ -23,7 +132,14 @@ jobs: | |||||||
|           echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa |           echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | ||||||
|           chmod 600 ~/.ssh/id_rsa |           chmod 600 ~/.ssh/id_rsa | ||||||
|  |  | ||||||
|           scp ./output/* $SSH_USER@$SSH_HOST:/var/www/html/ris/ |           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' | ||||||
|  |           ssh $SSH_USER@$SSH_HOST 'sudo systemctl stop rot' | ||||||
|  |           ssh $SSH_USER@$SSH_HOST 'mv  /home/philipp/rowing/rot-updating /home/philipp/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 }} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user