-
Notifications
You must be signed in to change notification settings - Fork 2
80 lines (66 loc) · 2.49 KB
/
v2-release.yml
File metadata and controls
80 lines (66 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 }}