-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (117 loc) · 4.62 KB
/
Copy pathcreate-release-pr.yml
File metadata and controls
130 lines (117 loc) · 4.62 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
name: Create Release Pull Request
description: Create a pull request to release a new version
on:
workflow_dispatch:
inputs:
version:
description: 'Version type'
required: true
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
pull-requests: write
jobs:
create-release-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: 'lts/*'
check-latest: true
package-manager-cache: false
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
with:
run_install: |
- recursive: true
args: [--frozen-lockfile]
# No need to install dependencies - npm version works without them
- name: Version bump
id: version
run: |
VERSION=$(pnpm version "$VERSION_TYPE" --no-git-tag-version)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
pnpm --recursive exec pnpm pkg set version=$(node -p "JSON.parse(fs.readFileSync('package.json', 'utf8')).version")
pnpm install --no-rozen-lockfile
env:
VERSION_TYPE: ${{ github.event.inputs.version }}
- uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Get release notes
id: release-notes
run: |
# Get the default branch
DEFAULT_BRANCH=$(gh api "repos/$GITHUB_REPOSITORY" --jq '.default_branch')
# Get the latest release tag using GitHub API
# Use the exit code to determine if a release exists
if LAST_TAG=$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq '.tag_name' 2>/dev/null); then
echo "Previous release found: $LAST_TAG"
else
LAST_TAG=""
echo "No previous releases found - this will be the first release"
fi
# Generate release notes - only include previous_tag_name if we have a valid previous tag
echo "Generating release notes for tag: $VERSION"
if [ -n "$LAST_TAG" ]; then
echo "Using previous tag: $LAST_TAG"
RELEASE_NOTES=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
-f "tag_name=$VERSION" \
-f "target_commitish=$DEFAULT_BRANCH" \
-f "previous_tag_name=$LAST_TAG" \
--jq '.body')
else
echo "Generating notes from all commits"
RELEASE_NOTES=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/$GITHUB_REPOSITORY/releases/generate-notes" \
-f "tag_name=$VERSION" \
-f "target_commitish=$DEFAULT_BRANCH" \
--jq '.body')
fi
# Set release notes as environment variable
echo "RELEASE_NOTES<<EOF" >> "$GITHUB_OUTPUT"
echo "$RELEASE_NOTES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
env:
RELEASE_NOTES: ${{ steps.release-notes.outputs.RELEASE_NOTES }}
VERSION: ${{ steps.version.outputs.version }}
with:
branch: release/${{ steps.version.outputs.version }}
delete-branch: true
title: "Release ${{ steps.version.outputs.version }}"
body: |
${{ env.RELEASE_NOTES }}
commit-message: "chore: release ${{ steps.version.outputs.version }}"
labels: |
Type: Release
assignees: ${{ github.actor }}
token: ${{ steps.app-token.outputs.token }}
draft: true