-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (108 loc) · 4.45 KB
/
release.yml
File metadata and controls
127 lines (108 loc) · 4.45 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
name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
ref:
description: 'Branch or tag to release (e.g., release/0.28.1)'
required: true
type: string
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout Repo
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ inputs.ref || '' }}
- name: Setup Node.js 24.x
uses: actions/setup-node@v6
with:
node-version: '24.14.1'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci --include=optional --ignore-scripts
- name: Check if version changed
id: version-check
run: |
# Get current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
# Check if this is a manual dispatch with ref input
if [ -n "${{ inputs.ref }}" ]; then
echo "Manual release triggered for ref: ${{ inputs.ref }}"
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Version to release: $CURRENT_VERSION"
else
# Normal flow: compare with last tag
# Get last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
LAST_VERSION=${LAST_TAG#v}
echo "Current version: $CURRENT_VERSION"
echo "Last released version: $LAST_VERSION"
if [ "$CURRENT_VERSION" != "$LAST_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Version changed from $LAST_VERSION to $CURRENT_VERSION"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "No version change detected"
fi
fi
- name: Build and test
if: steps.version-check.outputs.changed == 'true'
run: |
npm run build
npm run test
- name: Determine npm tag
if: steps.version-check.outputs.changed == 'true'
id: npm-tag
run: |
CURRENT_VERSION="${{ steps.version-check.outputs.version }}"
# Get the latest version from npm registry
LATEST_VERSION=$(npm view @remoteoss/remote-flows dist-tags.latest 2>/dev/null || echo "0.0.0")
echo "Current version to publish: $CURRENT_VERSION"
echo "Latest version on npm: $LATEST_VERSION"
# Compare versions using sort -V (version sort)
# If current version is less than latest, use legacy tag
if [ "$(printf '%s\n' "$CURRENT_VERSION" "$LATEST_VERSION" | sort -V | head -n1)" = "$CURRENT_VERSION" ] && [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
echo "tag=legacy" >> $GITHUB_OUTPUT
echo "Publishing with --tag legacy (older than current latest)"
else
echo "tag=" >> $GITHUB_OUTPUT
echo "Publishing with default tag (will become latest)"
fi
- name: Publish to npm
if: steps.version-check.outputs.changed == 'true'
run: |
if [ -n "${{ steps.npm-tag.outputs.tag }}" ]; then
npm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }}
else
npm publish --provenance --access public
fi
- name: Create git tag
if: steps.version-check.outputs.changed == 'true'
run: |
git tag v${{ steps.version-check.outputs.version }}
git push origin v${{ steps.version-check.outputs.version }}
- name: Create GitHub release
if: steps.version-check.outputs.changed == 'true'
run: |
# Get the changelog content for this version
CHANGELOG_CONTENT=$(awk '/^## [0-9]/ {if (p) exit} /^## '"${{ steps.version-check.outputs.version }}"'$/ {p=1; next} p' CHANGELOG.md)
gh release create v${{ steps.version-check.outputs.version }} \
--title "v${{ steps.version-check.outputs.version }}" \
--notes "$CHANGELOG_CONTENT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: No release needed
if: steps.version-check.outputs.changed == 'false'
run: |
echo "No version change detected. Skipping release."