feat: use TokenBucket algo to apply rate limiting #83
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy CMS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| name: Run tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Run tests | |
| run: go test ./test/... -v -count=1 | |
| build: | |
| name: Build check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Build backend | |
| run: go build ./... | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| cache-dependency-path: app/package-lock.json | |
| - name: Install frontend dependencies | |
| working-directory: app | |
| run: npm ci | |
| - name: Build frontend | |
| working-directory: app | |
| run: npm run build | |
| deploy-backend: | |
| name: Deploy backend | |
| needs: [test, build] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check backend changes | |
| id: changes | |
| run: | | |
| if git diff --name-only HEAD^ HEAD | grep -qv '^app/'; then | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Deploy backend | |
| if: steps.changes.outputs.changed == 'true' | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| port: 22 | |
| script: | | |
| set -e | |
| export PATH="/usr/local/go/bin:$PATH" | |
| echo "Go version:" | |
| go version | |
| cd /home/serv-admin/Documents/projects/cms-web | |
| echo "Pulling latest code..." | |
| git pull --ff-only origin main | |
| echo "Building backend..." | |
| go build -o cms-web.new . | |
| echo "Installing backend..." | |
| mv cms-web.new cms-web | |
| echo "Restarting CMS..." | |
| sudo -n /usr/bin/systemctl restart cms | |
| echo "Checking CMS..." | |
| sudo -n /usr/bin/systemctl is-active --quiet cms | |
| echo "Backend deployed successfully." | |
| deploy-frontend: | |
| name: Deploy frontend | |
| needs: [test, build] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check frontend changes | |
| id: changes | |
| run: | | |
| if git diff --name-only HEAD^ HEAD | grep -q '^app/'; then | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Deploy frontend | |
| if: steps.changes.outputs.changed == 'true' | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| port: 22 | |
| script: | | |
| set -e | |
| export PATH="/home/serv-admin/.nvm/versions/node/v24.19.0/bin:$PATH" | |
| echo "Node version:" | |
| node --version | |
| echo "npm version:" | |
| npm --version | |
| cd /home/serv-admin/Documents/projects/cms-web | |
| echo "Pulling latest code..." | |
| git pull --ff-only origin main | |
| cd app | |
| echo "Installing frontend dependencies..." | |
| npm ci | |
| echo "Building frontend..." | |
| npm run build | |
| echo "Deploying frontend..." | |
| sudo -n /usr/bin/rm -rf /var/www/cms/* | |
| sudo -n /usr/bin/cp -a dist/. /var/www/cms/ | |
| echo "Testing Nginx..." | |
| sudo -n /usr/sbin/nginx -t | |
| echo "Reloading Nginx..." | |
| sudo -n /usr/bin/systemctl reload nginx | |
| echo "Frontend deployed successfully." | |