Update backend versionning #45
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: Build and Release needlectl | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - needlectl/** | |
| - ui/** | |
| - backend/** | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Ensure full git history for tag discovery | |
| - name: Get version information | |
| id: version | |
| run: | | |
| # Get the latest needlectl tag | |
| LATEST_TAG=$(git tag -l "needlectl/v*" --sort=-v:refname | head -n 1) | |
| if [ -z "$LATEST_TAG" ]; then | |
| echo "No existing tags found, using needlectl/v0.1.0" | |
| echo "base_version=0.1.0" >> $GITHUB_OUTPUT | |
| COMMIT_COUNT=$(git rev-list --count HEAD) | |
| else | |
| echo "Found latest tag: $LATEST_TAG" | |
| # Extract version number without prefix | |
| BASE_VERSION=${LATEST_TAG#needlectl/v} | |
| echo "base_version=$BASE_VERSION" >> $GITHUB_OUTPUT | |
| # Count commits since last tag | |
| COMMIT_COUNT=$(git rev-list --count $LATEST_TAG..HEAD) | |
| fi | |
| # Split the base version | |
| IFS='.' read -r major minor patch <<< "$BASE_VERSION" | |
| # Calculate new version | |
| NEW_PATCH=$((patch + COMMIT_COUNT)) | |
| NEW_VERSION="${major}.${minor}.${NEW_PATCH}" | |
| echo "New version will be: $NEW_VERSION" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| build-ui: | |
| runs-on: ubuntu-latest | |
| needs: prepare | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| submodules: recursive | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: ui/package-lock.json | |
| - name: Install UI dependencies | |
| working-directory: ./ui | |
| run: npm ci | |
| - name: Build UI | |
| working-directory: ./ui | |
| run: npm run build | |
| - name: Create UI build artifacts | |
| run: | | |
| cd ui | |
| tar -czf ../ui-build-linux.tar.gz build/ | |
| - name: Upload UI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ui-build-linux | |
| path: ui-build-linux.tar.gz | |
| retention-days: 30 | |
| build-ui-macos: | |
| runs-on: macos-latest | |
| needs: prepare | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| submodules: recursive | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: ui/package-lock.json | |
| - name: Install UI dependencies | |
| working-directory: ./ui | |
| run: npm ci | |
| - name: Build UI | |
| working-directory: ./ui | |
| run: npm run build | |
| - name: Create UI build artifacts | |
| run: | | |
| cd ui | |
| tar -czf ../ui-build-macos.tar.gz build/ | |
| - name: Upload UI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ui-build-macos | |
| path: ui-build-macos.tar.gz | |
| retention-days: 30 | |
| build-linux: | |
| runs-on: ubuntu-22.04 | |
| needs: prepare | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Create version file | |
| run: | | |
| echo "VERSION = '${{ needs.prepare.outputs.version }}'" > needlectl/cli/version.py | |
| echo "VERSION = '${{ needs.prepare.outputs.version }}'" > backend/version.py | |
| - name: Build needlectl for Linux | |
| run: | | |
| cd needlectl | |
| chmod +x build.sh | |
| ./build.sh | |
| - name: Archive Linux binary | |
| run: | | |
| mkdir -p release/linux | |
| mv needlectl/dist/needlectl release/linux/needlectl-linux | |
| - name: Upload Linux artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: needlectl-linux | |
| path: release/linux/needlectl-linux | |
| build-macos: | |
| runs-on: macos-latest | |
| needs: prepare | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Create version file | |
| run: | | |
| echo "VERSION = '${{ needs.prepare.outputs.version }}'" > needlectl/cli/version.py | |
| echo "VERSION = '${{ needs.prepare.outputs.version }}'" > backend/version.py | |
| - name: Build needlectl for macOS | |
| run: | | |
| cd needlectl | |
| chmod +x build.sh | |
| ./build.sh --target-arch universal2 | |
| - name: Archive macOS binary | |
| run: | | |
| mkdir -p release/macos | |
| mv needlectl/dist/needlectl release/macos/needlectl-macos | |
| - name: Upload macOS artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: needlectl-macos | |
| path: release/macos/needlectl-macos | |
| release: | |
| needs: [prepare, build-ui, build-ui-macos, build-linux, build-macos] | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download Linux artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: needlectl-linux | |
| path: release/linux | |
| - name: Download macOS artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: needlectl-macos | |
| path: release/macos | |
| - name: Download UI Linux artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ui-build-linux | |
| path: release/ui-linux | |
| - name: Download UI macOS artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ui-build-macos | |
| path: release/ui-macos | |
| - name: Set file permissions | |
| run: | | |
| chmod +x release/linux/needlectl-linux | |
| chmod +x release/macos/needlectl-macos | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: "needlectl v${{ needs.prepare.outputs.version }}" | |
| tag_name: "needlectl/v${{ needs.prepare.outputs.version }}" | |
| files: | | |
| release/linux/needlectl-linux | |
| release/macos/needlectl-macos | |
| release/ui-linux/ui-build-linux.tar.gz | |
| release/ui-macos/ui-build-macos.tar.gz | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| - name: Update Latest Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: "needlectl (latest)" | |
| tag_name: "latest" | |
| files: | | |
| release/linux/needlectl-linux | |
| release/macos/needlectl-macos | |
| release/ui-linux/ui-build-linux.tar.gz | |
| release/ui-macos/ui-build-macos.tar.gz | |
| draft: false | |
| prerelease: false | |
| update_existing: true | |
| clean: | |
| runs-on: ubuntu-22.04 | |
| needs: [release] | |
| if: always() | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Clean up | |
| run: | | |
| rm -rf needlectl/dist needlectl/build needlectl/build_env release |