forked from winterbe/sequency
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (75 loc) · 3.06 KB
/
Copy pathpublish.yml
File metadata and controls
94 lines (75 loc) · 3.06 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
name: Publish
on:
push:
branches:
- master
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Ensure npm 11.5.1 or later
run: npm install -g npm@latest
- name: Enable Corepack
run: corepack enable
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build project
run: yarn build
- name: Publish to npm
run: npm publish --access public
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get version from package.json (before restoring original name)
VERSION=$(node -p "require('./package.json').version")
VERSION=${VERSION#v}
TAG_NAME="v$VERSION"
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Create git tag if it doesn't exist
if ! git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
fi
# Create release body with installation instructions
PACKAGE_NAME=$(node -p "require('./package.json').name")
RELEASE_BODY="Release $TAG_NAME\n\nInstall: \`npm install $PACKAGE_NAME@$VERSION\`\n\nAdd to package.json: \`\"$PACKAGE_NAME\": \"$VERSION\"\`"
RELEASE_BODY_JSON=$(echo "$RELEASE_BODY" | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
# Create GitHub release using GitHub API
RELEASE_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/releases" \
-d "{\"tag_name\":\"$TAG_NAME\",\"name\":\"$TAG_NAME\",\"body\":\"$RELEASE_BODY_JSON\",\"draft\":false,\"prerelease\":false}")
HTTP_CODE=$(echo "$RELEASE_RESPONSE" | tail -n1)
if [ "$HTTP_CODE" = "201" ]; then
echo "Release $TAG_NAME created successfully"
elif [ "$HTTP_CODE" = "422" ]; then
echo "Release $TAG_NAME already exists"
else
echo "Failed to create release. HTTP code: $HTTP_CODE"
echo "$RELEASE_RESPONSE"
fi
- name: Increment version
run: |
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Increment patch version
npm version patch --no-git-tag-version
# Commit and push version increment
git add package.json
git commit -m "Incremented version after release"
git push