This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
50 lines (46 loc) · 1.73 KB
/
auto-release.yml
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
name: Release automatically
on:
pull_request:
branches:
- main
types:
- closed
jobs:
release-from-pr:
name: Release from a PR that is marked with [new release]
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'new release')
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Fetch the version number 📝
id: fetch-version
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const package = require(`${process.env.GITHUB_WORKSPACE}/attractions/package.json`);
return `v${package.version}`;
- name: Fetch the changelog 📝
id: fetch-changelog
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const changelog = require('fs').readFileSync('CHANGELOG.md', { encoding: 'utf-8' }).split('\n');
const start = changelog.findIndex(line => line.startsWith('## '));
const end = changelog.findIndex((line, index) => line.startsWith('## ') && index > start);
return changelog.slice(start + 1, end).join('\n').trim();
- name: Create a release 🔖
uses: actions/github-script@v7
env:
CHANGELOG: ${{ steps.fetch-changelog.outputs.result }}
with:
script: |
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "${{ steps.fetch-version.outputs.result }}",
name: "${{ steps.fetch-version.outputs.result }}",
body: process.env.CHANGELOG,
});