-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (69 loc) · 2.7 KB
/
semantic-release-ci.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Semantic Release CI
on:
push:
branches:
- main
paths-ignore:
- "**/*.md"
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm install semantic-release @semantic-release/exec @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/github
- name: Run semantic-release and extract changelog
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Generate changelog with Markdown formatting by running semantic-release in dry-run mode
npx semantic-release --dry-run | tee semantic_output.log
# Capture the changelog markdown from semantic-release output for the latest version
changelog=$(awk '/Release note for version/ {flag=1; next} flag && !/^#[^#]/' semantic_output.log)
# Insert "v" in front of version numbers in `##` headers
changelog=$(echo "$changelog" | sed -E 's/^## ([0-9]+\.[0-9]+\.[0-9]+)/## v\1/')
# Trim leading spaces before each bullet point (lines starting with `* `)
changelog=$(echo "$changelog" | sed -E 's/^[[:space:]]+\*/\*/')
# Write the cleaned changelog to a file
echo "$changelog" > changelog.md
# Set the changelog as an output variable for use in the GitHub release step
echo "changelog<<EOF" >> $GITHUB_ENV
echo "$changelog" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Push new tag
if: ${{ steps.release.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="${{ steps.release.outputs.version }}"
# Create and push the new tag
git tag "$version"
git push origin "$version"
- name: Create GitHub Release with Changelog
if: ${{ steps.release.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="${{ steps.release.outputs.version }}"
tag_name="$version"
# Read changelog from the markdown file to preserve formatting
release_notes=$(<changelog.md)
# Create GitHub release with formatted markdown changelog
gh release create "$tag_name" \
--title "$version" \
--notes "$release_notes" \
--target main \
--draft