-
Notifications
You must be signed in to change notification settings - Fork 263
151 lines (131 loc) · 6.05 KB
/
Copy pathpublish-2nd-gen.yml
File metadata and controls
151 lines (131 loc) · 6.05 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
name: Publish 2nd-gen
on:
workflow_dispatch:
inputs:
tag:
description: 'NPM dist-tag (e.g., latest, beta, snapshot)'
required: false
default: 'snapshot-test'
push:
branches:
- SWC-1405
paths:
- '2nd-gen/**'
- '.changeset/**'
jobs:
publish:
# Temporarily disabled - change to 'true' to re-enable
if: true
runs-on: ubuntu-latest
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup job and install dependencies
uses: ./.github/actions/setup-job
- name: Set Git identity
run: |
git config --global user.email "support+actions@github.com"
git config --global user.name "github-actions-bot"
- name: Extract tag from commit message or use default
id: extract-tag
run: |
# Get tag from workflow_dispatch input (if manually triggered)
WORKFLOW_TAG="${{ github.event.inputs.tag }}"
# If not manually triggered, try to extract from commit message
if [ -z "$WORKFLOW_TAG" ]; then
COMMIT_MSG="${{ github.event.head_commit.message }}"
# Look for [tag:xxx] pattern in commit message
if echo "$COMMIT_MSG" | grep -qE '\[tag:([a-zA-Z0-9-]+)\]'; then
WORKFLOW_TAG=$(echo "$COMMIT_MSG" | grep -oE '\[tag:([a-zA-Z0-9-]+)\]' | sed 's/\[tag://;s/\]//')
else
# Default to snapshot-test if no tag specified
WORKFLOW_TAG="snapshot-test"
fi
fi
echo "tag=$WORKFLOW_TAG" >> $GITHUB_OUTPUT
echo "Using npm tag: $WORKFLOW_TAG"
- name: Filter changesets for 2nd-gen
id: check-changesets
run: |
# Create backup directory
mkdir -p .changeset-backup
# Count total changesets
TOTAL=$(ls -1 .changeset/*.md 2>/dev/null | grep -v README | wc -l | tr -d ' ')
# Move 1st-gen only changesets to backup
MOVED=0
for file in .changeset/*.md; do
if [ -f "$file" ] && [ "$(basename "$file")" != "README.md" ]; then
# Back up changesets that mention 1st-gen packages (including core)
# Only keep changesets that mention @adobe/spectrum-wc for 2nd-gen
if grep -q "@spectrum-web-components/" "$file" && ! grep -q "@adobe/spectrum-wc" "$file"; then
mv "$file" .changeset-backup/
echo "Backed up: $(basename "$file")"
MOVED=$((MOVED + 1))
fi
fi
done
REMAINING=$((TOTAL - MOVED))
echo "Total changesets: $TOTAL"
echo "Backed up 1st-gen: $MOVED"
echo "Remaining for 2nd-gen: $REMAINING"
if [ "$REMAINING" -eq 0 ]; then
echo "has_changesets=false" >> $GITHUB_OUTPUT
else
echo "has_changesets=true" >> $GITHUB_OUTPUT
fi
- name: Build packages
if: steps.check-changesets.outputs.has_changesets == 'true'
run: yarn build:2nd-gen
- name: Version packages
if: steps.check-changesets.outputs.has_changesets == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.extract-tag.outputs.tag }}"
if [ "$TAG" == "latest" ]; then
yarn changeset version
else
yarn changeset version --snapshot $TAG
fi
- name: Update 2nd-gen version file
if: steps.check-changesets.outputs.has_changesets == 'true'
run: |
yarn genversion --source ./1st-gen/tools/base/package.json --semi --es6 --force ./2nd-gen/packages/core/shared/base/version.ts
- name: Refresh lockfile and rebuild
if: steps.check-changesets.outputs.has_changesets == 'true'
run: |
yarn install --refresh-lockfile
yarn build:2nd-gen
- name: Configure NPM authentication for Adobe namespace
if: steps.check-changesets.outputs.has_changesets == 'true'
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.ADOBE_BOT_NPM_TOKEN }}" > ~/.npmrc
- name: Publish to npm
if: steps.check-changesets.outputs.has_changesets == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.ADOBE_BOT_NPM_TOKEN }}
run: |
TAG="${{ steps.extract-tag.outputs.tag }}"
if [ "$TAG" == "latest" ]; then
yarn changeset publish --no-git-tag
else
yarn changeset publish --no-git-tag --tag $TAG
fi
- name: Restore backed up changesets
if: always()
run: |
if [ -d ".changeset-backup" ]; then
mv .changeset-backup/*.md .changeset/ 2>/dev/null || true
rmdir .changeset-backup 2>/dev/null || true
echo "Restored backed up changesets"
fi
- name: Commit and push changes
if: steps.check-changesets.outputs.has_changesets == 'true' && steps.extract-tag.outputs.tag == 'latest'
run: |
git add .
git commit -m "chore: release 2nd-gen packages #publish" || echo "No changes to commit"
git push