diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 258b91a..fb1823f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,21 +1,11 @@ name: Deploy on: - workflow_dispatch: - inputs: - version_type: - description: 'Version bump type' - required: true - default: 'patch' - type: choice - options: - - patch - - minor - - major - tag: - description: 'Tag for pre-release (e.g., beta, alpha)' - required: false - type: string + push: + branches: + - main + paths: + - 'package.json' permissions: id-token: write @@ -35,7 +25,30 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract version and determine tag + id: version + run: | + VERSION=$(node -p "require('./package.json').version") + + if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + TAG="latest" + IS_PRERELEASE="false" + elif [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+-([a-zA-Z]+) ]]; then + TAG="${BASH_REMATCH[1]}" + IS_PRERELEASE="true" + else + echo "❌ Invalid version format: $VERSION" + exit 1 + fi + + echo "version=v$VERSION" >> $GITHUB_OUTPUT + echo "version_number=$VERSION" >> $GITHUB_OUTPUT + echo "tag=$TAG" >> $GITHUB_OUTPUT + echo "prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT + + echo "📦 Version: $VERSION" + echo "🏷️ NPM Tag: $TAG" - name: Setup pnpm uses: pnpm/action-setup@v4 @@ -47,6 +60,7 @@ jobs: with: node-version: 22 cache: 'pnpm' + registry-url: 'https://registry.npmjs.org' - name: Install dependencies run: pnpm install --frozen-lockfile @@ -61,34 +75,6 @@ jobs: - name: Build library run: pnpm run build - - name: Configure Git - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - - - name: Bump version - id: version - run: | - if [ -n "${{ inputs.tag }}" ]; then - # Pre-release version - NEW_VERSION=$(npm version pre${{ inputs.version_type }} --preid=${{ inputs.tag }} --no-git-tag-version) - echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT - else - # Regular version - NEW_VERSION=$(npm version ${{ inputs.version_type }} --no-git-tag-version) - echo "tag=latest" >> $GITHUB_OUTPUT - fi - echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT - echo "New version: ${NEW_VERSION}" - - - name: Commit version bump - run: | - git add package.json - git commit -m "chore: bump version to ${{ steps.version.outputs.version }}" - git tag ${{ steps.version.outputs.version }} - git push origin main - git push origin ${{ steps.version.outputs.version }} - - name: Publish to NPM run: npm publish --access public --tag ${{ steps.version.outputs.tag }} --provenance env: @@ -105,20 +91,20 @@ jobs: ## 📦 Installation ```bash - npm install @ubidots/react-html-canvas@${{ steps.version.outputs.version }} + npm install @ubidots/react-html-canvas@${{ steps.version.outputs.version_number }} # or - pnpm add @ubidots/react-html-canvas@${{ steps.version.outputs.version }} + pnpm add @ubidots/react-html-canvas@${{ steps.version.outputs.version_number }} ``` ## 🔗 Links - - [NPM Package](https://www.npmjs.com/package/@ubidots/react-html-canvas) + - [NPM Package](https://www.npmjs.com/package/@ubidots/react-html-canvas/v/${{ steps.version.outputs.version_number }}) - [Documentation](https://github.com/ubidots/react-html-canvas#readme) draft: false - prerelease: ${{ inputs.tag != '' }} + prerelease: ${{ steps.version.outputs.prerelease }} token: ${{ secrets.GITHUB_TOKEN }} - name: Deployment Summary run: | echo "✅ Successfully deployed ${{ steps.version.outputs.version }} to NPM" - echo "📦 Package: https://www.npmjs.com/package/@ubidots/react-html-canvas" - echo "🏷️ Tag: ${{ steps.version.outputs.tag }}" + echo "📦 Package: https://www.npmjs.com/package/@ubidots/react-html-canvas/v/${{ steps.version.outputs.version_number }}" + echo "🏷️ Tag: ${{ steps.version.outputs.tag }}" diff --git a/README.md b/README.md index 5dfd7f3..425fc35 100644 --- a/README.md +++ b/README.md @@ -184,34 +184,49 @@ Runs on every PR and push to main/develop branches: #### Deployment Pipeline (`.github/workflows/deploy.yml`) -Manual deployment workflow with the following features: - -- **Manual Trigger**: Only runs when manually triggered from GitHub Actions -- **Version Selection**: Choose patch, minor, or major version bump -- **Pre-release Support**: Optional tag for beta/alpha releases -- **Quality Checks**: Full linting, testing, and build verification -- **Automated Versioning**: Bumps version and creates git tags -- **NPM Publishing**: Publishes to NPM with appropriate tags +Automated deployment workflow triggered when version changes are merged to main: + +- **Automatic Trigger**: Runs when package.json changes are pushed to main +- **Pre-release Detection**: Auto-detects pre-release tags from version format +- **Quality Checks**: Full linting, testing, and build verification before publish +- **NPM Publishing**: Uses OIDC trusted publishing with provenance attestation - **GitHub Release**: Creates release with installation instructions ### How to Deploy To deploy a new version: -1. Go to the **Actions** tab in GitHub -2. Select the **Deploy** workflow -3. Click **Run workflow** -4. Choose the version bump type (patch/minor/major) -5. Optionally add a pre-release tag (e.g., "beta") -6. Click **Run workflow** +1. **Update version in your PR**: + + ```bash + # For stable releases + npm version patch # or minor, major + + # For pre-releases + npm version prerelease --preid=beta + ``` + +2. **Commit and create PR**: + + ```bash + git add package.json + git commit -m "chore: bump version to vX.Y.Z" + git push + ``` + +3. **Merge to main**: + - Ensure all PR checks pass + - Merge the PR + +4. **Automatic deployment**: + - Workflow automatically publishes to npm + - GitHub release created automatically -The deployment will: +#### Version Formats -- Run all quality checks -- Bump the version in package.json -- Create a git tag -- Publish to NPM -- Create a GitHub release +- `1.0.0` → npm tag: `latest` +- `1.0.0-beta.1` → npm tag: `beta` +- `1.0.0-alpha.1` → npm tag: `alpha` ## License