mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-29 21:33:54 +00:00
fix: ci cd
This commit is contained in:
parent
a42f8fa99f
commit
e883523815
151
.github/workflows/deploy-tfcode.yml
vendored
Normal file
151
.github/workflows/deploy-tfcode.yml
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
name: Deploy tfcode to NPM
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "packages/tfcode/**"
|
||||
- ".github/workflows/deploy-tfcode.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
NODE_VERSION: "18"
|
||||
|
||||
jobs:
|
||||
check-version:
|
||||
name: Check if version changed
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version-changed: ${{ steps.check.outputs.changed }}
|
||||
new-version: ${{ steps.check.outputs.version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
|
||||
- name: Check version change
|
||||
id: check
|
||||
working-directory: packages/tfcode
|
||||
run: |
|
||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||
echo "Current version: $CURRENT_VERSION"
|
||||
|
||||
git checkout HEAD^ 2>/dev/null || true
|
||||
PREV_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0")
|
||||
git checkout - 2>/dev/null || true
|
||||
echo "Previous version: $PREV_VERSION"
|
||||
|
||||
if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
|
||||
echo "changed=true" >> $GITHUB_OUTPUT
|
||||
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "✅ Version changed from $PREV_VERSION to $CURRENT_VERSION"
|
||||
else
|
||||
echo "changed=false" >> $GITHUB_OUTPUT
|
||||
echo "⏭️ Version unchanged, skipping deployment"
|
||||
fi
|
||||
|
||||
build:
|
||||
name: Build tfcode binaries
|
||||
needs: check-version
|
||||
if: needs.check-version.outputs.version-changed == 'true'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
settings:
|
||||
- host: macos-latest
|
||||
target: darwin-arm64
|
||||
- host: macos-latest
|
||||
target: darwin-x64
|
||||
- host: ubuntu-latest
|
||||
target: linux-arm64
|
||||
- host: ubuntu-latest
|
||||
target: linux-x64
|
||||
- host: windows-latest
|
||||
target: win32-arm64
|
||||
- host: windows-latest
|
||||
target: win32-x64
|
||||
runs-on: ${{ matrix.settings.host }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-bun
|
||||
|
||||
- name: Build tfcode binary
|
||||
working-directory: packages/tfcode
|
||||
run: bun run build:single
|
||||
env:
|
||||
TFCODE_VERSION: ${{ needs.check-version.outputs.new-version }}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: tfcode-${{ matrix.settings.target }}
|
||||
path: packages/tfcode/dist/*
|
||||
|
||||
publish:
|
||||
name: Publish to NPM
|
||||
needs:
|
||||
- check-version
|
||||
- build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-bun
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: packages/tfcode/dist
|
||||
pattern: tfcode-*
|
||||
merge-multiple: true
|
||||
|
||||
- name: Verify version
|
||||
working-directory: packages/tfcode
|
||||
run: |
|
||||
VERSION=$(node -p "require('./package.json').version")
|
||||
echo "Publishing version: $VERSION"
|
||||
if [ "$VERSION" != "${{ needs.check-version.outputs.new-version }}" ]; then
|
||||
echo "Version mismatch!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Publish to NPM
|
||||
working-directory: packages/tfcode
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
|
||||
echo "📤 Publishing to NPM..."
|
||||
bun run publish:npm
|
||||
echo "✅ Published tfcode v${{ needs.check-version.outputs.new-version }}"
|
||||
|
||||
- name: Create Git Tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -a "v${{ needs.check-version.outputs.new-version }}" -m "tfcode v${{ needs.check-version.outputs.new-version }}"
|
||||
git push origin "v${{ needs.check-version.outputs.new-version }}"
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "### ✅ tfcode Deployed Successfully" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Version:** ${{ needs.check-version.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Installation:**" >> $GITHUB_STEP_SUMMARY
|
||||
echo '```bash' >> $GITHUB_STEP_SUMMARY
|
||||
echo "npm install -g @toothfairyai/tfcode@${{ needs.check-version.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**NPM:** https://www.npmjs.com/package/@toothfairyai/tfcode/v/${{ needs.check-version.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
|
||||
Loading…
x
Reference in New Issue
Block a user