forked from Heliobond/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (125 loc) · 4.47 KB
/
Copy pathrelease.yml
File metadata and controls
143 lines (125 loc) · 4.47 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
name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
version_bump:
description: "Version bump type"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
issues: write
pull-requests: write
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build
run: bun run build
- name: Test
run: bun run test
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Release (semantic-release)
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
- name: Bump version (manual)
if: github.event_name == 'workflow_dispatch'
id: bump
run: |
NEW_VERSION=$(npm version "${{ github.event.inputs.version_bump }}" --no-git-tag-version)
echo "version=${NEW_VERSION#v}" >> "$GITHUB_OUTPUT"
- name: Update CHANGELOG (manual)
if: github.event_name == 'workflow_dispatch'
env:
VERSION: ${{ steps.bump.outputs.version }}
run: |
node -e '
const fs = require("fs");
const version = process.env.VERSION;
const date = new Date().toISOString().slice(0, 10);
const path = "CHANGELOG.md";
let content = fs.existsSync(path)
? fs.readFileSync(path, "utf8")
: "# Changelog\n\n## [Unreleased]\n";
const heading = "## [Unreleased]";
const entry = "## [" + version + "] - " + date +
"\n\n### Changed\n- See commit history for details.\n";
content = content.includes(heading)
? content.replace(heading, heading + "\n\n" + entry)
: content + "\n" + entry;
fs.writeFileSync(path, content);
'
- name: Extract release notes from CHANGELOG
if: github.event_name == 'workflow_dispatch'
env:
VERSION: ${{ steps.bump.outputs.version }}
run: |
node -e '
const fs = require("fs");
const version = process.env.VERSION;
const content = fs.readFileSync("CHANGELOG.md", "utf8");
const heading = "## [" + version + "]";
const start = content.indexOf(heading);
const rest = content.slice(start);
const nextHeadingIdx = rest.indexOf("\n## [", heading.length);
const section = nextHeadingIdx === -1 ? rest : rest.slice(0, nextHeadingIdx);
fs.writeFileSync("RELEASE_NOTES.md", section.trim() + "\n");
'
- name: Commit version bump and CHANGELOG
if: github.event_name == 'workflow_dispatch'
env:
VERSION: ${{ steps.bump.outputs.version }}
run: |
git add package.json CHANGELOG.md
git commit -m "chore(release): v${VERSION}"
- name: Create git tag
if: github.event_name == 'workflow_dispatch'
env:
VERSION: ${{ steps.bump.outputs.version }}
run: git tag -a "v${VERSION}" -m "Release v${VERSION}"
- name: Push commit and tag
if: github.event_name == 'workflow_dispatch'
run: git push origin HEAD --follow-tags
- name: Create GitHub release
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.bump.outputs.version }}
run: |
gh release create "v${VERSION}" \
--title "v${VERSION}" \
--notes-file RELEASE_NOTES.md
- name: Trigger deployment
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.bump.outputs.version }}
run: |
gh api repos/${{ github.repository }}/dispatches \
-f event_type=deploy \
-f "client_payload[version]=v${VERSION}" \
-f "client_payload[ref]=${{ github.sha }}"