feat: improve command context and answer lookup #160
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 | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - 'docs/**' | |
| - 'README.md' | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: deploy-main | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Lint | |
| run: npm run lint | |
| - name: Typecheck | |
| run: npm run typecheck | |
| - name: Test | |
| run: npm test | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Compute image name | |
| id: image | |
| run: echo "name=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/telegram-group-command-bot" >> "$GITHUB_OUTPUT" | |
| - name: Load SSH key | |
| uses: webfactory/ssh-agent@v0.9.0 | |
| with: | |
| ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }} | |
| - name: Trust deploy host | |
| run: | | |
| mkdir -p ~/.ssh | |
| ssh-keyscan -p "${{ secrets.DEPLOY_PORT }}" "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts | |
| - name: Read deployed metadata | |
| id: deployed | |
| run: | | |
| mkdir -p deploy/generated | |
| if ssh -p "${{ secrets.DEPLOY_PORT }}" "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \ | |
| "test -f '${{ secrets.DEPLOY_PATH }}/data/deploy-metadata.json'"; then | |
| scp -P "${{ secrets.DEPLOY_PORT }}" \ | |
| "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/data/deploy-metadata.json" \ | |
| deploy/generated/deployed-metadata.json | |
| sha="$(node -e "const fs = require('node:fs'); try { const metadata = JSON.parse(fs.readFileSync('deploy/generated/deployed-metadata.json', 'utf8')); if (typeof metadata.sha === 'string' && metadata.sha !== 'unknown') process.stdout.write(metadata.sha); } catch {}")" | |
| echo "sha=${sha}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "sha=" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Generate deploy metadata | |
| run: npm run deploy:metadata | |
| env: | |
| DEPLOY_METADATA_DEPLOYED_SHA: ${{ steps.deployed.outputs.sha }} | |
| DEPLOY_METADATA_BEFORE_SHA: ${{ github.event.before || '' }} | |
| DEPLOY_METADATA_SHA: ${{ github.sha }} | |
| DEPLOY_METADATA_BRANCH: ${{ github.ref_name }} | |
| DEPLOY_METADATA_OUTPUT: deploy/generated/deploy-metadata.json | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=min | |
| tags: | | |
| ${{ steps.image.outputs.name }}:latest | |
| ${{ steps.image.outputs.name }}:${{ github.sha }} | |
| - name: Upload deploy assets | |
| run: | | |
| ssh -p "${{ secrets.DEPLOY_PORT }}" "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \ | |
| "mkdir -p '${{ secrets.DEPLOY_PATH }}/data'" | |
| scp -P "${{ secrets.DEPLOY_PORT }}" \ | |
| deploy/compose.yml \ | |
| deploy/remote-deploy.sh \ | |
| "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/" | |
| scp -P "${{ secrets.DEPLOY_PORT }}" \ | |
| deploy/generated/deploy-metadata.json \ | |
| "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/data/deploy-metadata.json" | |
| - name: Deploy to server | |
| run: | | |
| ssh -p "${{ secrets.DEPLOY_PORT }}" "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \ | |
| "chmod +x '${{ secrets.DEPLOY_PATH }}/remote-deploy.sh' && \ | |
| DEPLOY_PATH='${{ secrets.DEPLOY_PATH }}' \ | |
| IMAGE_TAG='${{ github.sha }}' \ | |
| SERVER_GHCR_USERNAME='${{ secrets.SERVER_GHCR_USERNAME }}' \ | |
| SERVER_GHCR_TOKEN='${{ secrets.SERVER_GHCR_TOKEN }}' \ | |
| bash '${{ secrets.DEPLOY_PATH }}/remote-deploy.sh'" |