-
Notifications
You must be signed in to change notification settings - Fork 86
183 lines (158 loc) · 6.37 KB
/
publish.yml
File metadata and controls
183 lines (158 loc) · 6.37 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
name: 🚀 Publish ExTester
on:
workflow_dispatch:
inputs:
tag:
description: "Version tag to publish (vX.X.X)"
required: true
skipPublish:
description: "Skip publish into NPM registry (npmjs)"
default: false
type: boolean
skipPackageJsonMatch:
description: "Skip tag validation with package.json (testing)"
default: false
type: boolean
draft:
description: "Publish GH release as draft"
default: false
type: boolean
permissions:
contents: write
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: 🔖 Show input tag
run: echo "Publishing version ${{ github.event.inputs.tag }}"
- name: 👷🏻 Checkout Repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: ✅ Verify Git tag exists
run: |
git fetch --tags
if ! git rev-parse "refs/tags/${{ github.event.inputs.tag }}" >/dev/null 2>&1; then
echo "❌ Tag '${{ github.event.inputs.tag }}' does not exist!"
exit 1
fi
- name: ✅ Validate and extract tag
run: |
TAG=${{ github.event.inputs.tag }}
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Invalid tag format: $TAG. Use format like 'v1.2.3'"
exit 1
fi
echo "TAG=$TAG" >> $GITHUB_ENV
echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: ✅ Ensure tag matches package.json version
if: ${{ github.event.inputs.skipPackageJsonMatch != 'true' }}
working-directory: packages/extester
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
TAG_VERSION=${VERSION}
echo "Package version: $PKG_VERSION"
echo "Input tag version: $TAG_VERSION"
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
echo "❌ Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)!"
exit 1
fi
- name: 🔸 Get vscode-extension-tester version
working-directory: packages/extester
run: |
VERSION=$(node -p "require('./package.json').version")
echo "EXTESTER_VERSION=${VERSION}" >> $GITHUB_ENV
- name: 🔸 Get @redhat-developer/page-objects version
working-directory: packages/page-objects
run: |
VERSION=$(node -p "require('./package.json').version")
echo "PAGE_OBJECTS_VERSION=${VERSION}" >> $GITHUB_ENV
- name: 🔸 Get @redhat-developer/locators version
working-directory: packages/locators
run: |
VERSION=$(node -p "require('./package.json').version")
echo "LOCATORS_VERSION=${VERSION}" >> $GITHUB_ENV
- name: ⚙️ Set up Node.js
uses: actions/setup-node@v6
with:
node-version: lts/*
- name: 📦 Install GitHub CLI
run: sudo apt-get install -y gh
- name: 🔧 Install deps and build
run: |
npm ci
npm run build
- name: 📝 Generate changelog
run: |
PREV_TAG=$(git tag --list "v*" --sort=-creatordate | grep -v "$TAG" | head -n 1)
echo "Comparing changes from $PREV_TAG to $TAG"
if [ -z "$PREV_TAG" ]; then
LOG=$(git log "$TAG" --reverse --pretty='format:%s by **%aN** in %H' -- . | grep -vE "(runner)")
[ -z "$LOG" ] && LOG=$(git log --reverse --pretty='format:%s by **%aN** in %H' -- . | grep -vE "(runner)")
else
LOG=$(git log "$PREV_TAG..$TAG" --pretty='format:%s by **%aN** in %H' -- . | grep -vE "(runner)")
fi
if [ -z "$LOG" ]; then
LOG="Initial release (first tag)"
fi
# Helper to format sections
format_section() {
local pattern="$1"
local title="$2"
local content=$(echo "$LOG" | grep -iE "$pattern" || true)
if [[ -n "$content" ]]; then
echo "### $title"
echo "$content"
echo
fi
}
format_other_section() {
local title="🧼 Other Changes"
local content=$(echo "$LOG" | grep -vE "^(feat|feature|fix|test|chore|refactor|internal|ci|docs|deps|dependencies|build)" || true)
if [[ -n "$content" ]]; then
echo "### $title"
echo "$content"
echo
fi
}
{
echo "## What's Changed"
format_section '^break|^breaking' "⚠️ Breaking"
format_section '^feat|^feature' "🚀 Features"
format_section '^fix' "🚫 Bugs"
format_section '^test' "🔎 Tests"
format_section '^chore|^refactor|^internal|^ci|^docs' "🔧 Maintenance"
format_section '^deps|^dependencies|^build' "📦 Dependencies"
format_other_section
} > CHANGELOG.md
echo "Generated CHANGELOG.md"
cat CHANGELOG.md
- name: 🔧 Config .npmrc
if: ${{ github.event.inputs.skipPublish != 'true' }}
run: |
{
echo "registry=https://registry.npmjs.com"
echo "//registry.npmjs.com/:_authToken=\${NPM_TOKEN}"
} > .npmrc
- name: 🚀 Publish to NPM registry (npmjs)
if: ${{ github.event.inputs.skipPublish != 'true' }}
run: npm run publish -- --yes
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
- name: 📣 Add summary
if: ${{ github.event.inputs.skipPublish != 'true' }}
run: |
echo "#### ✅ Published \`vscode-extension-tester-${EXTESTER_VERSION}\`" >> $GITHUB_STEP_SUMMARY
echo "#### ✅ Published \`@redhat-developer/page-objects-${PAGE_OBJECTS_VERSION}\`" >> $GITHUB_STEP_SUMMARY
echo "#### ✅ Published \`@redhat-developer/locators-${LOCATORS_VERSION}\`" >> $GITHUB_STEP_SUMMARY
- name: 🚀 Publish GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event.inputs.draft }}" == "true" ]; then
echo "Publishing release as draft..."
gh release create "$TAG" --title "v${VERSION}" --notes-file CHANGELOG.md --draft
else
echo "Publishing release as a regular release..."
gh release create "$TAG" --title "v${VERSION}" --notes-file CHANGELOG.md
fi