Skip to content

Commit 1fd0992

Browse files
author
Maxim Titovich
committed
Add GitHub Actions for CI/CD automation
1 parent bccddb4 commit 1fd0992

File tree

6 files changed

+214
-1
lines changed

6 files changed

+214
-1
lines changed

.github/workflows/ci.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main", "develop" ]
6+
pull_request:
7+
branches: [ "main", "develop" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [16.x, 18.x, 20.x]
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run linting and formatting checks
29+
run: npm run check
30+
31+
- name: Run security check
32+
run: npm run security-check
33+
34+
- name: Build
35+
run: npm run build
36+
37+
# We can't run test-connection here since it requires Azure DevOps credentials
38+
# Instead, we can make sure the build doesn't have errors
39+
- name: Verify build artifacts
40+
run: |
41+
if [ ! -f "./build/index.js" ]; then
42+
echo "Build failed - index.js not found"
43+
exit 1
44+
fi
45+
if [ ! -f "./build/sse-server.js" ]; then
46+
echo "Build failed - sse-server.js not found"
47+
exit 1
48+
fi

.github/workflows/publish.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
# Only trigger when package.json changes or when a release tag is created
7+
paths:
8+
- 'package.json'
9+
- 'src/**'
10+
- 'build/**'
11+
release:
12+
types: [created]
13+
14+
jobs:
15+
publish:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Use Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: '20.x'
24+
cache: 'npm'
25+
registry-url: 'https://registry.npmjs.org'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Run checks
31+
run: npm run check
32+
33+
- name: Run security check
34+
run: npm run security-check
35+
36+
- name: Build
37+
run: npm run build
38+
39+
# This only runs on main branch pushes that have modified package.json or are from a release event
40+
- name: Extract version from package.json
41+
id: extract_version
42+
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
43+
44+
- name: Check if version exists
45+
id: version_check
46+
run: |
47+
if npm view cursor-azure-devops-mcp@${{ steps.extract_version.outputs.version }} version &> /dev/null; then
48+
echo "exists=true" >> $GITHUB_OUTPUT
49+
echo "Version ${{ steps.extract_version.outputs.version }} already exists on npm"
50+
else
51+
echo "exists=false" >> $GITHUB_OUTPUT
52+
echo "Version ${{ steps.extract_version.outputs.version }} doesn't exist yet"
53+
fi
54+
continue-on-error: true
55+
56+
- name: Publish to npm
57+
if: steps.version_check.outputs.exists != 'true'
58+
run: npm publish
59+
env:
60+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/version-bump.yml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Version Bump
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump_type:
7+
description: 'Version bump type (patch, minor, major)'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
jobs:
17+
bump-version:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Setup Git
27+
run: |
28+
git config user.name "GitHub Actions Bot"
29+
git config user.email "[email protected]"
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v3
33+
with:
34+
node-version: '20.x'
35+
36+
- name: Install dependencies
37+
run: npm ci
38+
39+
- name: Run checks
40+
run: npm run check
41+
42+
- name: Run security check
43+
run: npm run security-check
44+
45+
- name: Bump version
46+
run: npm version ${{ github.event.inputs.bump_type }} -m "Bump version to %s [skip ci]"
47+
48+
- name: Get version from package.json
49+
id: package-version
50+
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
51+
52+
- name: Push changes
53+
run: |
54+
git push
55+
git push --tags
56+
57+
- name: Create GitHub Release
58+
uses: softprops/action-gh-release@v1
59+
with:
60+
tag_name: v${{ steps.package-version.outputs.version }}
61+
name: Release v${{ steps.package-version.outputs.version }}
62+
generate_release_notes: true
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ backup/
1414
logs/
1515
*.swp
1616
.DS_Store
17+
# Don't ignore GitHub workflows
18+
!.github/
19+
!.github/workflows/
1720

1821
# Environment and secrets
1922
.env

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,40 @@ npm run build
310310
npm publish
311311
```
312312

313+
## Continuous Integration and Deployment
314+
315+
This project uses GitHub Actions for automated builds, testing, and publishing.
316+
317+
### CI Workflow
318+
319+
The CI workflow runs on every push to the main and develop branches, as well as on pull requests:
320+
321+
- Builds the project with Node.js 16.x, 18.x, and 20.x
322+
- Runs linting and formatting checks
323+
- Performs security checks to prevent sensitive data exposure
324+
- Ensures the build completes successfully
325+
326+
You can see the workflow details in `.github/workflows/ci.yml`.
327+
328+
### CD Workflow (Publishing)
329+
330+
The publishing workflow runs when:
331+
- A change is pushed to the main branch that modifies `package.json` or source code
332+
- A new GitHub release is created
333+
334+
It performs the following steps:
335+
1. Runs all checks and builds the package
336+
2. Extracts the package version from package.json
337+
3. Checks if that version already exists on npm
338+
4. If the version is new, publishes the package to npm
339+
340+
To use this workflow, you need to:
341+
1. Add an `NPM_TOKEN` secret to your GitHub repository settings
342+
2. Increase the version number in package.json when ready to publish
343+
3. Push to the main branch or create a new GitHub release
344+
345+
You can see the workflow details in `.github/workflows/publish.yml`.
346+
313347
## Troubleshooting
314348

315349
### Summary of Common Issues and Solutions

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
"lint:fix": "eslint . --ext .ts --fix",
2626
"format": "prettier --write \"src/**/*.ts\"",
2727
"format:check": "prettier --check \"src/**/*.ts\"",
28-
"check": "npm run format:check && npm run lint"
28+
"check": "npm run format:check && npm run lint",
29+
"version:patch": "npm version patch",
30+
"version:minor": "npm version minor",
31+
"version:major": "npm version major",
32+
"release": "npm run version:patch && git push && git push --tags"
2933
},
3034
"keywords": [
3135
"cursor",

0 commit comments

Comments
 (0)