Files
ccs/.github/workflows/dev-release.yml
T
kaitranntt ee76d663ae feat(ci): add Discord notifications for releases
- stable releases: fetch GH release, post green embed with changelog

- dev releases: post orange embed with version info

- graceful skip if webhook not configured
2025-12-19 00:26:22 -05:00

170 lines
5.4 KiB
YAML

name: Dev Release
on:
push:
branches: [dev]
jobs:
release:
# Skip if commit message contains [skip ci] or is a release commit
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: |
bun install --frozen-lockfile
cd ui && bun install --frozen-lockfile
- name: Build
run: bun run build:all
- name: Validate (typecheck + lint + tests)
run: bun run validate
- name: Bump dev version
id: bump
run: |
CURRENT=$(cat VERSION)
PKG_NAME=$(jq -r '.name' package.json)
# Extract base version
if [[ "$CURRENT" =~ ^([0-9]+\.[0-9]+\.[0-9]+)(-dev\.([0-9]+))?$ ]]; then
BASE="${BASH_REMATCH[1]}"
else
echo "Invalid version format: $CURRENT"
exit 1
fi
# Find highest published dev version for this base
LATEST_DEV=$(npm view "${PKG_NAME}" versions --json 2>/dev/null | \
jq -r '.[]' | \
grep "^${BASE}-dev\." | \
sed "s/${BASE}-dev\.//" | \
sort -n | \
tail -1)
if [[ -z "$LATEST_DEV" ]]; then
NEW_DEV=1
else
NEW_DEV=$((LATEST_DEV + 1))
fi
NEW_VERSION="${BASE}-dev.${NEW_DEV}"
echo "current=$CURRENT" >> $GITHUB_OUTPUT
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumping: $CURRENT -> $NEW_VERSION"
- name: Update version files
run: |
NEW_VERSION="${{ steps.bump.outputs.new }}"
# Update VERSION file
echo "$NEW_VERSION" > VERSION
# Update package.json
jq --arg v "$NEW_VERSION" '.version = $v' package.json > package.json.tmp
mv package.json.tmp package.json
- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --tag dev
- name: Tag resolved issues
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_VERSION="${{ steps.bump.outputs.new }}"
# Find commits since last dev release (look for version bump commits)
LAST_RELEASE_COMMIT=$(git log --oneline --grep="chore(release):" -n 2 | tail -1 | cut -d' ' -f1)
if [[ -n "$LAST_RELEASE_COMMIT" ]]; then
RANGE="${LAST_RELEASE_COMMIT}..HEAD"
else
RANGE="HEAD~20..HEAD"
fi
echo "Checking commits in range: $RANGE"
# Extract issue numbers from commits
ISSUES=$(git log $RANGE --pretty=format:"%s %b" | \
grep -oE "(Fixes|Closes|Resolves|Refs?) #[0-9]+" | \
grep -oE "#[0-9]+" | sort -u || true)
if [[ -z "$ISSUES" ]]; then
echo "No linked issues found in commits"
exit 0
fi
# Create labels if they don't exist
gh label create "released-dev" \
--color "1d76db" \
--description "Fix available in @dev npm channel" \
--repo ${{ github.repository }} 2>/dev/null || true
for ISSUE in $ISSUES; do
NUM=${ISSUE#\#}
# Skip if already tagged (avoid spam)
if gh issue view "$NUM" --repo "${{ github.repository }}" --json labels --jq '.labels[].name' | grep -q "released-dev"; then
echo "Issue #$NUM already has released-dev label, skipping"
continue
fi
echo "Tagging issue #$NUM as released-dev"
# Add comment
gh issue comment "$NUM" --repo "${{ github.repository }}" --body ":test_tube: Available in \`$NEW_VERSION\`. Install: \`npm i @kaitranntt/ccs@dev\`" || true
# Add released-dev label
gh issue edit "$NUM" --add-label "released-dev" --repo "${{ github.repository }}" || true
done
- name: Commit version bump
env:
HUSKY: 0
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add VERSION package.json
git commit -m "chore(release): ${{ steps.bump.outputs.new }} [skip ci]"
git push origin dev
- name: Notify Discord
if: success()
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
VERSION: ${{ steps.bump.outputs.new }}
run: |
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "DISCORD_WEBHOOK_URL not set, skipping notification"
exit 0
fi
curl -s -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"username\":\"CCS Dev Release\",\"embeds\":[{\"title\":\"Dev Release $VERSION\",\"url\":\"https://www.npmjs.com/package/@kaitranntt/ccs/v/$VERSION\",\"color\":15638323,\"description\":\"Pre-release version available for testing.\",\"footer\":{\"text\":\"npm i @kaitranntt/ccs@dev\"}}]}"