-
Notifications
You must be signed in to change notification settings - Fork 1
150 lines (131 loc) · 5.76 KB
/
Copy pathrelease.yml
File metadata and controls
150 lines (131 loc) · 5.76 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
name: Release
on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 10.20.0
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build packages
run: pnpm build
- name: Stage dist folder (if changed)
id: stage_dist
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add packages/scripts/dist/
if git diff --staged --quiet; then
echo "No changes to dist folder"
echo "has_dist_changes=false" >> $GITHUB_OUTPUT
else
echo "Dist folder has changes"
echo "has_dist_changes=true" >> $GITHUB_OUTPUT
fi
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
# Don't publish to npm - we only use GitHub releases
# Using a no-op command since package is marked private
publish: echo "Package is private, skipping npm publish"
version: pnpm changeset version
commit: 'chore: version packages'
title: 'chore: version packages'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create PR for dist changes (if no changesets PR was created)
if: steps.stage_dist.outputs.has_dist_changes == 'true' && steps.changesets.outputs.pullRequestNumber == ''
run: |
# Re-stage dist changes (in case changesets action reset staging)
git add packages/scripts/dist/
if ! git diff --staged --quiet; then
echo "Creating PR for dist changes"
BRANCH_NAME="chore/build-scripts-$(date +%s)"
git checkout -b "$BRANCH_NAME"
git commit -m "chore: build scripts package"
git push origin "$BRANCH_NAME"
gh pr create \
--title "chore: build scripts package" \
--body "Automated build of scripts package dist folder." \
--base main \
--head "$BRANCH_NAME"
else
echo "Dist changes were already committed"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if version was updated
if: steps.changesets.outputs.pullRequestNumber == ''
id: check_version
run: |
# Get current version from package.json
CURRENT_VERSION=$(grep -o '"version": "[^"]*"' packages/scripts/package.json | cut -d'"' -f4)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Check if there's already a tag for this version
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Tag v$CURRENT_VERSION already exists, skipping release"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "New version detected: $CURRENT_VERSION"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
- name: Get Scripts Package Version
if: steps.changesets.outputs.pullRequestNumber == '' && steps.check_version.outputs.should_release == 'true'
id: version
run: |
VERSION="${{ steps.check_version.outputs.current_version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
echo "Released version: $VERSION"
- name: Create Git Tag
if: steps.changesets.outputs.pullRequestNumber == '' && steps.check_version.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
- name: Create GitHub Release for Scripts
if: steps.changesets.outputs.pullRequestNumber == '' && steps.check_version.outputs.should_release == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Scripts Release ${{ steps.version.outputs.tag }}
body: |
Automated release of scripts package.
**Version:** ${{ steps.version.outputs.version }}
**jsdelivr URLs:**
- Latest from this version: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.tag }}/packages/scripts/dist/index.js`
- Latest from major version: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.version }}.*/packages/scripts/dist/index.js`
- Specific commit: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ github.sha }}/packages/scripts/dist/index.js`
**Usage in HTML:**
```html
<script defer src="https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.tag }}/packages/scripts/dist/index.js"></script>
```
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Scripts Artifacts
if: steps.changesets.outputs.pullRequestNumber == '' && steps.check_version.outputs.should_release == 'true'
uses: actions/upload-artifact@v4
with:
name: scripts-dist
path: packages/scripts/dist/**
retention-days: 90