Releaser #314
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: Releaser | |
on: | |
push: | |
tags: | |
- 'v*' | |
schedule: | |
# Check for unreleased commits every 2 hours | |
- cron: '0 */6 * * *' | |
# Allow manual trigger | |
workflow_dispatch: | |
permissions: | |
contents: write | |
packages: write | |
id-token: write | |
jobs: | |
auto-release: | |
# Only run on schedule or manual trigger, not on tag pushes | |
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Debug workflow trigger | |
run: | | |
echo "=== Workflow Debug Information ===" | |
echo "Event name: ${{ github.event_name }}" | |
echo "Repository: ${{ github.repository }}" | |
echo "Ref: ${{ github.ref }}" | |
echo "SHA: ${{ github.sha }}" | |
echo "Actor: ${{ github.actor }}" | |
echo "Workflow: ${{ github.workflow }}" | |
echo "Job: ${{ github.job }}" | |
echo "Run ID: ${{ github.run_id }}" | |
echo "Run number: ${{ github.run_number }}" | |
echo "=================================" | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PAT_TOKEN || github.token }} | |
fetch-depth: 0 | |
- name: Setup Bun | |
uses: oven-sh/setup-bun@v2 | |
- name: Install dependencies | |
run: bun install | |
- name: Check for unreleased commits | |
id: check-commits | |
run: | | |
# Get the latest tag | |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
echo "Checking for unreleased commits..." | |
echo "Latest tag: $LATEST_TAG" | |
if [ -z "$LATEST_TAG" ]; then | |
echo "No previous tags found, will create initial release" | |
COMMIT_COUNT=$(git rev-list --count HEAD) | |
echo "Total commits in repository: $COMMIT_COUNT" | |
echo "commits_since_release=$COMMIT_COUNT" >> $GITHUB_OUTPUT | |
echo "has_unreleased=true" >> $GITHUB_OUTPUT | |
echo "latest_tag=" >> $GITHUB_OUTPUT | |
else | |
# Count commits since the latest tag | |
COMMIT_COUNT=$(git rev-list --count ${LATEST_TAG}..HEAD) | |
echo "Found $COMMIT_COUNT commits since $LATEST_TAG" | |
# Show the actual commits for debugging | |
if [ "$COMMIT_COUNT" -gt 0 ]; then | |
echo "Recent commits since $LATEST_TAG:" | |
git log --oneline ${LATEST_TAG}..HEAD | head -10 | |
fi | |
if [ "$COMMIT_COUNT" -gt 0 ]; then | |
echo "commits_since_release=$COMMIT_COUNT" >> $GITHUB_OUTPUT | |
echo "has_unreleased=true" >> $GITHUB_OUTPUT | |
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT | |
else | |
echo "No commits since last release" | |
echo "commits_since_release=0" >> $GITHUB_OUTPUT | |
echo "has_unreleased=false" >> $GITHUB_OUTPUT | |
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT | |
fi | |
fi | |
- name: Configure Git | |
if: steps.check-commits.outputs.has_unreleased == 'true' | |
run: | | |
# Use PAT if available to trigger subsequent workflows, otherwise use default token | |
if [ -n "${{ secrets.PAT_TOKEN }}" ]; then | |
echo "Using PAT token to trigger subsequent workflows" | |
git config --global user.name "chrisbbreuer" | |
git config --global user.email "chrisbreuer93@gmail.com" | |
git remote set-url origin https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git | |
else | |
echo "Using default GitHub token (subsequent workflows may not trigger)" | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
fi | |
- name: Run release | |
if: steps.check-commits.outputs.has_unreleased == 'true' | |
run: | | |
COMMIT_COUNT="${{ steps.check-commits.outputs.commits_since_release }}" | |
LATEST_TAG="${{ steps.check-commits.outputs.latest_tag }}" | |
echo "=== Release Information ===" | |
echo "Commits since last release: $COMMIT_COUNT" | |
echo "Latest tag: $LATEST_TAG" | |
echo "Current branch: $(git branch --show-current)" | |
echo "Current commit: $(git rev-parse HEAD)" | |
echo "==========================" | |
echo "Creating patch release for $COMMIT_COUNT new commit(s)" | |
# Use our simple bump script that always does patch releases | |
bun scripts/bump-version.ts | |
echo "Successfully created and pushed release" | |
env: | |
CI: true | |
FORCE_COLOR: 0 | |
NODE_ENV: production | |
npm: | |
# Only run on actual tag pushes (not on schedule) | |
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ env.VERSION }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PAT_TOKEN || github.token }} | |
fetch-depth: 0 | |
- name: Setup Bun | |
uses: oven-sh/setup-bun@v2 | |
- name: Use Cached node_modules | |
uses: actions/cache@v4 | |
with: | |
path: node_modules | |
key: node-modules-${{ hashFiles('**/bun.lock') }} | |
restore-keys: | | |
node-modules- | |
- name: Install Dependencies | |
run: bun install | |
- name: Extract tag version | |
id: get_version | |
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Publish to npm | |
run: bun publish --access public | |
env: | |
BUN_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | |
- name: Create GitHub Release | |
run: bunx changelogithub | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
- name: Attach Release Assets | |
id: create_release | |
uses: stacksjs/action-releaser@v1.1.0 | |
with: | |
files: | | |
./bin/pkgx-tools-linux-x64.zip | |
./bin/pkgx-tools-linux-arm64.zip | |
./bin/pkgx-tools-windows-x64.zip | |
./bin/pkgx-tools-darwin-x64.zip | |
./bin/pkgx-tools-darwin-arm64.zip | |
# --- Homebrew tap update support --- | |
# Path to your Homebrew formula template (update this path as needed) | |
# homebrewFormula: .github/homebrew-formula.rb | |
# The owner/repo of your Homebrew tap (update this value as needed) | |
# homebrewRepo: stacksjs/homebrew-tap | |
# Optionally uncomment and set these if you need custom values: | |
# homebrewBranch: main | |
# homebrewPath: Formula | |
# homebrewCommitFormat: "update: {{ formula }} to {{ version }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |