ci: automate releases on every push to main #7
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: CI/CD & Auto-Release | |
| on: | |
| push: | |
| branches: [main, master, develop] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [main, master, develop] | |
| workflow_dispatch: | |
| env: | |
| NODE_VERSION: '22' | |
| jobs: | |
| # ============================================================ | |
| # Stage 1: Validation & Code Quality | |
| # ============================================================ | |
| quality: | |
| name: π¬ Quality & Lint | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: π Checkout code | |
| uses: actions/checkout@v4 | |
| - name: π’ Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: π¦ Install dependencies | |
| run: npm ci | |
| - name: β¨ Prettier Format Check | |
| run: npm run format:check | |
| - name: π§Ή Lint Check | |
| run: npm run lint | |
| - name: π‘οΈ TypeScript Type Check | |
| run: npm run type-check | |
| # ============================================================ | |
| # Stage 2: Unit Testing | |
| # ============================================================ | |
| test: | |
| name: π§ͺ Unit Tests | |
| needs: quality | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: π Checkout code | |
| uses: actions/checkout@v4 | |
| - name: π’ Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: π¦ Install dependencies | |
| run: npm ci | |
| - name: π Run Tests | |
| run: npm test | |
| # ============================================================ | |
| # Stage 3: Build & Release (Windows) | |
| # ============================================================ | |
| build-and-release: | |
| name: ποΈ Build & Release EXE | |
| needs: test | |
| runs-on: windows-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: π Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: π’ Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: π¦ Install dependencies | |
| run: npm ci | |
| - name: π¨ Build Standalone EXE | |
| run: npm run build:sea | |
| - name: β¬οΈ Upload Artifact (Summary Page) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: remote-opencode-windows | |
| path: dist/remote-opencode.exe | |
| retention-days: 7 | |
| # ============================================================ | |
| # Release Logic (Automated for Push to Main) | |
| # ============================================================ | |
| - name: π Create/Update Release | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: dist/remote-opencode.exe | |
| # If it's a tag, use tag name. Otherwise, use 'Latest Build' | |
| name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || 'Latest Build (Main)' }} | |
| tag_name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || 'latest' }} | |
| draft: false | |
| prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') }} # Mark rolling builds as pre-release | |
| generate_release_notes: true | |
| make_latest: ${{ startsWith(github.ref, 'refs/tags/v') && 'true' || 'false' }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # ============================================================ | |
| # PR Feedback | |
| # ============================================================ | |
| - name: π Post PR Summary | |
| if: github.event_name == 'pull_request' && always() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const body = `## β CI/CD Pipeline Passed | |
| - π¬ Code Quality: Passed | |
| - π§ͺ Unit Tests: Passed | |
| - ποΈ Build EXE: Standalone Windows binary generated successfully. | |
| This PR is ready to be merged. Once merged to main, a new **Latest Build** release will be automatically created! π`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); |