publish v4.1.3 #12
Workflow file for this run
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: V2 Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' # Triggers on version tags like v4.0.0, v4.1.0, etc. | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # For creating GitHub Release | |
| packages: write # For publishing to GitHub Packages | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Full history needed for branch detection | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://npm.pkg.github.com' | |
| scope: '@weka' | |
| - name: Check branch for official releases | |
| run: | | |
| VERSION="${GITHUB_REF_NAME}" | |
| # Get the branch that contains this tag | |
| BRANCHES=$(git branch -r --contains ${{ github.sha }} | grep -v HEAD || true) | |
| if [[ ! "$VERSION" =~ "beta" && ! "$VERSION" =~ "alpha" && ! "$VERSION" =~ "rc" ]]; then | |
| # Official release - must be on main | |
| if [[ ! "$BRANCHES" =~ "origin/main" ]]; then | |
| echo "❌ Official releases must be from main branch" | |
| echo " Tag: $VERSION" | |
| echo " Branches containing this commit: $BRANCHES" | |
| echo "" | |
| echo "To fix: merge your changes to main first, then create the tag from main" | |
| exit 1 | |
| fi | |
| echo "✅ Official release from main branch" | |
| else | |
| echo "✅ Pre-release ($VERSION) - allowed from any branch" | |
| fi | |
| - name: Enable Corepack (for Yarn 4) | |
| run: corepack enable | |
| - name: Install dependencies | |
| run: yarn install --immutable | |
| - name: Sync version from git tag | |
| run: | | |
| TAG_VERSION="${GITHUB_REF_NAME#v}" # Strip 'v' prefix | |
| echo "Setting version to: $TAG_VERSION" | |
| npm version "$TAG_VERSION" --no-git-tag-version --allow-same-version | |
| - name: Build | |
| run: yarn build | |
| - name: Run tests | |
| run: yarn test:run | |
| - name: Configure npm authentication | |
| run: | | |
| yarn config set npmScopes.weka.npmRegistryServer "https://npm.pkg.github.com" | |
| yarn config set npmScopes.weka.npmAuthToken "${{ secrets.GITHUB_TOKEN }}" | |
| - name: Publish to GitHub Packages | |
| run: yarn npm publish | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |