forked from RoundTable02/remote-opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (152 loc) Β· 6 KB
/
ci-cd.yml
File metadata and controls
178 lines (152 loc) Β· 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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: π·οΈ Get Version and Extract Changelog
id: get_release_info
shell: bash
run: |
# Use node to safely read version from package.json regardless of module type
VERSION=$(node -e "import fs from 'fs'; console.log(JSON.parse(fs.readFileSync('./package.json')).version)" --input-type=module)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
# Extract the section from CHANGELOG.md for the current version
# Using .cjs extension to force CommonJS mode for the extraction script
cat << 'EOF' > extract_changelog.cjs
const fs = require('fs');
const content = fs.readFileSync('CHANGELOG.md', 'utf8');
const version = process.argv[2];
const regex = new RegExp(`## \\[${version.replace(/\./g, '\\.')}\\][\\s\\S]*?(?=## \\[|$)`);
const match = content.match(regex);
if (match) {
let notes = match[0].trim();
// Remove the version header itself from the body
notes = notes.replace(/^## \[.*\] - .*\n/, '').trim();
fs.writeFileSync('release_notes.md', notes);
console.log('Changelog extracted successfully');
} else {
fs.writeFileSync('release_notes.md', 'New version release.');
console.log('Version section not found in CHANGELOG.md');
}
EOF
node extract_changelog.cjs $VERSION
- 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
# Dynamic name using the version from package.json
name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || format('Release v{0}', steps.get_release_info.outputs.VERSION) }}
# Use the tag from git if available, otherwise fallback to 'latest'
tag_name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || 'latest' }}
body_path: release_notes.md
draft: false
prerelease: false
append_body: true # Append the "Full Changelog" link below our extracted notes
generate_release_notes: true # This will append the contributor list and link below our custom body
make_latest: true
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 **Main Release** will be automatically created with notes from CHANGELOG.md! π`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});