Skip to content

Commit 0ed960e

Browse files
committed
improve CI/CD script
1 parent 1f7d55d commit 0ed960e

14 files changed

+1499
-73
lines changed

.github/workflows/ci.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
schedule:
7+
- cron: '0 0 * * 0' # Run weekly on Sundays at midnight
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: 16
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Lint
26+
run: npm run lint
27+
28+
- name: Build
29+
run: npm run webpack-prod
30+
31+
- name: Test
32+
run: npm test
33+
34+
- name: Create Package
35+
run: npm run package
36+
37+
- name: Upload Artifact
38+
uses: actions/upload-artifact@v3
39+
with:
40+
name: vsix-package
41+
path: "*.vsix"
42+
retention-days: 7

.github/workflows/pr-validation.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Pull Request Validation
2+
3+
on:
4+
pull_request:
5+
branches: [ main, master, develop ]
6+
7+
jobs:
8+
validate:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: 16
18+
cache: 'npm'
19+
20+
- name: Install dependencies
21+
run: npm ci
22+
23+
- name: Lint
24+
run: npm run lint
25+
26+
- name: Build
27+
run: npm run webpack-prod
28+
29+
- name: Test
30+
run: npm test
31+
32+
# Optional: Add code coverage reporting
33+
# - name: Generate Coverage Report
34+
# run: npm run test:coverage
35+
36+
# - name: Upload Coverage Report
37+
# uses: codecov/codecov-action@v3
38+
# with:
39+
# token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/release.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release Extension
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_bump:
7+
description: 'Version bump type'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
# Define a job environment variable to check for the presence of the secret
20+
env:
21+
HAS_VSCE_PAT: ${{ secrets.VSCE_PAT != '' }}
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 0 # We need git history for changelog
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: 16
32+
cache: 'npm'
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Configure Git
38+
run: |
39+
git config --local user.email "[email protected]"
40+
git config --local user.name "GitHub Actions"
41+
42+
- name: Run release script
43+
run: |
44+
node ./scripts/release.js ${{ github.event.inputs.version_bump }}
45+
46+
- name: Extract version
47+
id: extract_version
48+
run: |
49+
VERSION=$(node -p "require('./package.json').version")
50+
echo "version=$VERSION" >> $GITHUB_OUTPUT
51+
echo "package_name=Markdown-Arweave-Uploader-$VERSION.vsix" >> $GITHUB_OUTPUT
52+
53+
- name: Push changes
54+
run: |
55+
git push
56+
git push --tags
57+
58+
- name: Create GitHub Release
59+
uses: softprops/action-gh-release@v1
60+
with:
61+
tag_name: v${{ steps.extract_version.outputs.version }}
62+
name: Release v${{ steps.extract_version.outputs.version }}
63+
body_path: CHANGELOG.md
64+
draft: false
65+
prerelease: false
66+
files: |
67+
${{ steps.extract_version.outputs.package_name }}
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
# Publish to VS Code Marketplace if VSCE_PAT is available
72+
- name: Publish to VS Code Marketplace
73+
if: env.HAS_VSCE_PAT == 'true'
74+
run: npx vsce publish --packagePath ${{ steps.extract_version.outputs.package_name }}
75+
env:
76+
VSCE_PAT: ${{ secrets.VSCE_PAT }}

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to the "Markdown Arweave Uploader" extension will be documented in this file.
4+
5+
## [0.2.0] - 2023-04-09
6+
7+
- Initial release with core functionality
8+
- Image optimization and processing
9+
- Arweave blockchain storage integration
10+
- Markdown link insertion
11+
- Wallet management
12+
- Statistics tracking

Makefile

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Makefile for Markdown Arweave Uploader
2+
3+
# Detect OS
4+
ifeq ($(OS),Windows_NT)
5+
DETECTED_OS := Windows
6+
else
7+
DETECTED_OS := $(shell uname -s)
8+
endif
9+
10+
# Tool management
11+
NODE := node
12+
NPM := npm
13+
VSCE := npx vsce
14+
15+
# Colors
16+
YELLOW := \033[1;33m
17+
GREEN := \033[1;32m
18+
RED := \033[1;31m
19+
BLUE := \033[1;34m
20+
RESET := \033[0m
21+
22+
# Targets
23+
.PHONY: all setup setup-first deps clean clean-all dev build package publish check \
24+
env-setup env-create env-check release-patch release-minor release-major help
25+
26+
all: setup build
27+
28+
# Setup commands
29+
setup: deps node_modules env-check_silent
30+
@echo "$(BLUE)Checking if environment is properly set up...$(RESET)"
31+
@if [ ! -f .env ]; then \
32+
echo "$(YELLOW)No .env file found. Creating from template...$(RESET)"; \
33+
$(MAKE) env-create; \
34+
echo "$(YELLOW)Please edit the .env file with your settings!$(RESET)"; \
35+
fi
36+
@echo "$(GREEN)✓ Setup complete$(RESET)"
37+
@echo "$(YELLOW)Run 'make env-setup' if you need to configure environment variables$(RESET)"
38+
39+
# Check environment without verbose output (for use in other targets)
40+
env-check_silent:
41+
@$(NPM) run env:validate > /dev/null 2>&1 || echo "$(YELLOW)⚠ Environment validation failed. Run 'make env-setup' to fix.$(RESET)"
42+
43+
# First-time setup for new developers
44+
setup-first:
45+
@echo "$(BLUE)Running first-time setup...$(RESET)"
46+
@$(NPM) run setup
47+
48+
node_modules: package.json
49+
@echo "$(BLUE)Installing dependencies...$(RESET)"
50+
@$(NPM) install
51+
@echo "$(GREEN)✓ Dependencies installed$(RESET)"
52+
53+
# Install ImageMagick if needed
54+
deps:
55+
@echo "$(BLUE)Checking system dependencies...$(RESET)"
56+
@if ! command -v node > /dev/null; then \
57+
echo "$(RED)✗ Node.js is not installed!$(RESET)"; \
58+
echo "$(YELLOW)Please install Node.js from https://nodejs.org/$(RESET)"; \
59+
exit 1; \
60+
else \
61+
echo "$(GREEN)✓ Node.js is installed$(RESET)"; \
62+
fi
63+
@if ! command -v npm > /dev/null; then \
64+
echo "$(RED)✗ npm is not installed!$(RESET)"; \
65+
echo "$(YELLOW)Please install npm (it usually comes with Node.js)$(RESET)"; \
66+
exit 1; \
67+
else \
68+
echo "$(GREEN)✓ npm is installed$(RESET)"; \
69+
fi
70+
ifeq ($(DETECTED_OS),Darwin)
71+
@echo "$(BLUE)Checking ImageMagick on macOS...$(RESET)"
72+
@if ! command -v magick > /dev/null && ! command -v convert > /dev/null; then \
73+
echo "$(YELLOW)Installing ImageMagick via Homebrew...$(RESET)"; \
74+
brew install imagemagick || echo "$(RED)Failed to install ImageMagick. Please install manually.$(RESET)"; \
75+
else \
76+
echo "$(GREEN)✓ ImageMagick is already installed$(RESET)"; \
77+
fi
78+
else ifeq ($(DETECTED_OS),Linux)
79+
@echo "$(BLUE)Checking ImageMagick on Linux...$(RESET)"
80+
@if ! command -v magick > /dev/null && ! command -v convert > /dev/null; then \
81+
echo "$(YELLOW)Installing ImageMagick...$(RESET)"; \
82+
if command -v apt-get > /dev/null; then \
83+
sudo apt-get update && sudo apt-get install -y imagemagick || echo "$(RED)Failed to install ImageMagick. Please install manually.$(RESET)"; \
84+
elif command -v yum > /dev/null; then \
85+
sudo yum install -y ImageMagick || echo "$(RED)Failed to install ImageMagick. Please install manually.$(RESET)"; \
86+
else \
87+
echo "$(RED)Please install ImageMagick manually$(RESET)"; \
88+
fi \
89+
else \
90+
echo "$(GREEN)✓ ImageMagick is already installed$(RESET)"; \
91+
fi
92+
else
93+
@echo "$(YELLOW)Please install ImageMagick manually:$(RESET)"
94+
@echo "Download from: https://imagemagick.org/script/download.php"
95+
endif
96+
@echo "$(GREEN)✓ System dependency checks completed$(RESET)"
97+
98+
# Environment setup
99+
env-setup:
100+
@echo "$(BLUE)Setting up environment variables...$(RESET)"
101+
@$(NPM) run env:setup
102+
103+
env-create:
104+
@echo "$(BLUE)Creating .env file from template...$(RESET)"
105+
@$(NPM) run env:create
106+
107+
env-check:
108+
@echo "$(BLUE)Validating environment variables...$(RESET)"
109+
@$(NPM) run env:validate
110+
111+
# Development commands
112+
dev:
113+
@echo "$(BLUE)Starting development server...$(RESET)"
114+
@$(NPM) run webpack-watch
115+
116+
# Build commands
117+
build:
118+
@echo "$(BLUE)Building extension...$(RESET)"
119+
@$(NPM) run webpack-prod
120+
@echo "$(GREEN)✓ Build completed$(RESET)"
121+
122+
test:
123+
@echo "$(BLUE)Running tests...$(RESET)"
124+
@$(NPM) test
125+
126+
lint:
127+
@echo "$(BLUE)Linting code...$(RESET)"
128+
@$(NPM) run lint
129+
130+
# Package and publish
131+
package:
132+
@echo "$(BLUE)Packaging extension...$(RESET)"
133+
@$(NPM) run package
134+
@echo "$(GREEN)✓ Package created$(RESET)"
135+
136+
publish: env-check
137+
@echo "$(BLUE)Publishing extension...$(RESET)"
138+
@$(NPM) run publish
139+
140+
# Release commands
141+
release-patch:
142+
@echo "$(BLUE)Creating patch release...$(RESET)"
143+
@$(NPM) run release:patch
144+
145+
release-minor:
146+
@echo "$(BLUE)Creating minor release...$(RESET)"
147+
@$(NPM) run release:minor
148+
149+
release-major:
150+
@echo "$(BLUE)Creating major release...$(RESET)"
151+
@$(NPM) run release:major
152+
153+
# Clean commands
154+
clean:
155+
@echo "$(BLUE)Cleaning build artifacts...$(RESET)"
156+
@$(NPM) run clean
157+
@echo "$(GREEN)✓ Clean completed$(RESET)"
158+
159+
clean-all: clean
160+
@echo "$(BLUE)Removing node_modules...$(RESET)"
161+
@rm -rf node_modules
162+
@echo "$(GREEN)✓ All cleaned$(RESET)"
163+
164+
# Help
165+
help:
166+
@echo "$(YELLOW)Markdown Arweave Uploader$(RESET) build commands:"
167+
@echo ""
168+
@echo "$(BLUE)Setup:$(RESET)"
169+
@echo " $(GREEN)make setup-first$(RESET) - Run first-time setup (recommended for new developers)"
170+
@echo " $(GREEN)make setup$(RESET) - Install dependencies"
171+
@echo " $(GREEN)make deps$(RESET) - Install system dependencies (ImageMagick)"
172+
@echo " $(GREEN)make env-setup$(RESET) - Interactive .env setup"
173+
@echo " $(GREEN)make env-create$(RESET) - Create .env from template"
174+
@echo " $(GREEN)make env-check$(RESET) - Validate environment variables"
175+
@echo ""
176+
@echo "$(BLUE)Development:$(RESET)"
177+
@echo " $(GREEN)make dev$(RESET) - Start development server with watch mode"
178+
@echo " $(GREEN)make build$(RESET) - Build the extension"
179+
@echo " $(GREEN)make test$(RESET) - Run tests"
180+
@echo " $(GREEN)make lint$(RESET) - Run linter"
181+
@echo ""
182+
@echo "$(BLUE)Release:$(RESET)"
183+
@echo " $(GREEN)make package$(RESET) - Create VSIX package"
184+
@echo " $(GREEN)make publish$(RESET) - Publish to VS Code Marketplace"
185+
@echo " $(GREEN)make release-patch$(RESET) - Create patch release (0.0.X)"
186+
@echo " $(GREEN)make release-minor$(RESET) - Create minor release (0.X.0)"
187+
@echo " $(GREEN)make release-major$(RESET) - Create major release (X.0.0)"
188+
@echo ""
189+
@echo "$(BLUE)Clean:$(RESET)"
190+
@echo " $(GREEN)make clean$(RESET) - Clean build artifacts"
191+
@echo " $(GREEN)make clean-all$(RESET) - Clean everything including node_modules"
192+
@echo ""
193+
194+
# Default target
195+
.DEFAULT_GOAL := help

0 commit comments

Comments
 (0)