diff --git a/.gitea/workflows/action.yml b/.gitea/workflows/action.yml index 90def89..2ebb599 100644 --- a/.gitea/workflows/action.yml +++ b/.gitea/workflows/action.yml @@ -13,19 +13,32 @@ env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} jobs: + setup-environment: + runs-on: ubuntu-latest + outputs: + cache-key: ${{ steps.cache-keys.outputs.cache-key }} + steps: + - name: Calculate Cache Keys + id: cache-keys + run: echo "::set-output name=cache-key::$(date +%s)" + build: runs-on: ubuntu-latest - container: rust:latest + needs: setup-environment + container: my-custom-container:latest steps: - - name: Setup Environment - run: | - rustup target add $CARGO_TARGET - 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 - - name: Checkout uses: actions/checkout@v3 + - name: Restore Cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo + ./frontend/node_modules + key: ${{ needs.setup-environment.outputs.cache-key }} + - name: Run Test DB Script run: ./test_db.sh @@ -46,39 +59,31 @@ jobs: test: runs-on: ubuntu-latest - container: rust:latest + needs: build + container: my-custom-container:latest steps: - - 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 - - name: Checkout uses: actions/checkout@v3 - - name: Run Test DB Script - run: ./test_db.sh - - - name: Download Artifacts - uses: actions/download-artifact@v3 + - name: Restore Cache + uses: actions/cache@v3 with: - name: build-artifacts + path: ~/.cargo + key: ${{ needs.setup-environment.outputs.cache-key }} - name: Run Tests run: cargo test --verbose deploy-staging: runs-on: ubuntu-latest - needs: [build, test] + needs: test if: github.ref == 'refs/heads/staging' - steps: - - 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 + steps: - name: Checkout uses: actions/checkout@v3 - + - name: Download Artifacts uses: actions/download-artifact@v3 with: @@ -94,7 +99,7 @@ jobs: 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' + ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rotstaging' env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SSH_HOST: ${{ secrets.SSH_HOST }} @@ -102,13 +107,10 @@ jobs: deploy-main: runs-on: ubuntu-latest - needs: [build, test] + needs: test if: github.ref == 'refs/heads/main' - steps: - - 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 + steps: - name: Checkout uses: actions/checkout@v3 @@ -126,7 +128,7 @@ jobs: 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' + ssh $SSH_USER@$SSH_HOST 'sudo systemctl start rot' env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SSH_HOST: ${{ secrets.SSH_HOST }}