-
Notifications
You must be signed in to change notification settings - Fork 2
151 lines (126 loc) · 5.21 KB
/
release.yml
File metadata and controls
151 lines (126 loc) · 5.21 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: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (leave empty to use package.json version)'
required: false
type: string
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Install dependencies
run: pnpm install
- name: Get version from package.json
id: package-version
run: |
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=$(node -p "require('./package.json').version")
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Parse version with SemVer
id: semver
run: |
VERSION="${{ steps.package-version.outputs.version }}"
# Remove 'v' prefix if present
VERSION=${VERSION#v}
# Parse semantic version
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)
PATCH=$(echo $VERSION | cut -d. -f3)
echo "major=$MAJOR" >> $GITHUB_OUTPUT
echo "minor=$MINOR" >> $GITHUB_OUTPUT
echo "patch=$PATCH" >> $GITHUB_OUTPUT
echo "full=$VERSION" >> $GITHUB_OUTPUT
echo "Parsed version: $VERSION (Major: $MAJOR, Minor: $MINOR, Patch: $PATCH)"
- name: Build action
run: pnpm run build
- name: Create release archive
run: |
mkdir -p release-assets
cp -r dist/ action.yml package.json pnpm-lock.yaml release-assets/
tar -czf action-v${{ steps.semver.outputs.full }}.tar.gz -C release-assets .
mv action-v${{ steps.semver.outputs.full }}.tar.gz release-assets/
- name: Delete existing releases (cleanup)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get all releases
RELEASES=$(gh api repos/${{ github.repository }}/releases --jq '.[].tag_name')
# Delete existing major version release only
MAJOR_TAG="v${{ steps.semver.outputs.major }}"
for tag in $RELEASES; do
if [[ "$tag" == "$MAJOR_TAG" ]]; then
echo "Deleting existing release: $tag"
gh release delete "$tag" --yes || true
git push --delete origin "$tag" || true
fi
done
- name: Commit built files for tags
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Force add the built dist/ folder to git (override .gitignore)
git add -f dist/
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Build dist for release v${{ steps.semver.outputs.full }}"
fi
- name: Create/Update major version tag
run: |
MAJOR_TAG="v${{ steps.semver.outputs.major }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create or update the major version tag
git tag -f "$MAJOR_TAG"
git push origin "$MAJOR_TAG" --force
# Skip creating full version tags to avoid MODULE_NOT_FOUND errors
# Users should only reference the major version tag (e.g., @v3)
# which contains the built dist files
- name: Create GitHub Release (Major Version)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
MAJOR_TAG="v${{ steps.semver.outputs.major }}"
FULL_VERSION="${{ steps.semver.outputs.full }}"
gh release create "$MAJOR_TAG" \
--title "Release $MAJOR_TAG (v$FULL_VERSION)" \
--notes "Auto-generated release for major version ${{ steps.semver.outputs.major }} (v$FULL_VERSION)" \
--latest \
release-assets/action-v$FULL_VERSION.tar.gz
# Skip creating full version releases - only major version releases are created
# This prevents users from referencing problematic tags without built files
- name: Update action.yml in release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# The built action is now available in the release artifacts
echo "Release completed successfully!"
echo "Major version tag: v${{ steps.semver.outputs.major }}"
echo "Users should reference this action as:"
echo " - uses: ${{ github.repository }}@v${{ steps.semver.outputs.major }}"
echo ""
echo "Note: Full version tags (v${{ steps.semver.outputs.full }}) are not created"
echo "to prevent MODULE_NOT_FOUND errors. Always use major version tags."