diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 0000000..530f2d8 --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,188 @@ +name: Auto Release + +on: + push: + branches: + - main + paths-ignore: + - '**.md' + - '.github/workflows/auto-release.yml' + +permissions: + contents: write + +jobs: + auto-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Setup Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install system dependencies for skia-canvas + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + libcairo2-dev \ + libpango1.0-dev \ + libjpeg-dev \ + libgif-dev \ + librsvg2-dev \ + libpixman-1-dev \ + pkg-config \ + python3 \ + make \ + g++ \ + libstdc++6 + + - name: Install dependencies + run: bun install + + - name: Rebuild native modules + env: + NODE_ENV: production + SKIA_CANVAS_USE_SYSTEM_LIBRARIES: 1 + run: | + cd node_modules/skia-canvas && npm rebuild + cd ../.. + node -e "console.log('Testing skia-canvas import...'); require('skia-canvas'); console.log('✅ skia-canvas loaded successfully')" + + - name: Build action + run: bun run build + + - name: Verify build + run: | + echo "Checking built files..." + ls -la dist/ + echo "Testing action execution..." + node -e "console.log('Testing action import...'); require('./dist/action.js'); console.log('✅ Action loaded successfully')" + + - name: Get commit history + id: commits + uses: actions/github-script@v7 + with: + script: | + const { execSync } = require('child_process'); + + // Get commits since last tag + const lastTag = execSync('git describe --tags --abbrev=0 2>/dev/null || echo ""', { encoding: 'utf8' }).trim(); + const commits = execSync(`git log ${lastTag ? lastTag + '..HEAD' : '--oneline'} --pretty=format:"%s"`, { encoding: 'utf8' }).trim().split('\n'); + + console.log('Commits since last tag:', commits); + + return { commits: commits.join('\n') }; + + - name: Determine version bump + id: version + run: | + # Always bump patch version for auto-releases + echo "bump_type=patch" >> $GITHUB_OUTPUT + echo "Bump type: ${{ steps.version.outputs.bump_type }}" + + - name: Bump version + id: bump + run: | + # Get current version + CURRENT_VERSION=$(node -p "require('./package.json').version") + echo "Current version: $CURRENT_VERSION" + + # Bump version + NEW_VERSION=$(npm version ${{ steps.version.outputs.bump_type }} --no-git-tag-version) + echo "New version: $NEW_VERSION" + + # Remove 'v' prefix if present + NEW_VERSION=${NEW_VERSION#v} + echo "Cleaned version: $NEW_VERSION" + + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.bump.outputs.new_version }} + release_name: Release v${{ steps.bump.outputs.new_version }} + body: | + ## 🎉 Release v${{ steps.bump.outputs.new_version }} + + ### Changes: + ${{ steps.commits.outputs.commits }} + + ### Usage: + Update your workflows to use: + ```yaml + uses: LukeHagar/usage-statistics@v${{ steps.bump.outputs.new_version }} + ``` + draft: false + prerelease: false + + - name: Upload Release Assets + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/action.js + asset_name: action.js + asset_content_type: application/javascript + + - name: Upload Release Assets - Collectors + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/collectors/ + asset_name: collectors.zip + asset_content_type: application/zip + + - name: Upload Release Assets - Summaries + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/summaries/ + asset_name: summaries.zip + asset_content_type: application/zip + + - name: Upload Release Assets - Utils + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/utils.js + asset_name: utils.js + asset_content_type: application/javascript + + - name: Commit version bump + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add package.json + git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}" + git push + + - name: Create and push tag + run: | + git tag v${{ steps.bump.outputs.new_version }} + git push origin v${{ steps.bump.outputs.new_version }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f0082d7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,183 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: 'Version to release (patch, minor, major)' + required: true + default: 'patch' + type: choice + options: + - patch + - minor + - major + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Setup Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install system dependencies for skia-canvas + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + libcairo2-dev \ + libpango1.0-dev \ + libjpeg-dev \ + libgif-dev \ + librsvg2-dev \ + libpixman-1-dev \ + pkg-config \ + python3 \ + make \ + g++ \ + libstdc++6 + + - name: Install dependencies + run: bun install + + - name: Rebuild native modules + env: + NODE_ENV: production + SKIA_CANVAS_USE_SYSTEM_LIBRARIES: 1 + run: | + cd node_modules/skia-canvas && npm rebuild + cd ../.. + node -e "console.log('Testing skia-canvas import...'); require('skia-canvas'); console.log('✅ skia-canvas loaded successfully')" + + - name: Build action + run: bun run build + + - name: Verify build + run: | + echo "Checking built files..." + ls -la dist/ + echo "Testing action execution..." + node -e "console.log('Testing action import...'); require('./dist/action.js'); console.log('✅ Action loaded successfully')" + + - name: Bump version + id: bump + run: | + # Get current version + CURRENT_VERSION=$(node -p "require('./package.json').version") + echo "Current version: $CURRENT_VERSION" + + # Bump version + NEW_VERSION=$(npm version ${{ github.event.inputs.version }} --no-git-tag-version) + echo "New version: $NEW_VERSION" + + # Remove 'v' prefix if present + NEW_VERSION=${NEW_VERSION#v} + echo "Cleaned version: $NEW_VERSION" + + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.bump.outputs.new_version }} + release_name: Release v${{ steps.bump.outputs.new_version }} + draft: false + prerelease: false + + - name: Upload Release Assets + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/action.js + asset_name: action.js + asset_content_type: application/javascript + + - name: Upload Release Assets - Collectors + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/collectors/ + asset_name: collectors.zip + asset_content_type: application/zip + + - name: Upload Release Assets - Summaries + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/summaries/ + asset_name: summaries.zip + asset_content_type: application/zip + + - name: Upload Release Assets - Utils + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/utils.js + asset_name: utils.js + asset_content_type: application/javascript + + - name: Commit version bump + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add package.json + git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}" + git push + + - name: Create and push tag + run: | + git tag v${{ steps.bump.outputs.new_version }} + git push origin v${{ steps.bump.outputs.new_version }} + + - name: Update action.yml version reference + run: | + # Update the action.yml to reference the new version + sed -i "s/uses: LukeHagar\/usage-statistics@v[0-9]*\.[0-9]*\.[0-9]*/uses: LukeHagar\/usage-statistics@v${{ steps.bump.outputs.new_version }}/g" .github/workflows/test-action-local.yml + git add .github/workflows/test-action-local.yml + git commit -m "chore: update test workflow to use v${{ steps.bump.outputs.new_version }}" || echo "No changes to commit" + git push + + - name: Comment on release + run: | + echo "## 🎉 Release v${{ steps.bump.outputs.new_version }} Published!" + echo "" + echo "### What's New:" + echo "- Version bumped from ${{ steps.bump.outputs.current_version }} to ${{ steps.bump.outputs.new_version }}" + echo "- Action built and tested successfully" + echo "- Release assets uploaded" + echo "" + echo "### Usage:" + echo "Update your workflows to use:" + echo "```yaml" + echo "uses: LukeHagar/usage-statistics@v${{ steps.bump.outputs.new_version }}" + echo "```" diff --git a/RELEASES.md b/RELEASES.md new file mode 100644 index 0000000..d80dbaa --- /dev/null +++ b/RELEASES.md @@ -0,0 +1,119 @@ +# Release Process + +This repository has two release workflows to make publishing new versions easy and automated. + +## 🚀 Release Workflows + +### 1. Manual Release (`release.yml`) + +**When to use**: When you want to manually control the release process and version bump. + +**How to trigger**: +1. Go to the **Actions** tab in GitHub +2. Select **Release** workflow +3. Click **Run workflow** +4. Choose the version bump type: + - `patch` - Bug fixes and minor changes (1.0.0 → 1.0.1) + - `minor` - New features (1.0.0 → 1.1.0) + - `major` - Breaking changes (1.0.0 → 2.0.0) + +**What it does**: +- ✅ Installs dependencies and builds the action +- ✅ Bumps version in `package.json` +- ✅ Creates a new GitHub release with tag +- ✅ Uploads built assets to the release +- ✅ Commits version bump back to repository +- ✅ Updates test workflow to use new version + +### 2. Automated Release (`auto-release.yml`) + +**When to use**: For automatic releases on every push to main. + +**How to trigger**: Push any commits to `main` branch. + +**What it does**: +- ✅ Automatically creates a new patch release +- ✅ Bumps version in package.json +- ✅ Creates release with commit history +- ✅ Uploads built assets +- ✅ Tags and commits version bump + +## 📦 Release Assets + +Each release includes: +- `action.js` - Main action entry point +- `collectors.zip` - All collector modules +- `summaries.zip` - All summary modules +- `utils.js` - Utility functions + +## 🔄 Version Management + +### Current Version +The current version is stored in `package.json` and follows [semantic versioning](https://semver.org/): +- **Major** (X.0.0): Breaking changes +- **Minor** (0.X.0): New features, backward compatible +- **Patch** (0.0.X): Bug fixes, backward compatible + +### Version Tags +Releases are tagged with `v` prefix: +- `v1.0.0` +- `v1.1.0` +- `v2.0.0` + +### Action Usage +Users can reference specific versions: +```yaml +uses: LukeHagar/usage-statistics@v1.0.0 # Specific version +uses: LukeHagar/usage-statistics@v1 # Latest v1.x.x +uses: LukeHagar/usage-statistics@main # Latest from main branch +``` + +## 🛠️ Development Workflow + +### For Feature Development +1. Create feature branch +2. Make changes and commit +3. Push to main branch +4. Automated release will trigger automatically + +### For Manual Releases +1. Make changes and commit +2. Go to Actions → Release +3. Choose version bump type +4. Run workflow + +### For Quick Updates +1. Make changes and commit +2. Push to main branch +3. Automated release creates patch version + +## 📋 Release Checklist + +Before releasing: +- [ ] All tests pass +- [ ] Action builds successfully +- [ ] Native modules compile correctly +- [ ] README is up to date +- [ ] Version is appropriate for changes + +After release: +- [ ] Verify release assets are uploaded +- [ ] Check that action works with new version +- [ ] Update documentation if needed +- [ ] Notify users of breaking changes (if any) + +## 🚨 Breaking Changes + +When making breaking changes: +1. Use `BREAKING CHANGE:` in commit message +2. Update README with migration guide +3. Consider creating a migration guide in release notes +4. Notify users through GitHub discussions or issues + +## 📈 Release History + +Check the [Releases page](https://github.com/LukeHagar/usage-statistics/releases) for: +- Complete release history +- Downloadable assets +- Release notes and changelog +- Migration guides for breaking changes diff --git a/package.json b/package.json index b94f0f7..2d6e154 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,11 @@ "main": "src/index.ts", "scripts": { "dev": "bun --watch --env-file=.dev.env --env-file=.env run src/action.ts", - "build": "tsc -p tsconfig.build.json" + "build": "tsc -p tsconfig.build.json", + "test": "bun test", + "test:action": "bun --env-file=.dev.env run dist/action.js", + "clean": "rm -rf dist/", + "prebuild": "npm run clean" }, "devDependencies": { "@types/bun": "latest", @@ -46,12 +50,11 @@ "npm", "github", "pypi", - "homebrew", "powershell", - "postman", - "go", "tracking", - "usage" + "usage", + "charts", + "reports" ], "author": "LukeHagar", "license": "MIT",