-
Notifications
You must be signed in to change notification settings - Fork 3
195 lines (172 loc) · 6.15 KB
/
main.yml
File metadata and controls
195 lines (172 loc) · 6.15 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# v2.2.0
name: Virto-shell CI
on:
workflow_dispatch:
push:
branches: [ main ]
# Only on commits with package changes or release commits
paths:
- 'framework/**'
- 'cli/**'
- 'configs/**'
- '**/package.json'
- '**/CHANGELOG.md'
release:
types: [published]
jobs:
CI:
runs-on: ubuntu-latest
# Only runs on release commits, releases, or manual dispatch
if: |
github.event_name == 'release' ||
github.event_name == 'workflow_dispatch' ||
contains(github.event.head_commit.message, 'release:') ||
contains(github.event.head_commit.message, 'chore: release')
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
VERSION_SUFFIX: ''
ARTIFACT_URL: ''
GITHUB_USER: '${{ github.repository_owner }}'
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TAG: 'latest'
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'
cache-dependency-path: 'yarn.lock'
always-auth: true
- name: Set GITHUB_USER to lowercase
run: |
echo "GITHUB_USER=${GITHUB_USER,,}" >> $GITHUB_ENV
- name: Install dependencies
run: |
yarn install
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
- name: Get Image Version
uses: VirtoCommerce/vc-github-actions/get-image-version@master
id: image
with:
projectType: theme
- name: Set release variables
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feat/vm-1646-custom-auth' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.prefix }}" >> $GITHUB_ENV
- name: Set release-alpha variables
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.fullVersion }}" >> $GITHUB_ENV
- name: Set PR variables
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.taggedVersion }}" >> $GITHUB_ENV
- name: Build virto-shell
run: |
yarn build
- name: Configure npm
if: success()
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Clean git state
if: success()
run: |
# Reset any changes to yarn.lock that might have occurred during install
git checkout -- yarn.lock || true
# Ensure clean working directory for Lerna
git status --porcelain
- name: Determine npm tag
if: success()
run: |
echo "Determining npm tag for publishing..."
# Get current version from framework package
CURRENT_VERSION=$(node -p "require('./framework/package.json').version")
echo "Current version: $CURRENT_VERSION"
# Strategy 1: Get npm tag from git tag (most reliable)
GIT_TAG=$(git describe --tags --exact-match HEAD 2>/dev/null || echo "")
if [ ! -z "$GIT_TAG" ]; then
echo "Found git tag: $GIT_TAG"
# Extract npm tag from git tag (e.g., v1.1.98-rc.3 -> rc)
if [[ "$GIT_TAG" == *"-rc"* ]]; then
NPM_TAG="rc"
elif [[ "$GIT_TAG" == *"-alpha"* ]]; then
NPM_TAG="alpha"
elif [[ "$GIT_TAG" == *"-beta"* ]]; then
NPM_TAG="beta"
elif [[ "$GIT_TAG" == *"-next"* ]]; then
NPM_TAG="next"
else
NPM_TAG="latest"
fi
echo "Using npm tag from git tag: $NPM_TAG"
else
# Strategy 2: Analyze version pattern (fallback)
if [[ "$CURRENT_VERSION" == *"-rc"* ]]; then
NPM_TAG="rc"
elif [[ "$CURRENT_VERSION" == *"-alpha"* ]]; then
NPM_TAG="alpha"
elif [[ "$CURRENT_VERSION" == *"-beta"* ]]; then
NPM_TAG="beta"
elif [[ "$CURRENT_VERSION" == *"-next"* ]]; then
NPM_TAG="next"
else
NPM_TAG="latest"
fi
echo "Using version-based tag (no git tag found): $NPM_TAG"
fi
# Strategy 3: Check commit message for explicit tag (override)
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MESSAGE" == *"npmTag:"* ]]; then
COMMIT_TAG=$(echo "$COMMIT_MESSAGE" | grep -o "npmTag:[a-zA-Z0-9-]*" | cut -d: -f2)
if [ ! -z "$COMMIT_TAG" ]; then
NPM_TAG="$COMMIT_TAG"
echo "Using tag from commit message (override): $NPM_TAG"
fi
fi
echo "NPM_TAG=$NPM_TAG" >> $GITHUB_ENV
echo "Final npm tag: $NPM_TAG"
- name: Publish with Lerna
if: success()
run: |
echo "Publishing packages with Lerna using tag: $NPM_TAG"
# Lerna automatically:
# - Detects changed packages from package.json
# - Uses the specified npm tag for all packages
# - Handles dependencies between packages
# - Excludes private packages and root package
npx lerna publish from-package --yes --no-git-reset --no-private --npm-tag="$NPM_TAG"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Verify npm dist tags
if: success()
run: |
echo "Verifying npm dist tags..."
echo "Published packages with tag: $NPM_TAG"
# Show current tags for verification
PACKAGES=(
"@vc-shell/framework"
"@vc-shell/ts-config"
"@vc-shell/release-config"
"@vc-shell/create-vc-app"
"@vc-shell/config-generator"
"@vc-shell/api-client-generator"
)
for PACKAGE in "${PACKAGES[@]}"; do
echo "Tags for $PACKAGE:"
npm dist-tag ls "$PACKAGE" 2>/dev/null || echo "Package not found in npm"
echo "---"
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Storybook:
needs: 'CI'
uses: VirtoCommerce/vc-shell/.github/workflows/storybook-ci.yml@main
with:
event_name: ${{ github.event_name }}
secrets:
VCMP_PLATFORM_TOKEN: ${{ secrets.VCMP_PLATFORM_TOKEN }}