This repository was archived by the owner on May 12, 2026. It is now read-only.
Fix roles not being mentioned on logs (#98) #60
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: Release | |
| on: | |
| push: | |
| branches: | |
| - master | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| outputs: | |
| published: ${{ steps.changesets.outputs.published }} | |
| publishedPackages: ${{ steps.changesets.outputs.publishedPackages }} | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.16.0 | |
| cache: 'pnpm' | |
| - name: Install Dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Create Release Pull Request or Publish | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| version: npx changeset version | |
| publish: pnpm run release | |
| commit: "chore: release versions" | |
| title: "chore: release versions" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
| deploy: | |
| name: Deploy to VPS | |
| runs-on: ubuntu-latest | |
| needs: [release] | |
| if: needs.release.outputs.published == 'true' | |
| steps: | |
| - name: Check if khaxyrewrite was published | |
| id: check | |
| run: | | |
| PACKAGES='${{ needs.release.outputs.publishedPackages }}' | |
| echo "Published packages: $PACKAGES" | |
| if [ -z "$PACKAGES" ] || [ "$PACKAGES" = "false" ]; then | |
| echo "should_deploy=false" >> $GITHUB_OUTPUT | |
| echo "No packages were published" | |
| elif echo "$PACKAGES" | jq -e '.[] | select(.name == "khaxyrewrite")' > /dev/null 2>&1; then | |
| echo "should_deploy=true" >> $GITHUB_OUTPUT | |
| echo "khaxyrewrite was published, will deploy" | |
| else | |
| echo "should_deploy=false" >> $GITHUB_OUTPUT | |
| echo "khaxyrewrite was not in the published packages" | |
| fi | |
| - name: SSH and Deploy | |
| if: steps.check.outputs.should_deploy == 'true' | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.VPS_IP }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| script: | | |
| set -e | |
| cd ~/Khaxy | |
| # 1. Update local tags from GitHub | |
| git fetch --all --tags | |
| # 2. Get the most recent tag created by Changesets | |
| LATEST_TAG=$(git tag -l "khaxyrewrite@*" --sort=-v:refname | head -n1) | |
| if [ -z "$LATEST_TAG" ]; then | |
| echo "❌ No khaxyrewrite tag found!" | |
| exit 1 | |
| fi | |
| echo "🚀 Deploying release: $LATEST_TAG" | |
| git checkout --force $LATEST_TAG | |
| # 3. Docker Zero-Downtime Update | |
| echo "🏗️ Building and deploying with Docker..." | |
| docker-compose build | |
| docker-compose up -d | |
| # 4. Cleanup | |
| echo "🧹 Cleaning up old images..." | |
| docker image prune -f | |
| echo "✅ Deployment Complete!" |