Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 36 additions & 50 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 }}"
55 changes: 35 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading