-
-
Notifications
You must be signed in to change notification settings - Fork 425
160 lines (135 loc) Β· 5.49 KB
/
release-tag.yml
File metadata and controls
160 lines (135 loc) Β· 5.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
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
name: release-tag
on:
push:
branches:
- release
permissions: {}
jobs:
tag:
name: π·οΈ Tag release and create GitHub Release
runs-on: ubuntu-slim
if: github.repository == 'npmx-dev/npmx.dev'
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.next }}
skipped: ${{ steps.check.outputs.skip }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: π’ Determine next version
id: version
run: |
# Get the latest tag on this branch
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LATEST_TAG" ]; then
CURRENT_VERSION="0.0.0"
FROM_REF=$(git rev-list --max-parents=0 HEAD)
else
CURRENT_VERSION="${LATEST_TAG#v}"
FROM_REF="$LATEST_TAG"
fi
# Analyze conventional commits since last tag
HAS_BREAKING=$(git log "${FROM_REF}..HEAD" --format='%B' | grep -c 'BREAKING CHANGE\|!:' || true)
HAS_FEAT=$(git log "${FROM_REF}..HEAD" --oneline --no-merges | grep -cE '^[a-f0-9]+ feat(\(|:)' || true)
HAS_FIX=$(git log "${FROM_REF}..HEAD" --oneline --no-merges | grep -cE '^[a-f0-9]+ fix(\(|:)' || true)
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
if [ "$HAS_BREAKING" -gt 0 ] && [ "$MAJOR" -gt 0 ]; then
NEXT_VERSION="$((MAJOR + 1)).0.0"
elif [ "$HAS_FEAT" -gt 0 ]; then
NEXT_VERSION="${MAJOR}.$((MINOR + 1)).0"
elif [ "$HAS_FIX" -gt 0 ]; then
NEXT_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
else
# Only chore/docs/ci commits β still bump patch
NEXT_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
fi
echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "next=v${NEXT_VERSION}" >> "$GITHUB_OUTPUT"
echo "from=$FROM_REF" >> "$GITHUB_OUTPUT"
echo "Bumping from v${CURRENT_VERSION} to v${NEXT_VERSION}"
- name: π Check if tag already exists
id: check
env:
VERSION: ${{ steps.version.outputs.next }}
run: |
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Tag $VERSION already exists, skipping"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: π·οΈ Create and push tag
if: steps.check.outputs.skip == 'false'
env:
VERSION: ${{ steps.version.outputs.next }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
if: steps.check.outputs.skip == 'false'
with:
node-version: lts/*
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # 4e1c8eafbd745f64b1ef30a7d7ed7965034c486c
if: steps.check.outputs.skip == 'false'
name: π§ Install pnpm
- name: π¦ Install dependencies
if: steps.check.outputs.skip == 'false'
run: pnpm install --filter . --ignore-scripts
- name: π Generate release notes
if: steps.check.outputs.skip == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FROM_REF: ${{ steps.version.outputs.from }}
run: node scripts/release-notes.ts "$FROM_REF" > /tmp/release-notes.md
- name: π Create GitHub Release
if: steps.check.outputs.skip == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.next }}
run: |
gh release create "$VERSION" \
--notes-file /tmp/release-notes.md \
--title "$VERSION"
publish-connector:
name: π¦ Publish npmx-connector to npm
runs-on: ubuntu-slim
needs: tag
if: needs.tag.outputs.skipped == 'false'
permissions:
contents: read
id-token: write
environment: npm-publish
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: release
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: lts/*
registry-url: https://registry.npmjs.org
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # 4e1c8eafbd745f64b1ef30a7d7ed7965034c486c
name: π§ Install pnpm
with:
cache: false
- name: π¦ Install dependencies
run: pnpm install --filter npmx-connector...
- name: π’ Set connector version
env:
VERSION: ${{ needs.tag.outputs.version }}
run: |
# Strip the 'v' prefix for package.json
PKG_VERSION="${VERSION#v}"
cd cli
npm version "$PKG_VERSION" --no-git-tag-version
echo "Publishing npmx-connector@${PKG_VERSION}"
- name: ποΈ Build connector
run: pnpm --filter npmx-connector build
- name: π€ Publish to npm with provenance
# Uses OIDC trusted publishing β no NPM_TOKEN needed.
# Configure on npmjs.com: repo npmx-dev/npmx.dev, workflow release-tag.yml, environment npm-publish
run: npm publish --provenance --access public
working-directory: cli