mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 22:16:41 +00:00
- Use GITHUB_TOKEN for comments (posts as github-actions[bot]) - Skip issues already labeled released-dev (avoid spam) - Simpler one-line comment format
160 lines
4.9 KiB
YAML
160 lines
4.9 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
|
|
|
|
# Update installers
|
|
sed -i "s/^VERSION=.*/VERSION=\"$NEW_VERSION\"/" installers/install.sh
|
|
sed -i "s/^\$Version = .*/\$Version = \"$NEW_VERSION\"/" installers/install.ps1
|
|
|
|
- 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 installers/install.sh installers/install.ps1
|
|
git commit -m "chore(release): ${{ steps.bump.outputs.new }} [skip ci]"
|
|
git push origin dev
|