fix: use bundler-based import resolution for npm packages in workers #10
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: Release & Publish | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
| concurrency: | ||
| group: release-${{ github.ref }} | ||
| cancel-in-progress: false | ||
| jobs: | ||
| # First run the full CI pipeline | ||
| ci: | ||
| name: CI Pipeline | ||
| uses: ./.github/workflows/ci.yml | ||
| release: | ||
| name: Release & Publish | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| packages: write | ||
| # Only run if CI passes and this is a changeset release | ||
| needs: [ci] | ||
| if: contains(github.event.head_commit.message, 'chore: version packages') || contains(github.event.head_commit.message, 'Release: Version Packages') || github.event_name == 'workflow_dispatch' | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits | ||
| fetch-depth: 0 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| scope: '@easythread' | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v2 | ||
| with: | ||
| version: 10.13.1 | ||
| - name: Get pnpm store directory | ||
| id: pnpm-cache | ||
| shell: bash | ||
| run: | | ||
| echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | ||
| - name: Setup pnpm cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | ||
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pnpm-store- | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| - name: Build packages | ||
| run: pnpm build | ||
| - name: Setup NPM authentication | ||
| run: | | ||
| echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc | ||
| echo "Current NPM user:" | ||
| npm whoami | ||
| echo "" | ||
| echo "Checking NPM token permissions:" | ||
| npm token list 2>/dev/null || echo "Could not list tokens (this is normal with publish tokens)" | ||
| echo "" | ||
| echo "Checking @easythread organization access:" | ||
| npm org ls @easythread 2>/dev/null || echo "Organization not accessible or doesn't exist" | ||
| echo "" | ||
| echo "Checking if we can access the organization packages:" | ||
| npm access list packages @easythread 2>/dev/null || echo "No packages found or no access (expected for first publish)" | ||
| echo "" | ||
| echo "Testing package publish permissions (dry run):" | ||
| cd packages/core | ||
| npm publish --dry-run --access public || echo "Dry run failed - this will help identify the issue" | ||
| env: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| - name: Create Release Pull Request or Publish to npm | ||
| id: changesets | ||
| uses: changesets/action@v1 | ||
| with: | ||
| # This expects you to have a script called release which does a build for your packages and calls changeset publish | ||
| publish: pnpm release | ||
| title: "Release: Version Packages" | ||
| commit: "chore: version packages" | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| - name: Send Slack notification on release | ||
| if: steps.changesets.outputs.published == 'true' | ||
| run: | | ||
| echo "🎉 New release published!" | ||
| echo "Published packages: ${{ steps.changesets.outputs.publishedPackages }}" | ||
| # Create GitHub releases when packages are published | ||
| create-github-release: | ||
| name: Create GitHub Release | ||
| runs-on: ubuntu-latest | ||
| needs: [release] | ||
| if: needs.release.outputs.published == 'true' | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v2 | ||
| with: | ||
| version: 10.13.1 | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| - name: Get latest version | ||
| id: version | ||
| run: | | ||
| VERSION=$(node -p "require('./packages/core/package.json').version") | ||
| echo "version=v$VERSION" >> $GITHUB_OUTPUT | ||
| - name: Generate changelog | ||
| id: changelog | ||
| run: | | ||
| if [ -f "CHANGELOG.md" ]; then | ||
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | ||
| head -n 50 CHANGELOG.md >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "changelog=New release with latest changes" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Create GitHub Release | ||
| uses: actions/create-release@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| tag_name: ${{ steps.version.outputs.version }} | ||
| release_name: ${{ steps.version.outputs.version }} | ||
| body: | | ||
| ## 🎉 New Release | ||
| ${{ steps.changelog.outputs.changelog }} | ||
| ### 📦 Published Packages | ||
| - `@easythread/core` | ||
| - `@easythread/vite` | ||
| - `@easythread/rollup` | ||
| - `@easythread/esbuild` | ||
| ### 🚀 Installation | ||
| ```bash | ||
| # Core package | ||
| npm install @easythread/core | ||
| # Plugin for your bundler | ||
| npm install @easythread/vite | ||
| npm install @easythread/rollup | ||
| npm install @easythread/esbuild | ||
| ``` | ||
| **Full Changelog**: https://github.com/leka74/easythread/compare/${{ github.event.before }}...${{ github.sha }} | ||
| draft: false | ||
| prerelease: false | ||