-
-
Notifications
You must be signed in to change notification settings - Fork 78
89 lines (74 loc) · 2.86 KB
/
Copy pathrelease.yml
File metadata and controls
89 lines (74 loc) · 2.86 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
name: Release to npm
on:
push:
tags:
- "v*" # Trigger only on version tags
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write # Required for creating releases
packages: write # Required for publishing packages
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for tag information
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm install -g pnpm && pnpm install --no-frozen-lockfile
- name: Build project
run: pnpm run build
- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Update package.json version
run: |
VERSION="${{ steps.get_version.outputs.VERSION }}"
npm version $VERSION --no-git-tag-version --allow-same-version
- name: Generate Release Notes
id: release_notes
run: |
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
# If no previous tag exists, get all PRs
SINCE_DATE="1970-01-01"
else
# Get date of previous tag
SINCE_DATE=$(git log -1 --format=%aI $PREVIOUS_TAG)
fi
# Use GitHub API to get PRs merged since the last tag
REPO_NAME="${GITHUB_REPOSITORY}"
CHANGELOG=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${REPO_NAME}/pulls?state=closed&sort=updated&direction=desc&per_page=100" | \
jq -r ".[] | select(.merged_at != null) | select(.merged_at > \"${SINCE_DATE}\") | \"* \(.title) ([#\(.number)](\(.html_url))) by @\(.user.login)\"")
# Save changelog to a file with proper escaping
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Publish to npm
run: pnpm publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: "Release v${{ steps.get_version.outputs.VERSION }}"
body: |
## What's Changed
${{ steps.release_notes.outputs.CHANGELOG }}
## Installation
```bash
pnpm add @chaibuilder/sdk@${{ steps.get_version.outputs.VERSION }}
```
draft: false
prerelease: false
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}