-
Notifications
You must be signed in to change notification settings - Fork 461
118 lines (101 loc) · 4.14 KB
/
draft_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
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
name: Create draft release
on:
pull_request:
branches:
- test_next
jobs:
draft_release:
name: Draft release
if: startsWith(github.head_ref, 'release/')
runs-on: ubuntu-latest
steps:
- name: Checkout files
uses: actions/checkout@v4
with:
fetch-tags: true
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Fetch history and git
run: |
git fetch --prune --unshallow --tags
# git fetch --prune --unshallow --tags
- name: Install
run: npm ci
- name: Build and add dist files
run: |
rm -rf dist/
npm run build:content
git add package* dist/
- name: Parse changelog
id: get_changelog
# when trying to use 'npm changelog' below it put escaped slash characters in the output, so opted for raw git log command
# also multiline output here https://stackoverflow.com/questions/59191913/how-do-i-get-the-output-of-a-specific-step-in-github-actions
run: |
{
echo 'changelog_text<<EOF'
git log $(git describe --tags --abbrev=0)..HEAD --oneline --format="* %h %s (%an)"
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Get previous tag
id: get_previous_tag
run: |
echo previous_tag=$(git describe --tags --abbrev=0) >> "$GITHUB_OUTPUT"
# or this for get previous
# run: |
# name=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | tail -2 | head -1)
# echo "previousTag: $name"
# echo "previousTag=$name" >> $GITHUB_ENV
- name: Extract version from ref name
id: extract_version
run: |
VERSION=$(echo "${{ github.ref_name }}" | grep -oP 'v\d+\.\d+\.\d+' || true)
if [[ -n "$VERSION" ]]; then
echo "versionFromBranch=$VERSION" >> "$GITHUB_OUTPUT"
fi
shell: bash
- name: Determine version bump
if: ${{ !steps.extract_version.outputs.versionFromBranch }}
id: determine_bump
# https://unix.stackexchange.com/questions/736318/make-grep-exit-1-if-found-and-exit-0-if-not-found
run: |
echo "${{ steps.get_changelog.outputs.changelog_text }}" | grep -q "feat:" && echo "isMinor=true" >> "$GITHUB_OUTPUT" || echo "isMinor=false" >> "$GITHUB_OUTPUT"
echo "${{ steps.get_changelog.outputs.changelog_text }}" | grep -q "\!:" && echo "isBreakingChange=true" >> "$GITHUB_OUTPUT" || echo "isBreakingChange=false" >> "$GITHUB_OUTPUT"
shell: bash
- name: Config git user
run: |
git config user.name "${{ github.actor}}"
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
- name: Bump version
id: bump_version
run: |
npm version ${{
steps.extract_version.outputs.versionFromBranch ||
(steps.determine_bump.outputs.isBreakingChange=='true' && 'major') ||
(steps.determine_bump.outputs.isMinor=='true' && 'minor') ||
'patch'
}} \
--force -m "chore(release): Bumps version to v%s and updates dist files"
echo updated_version=$(node -p "require('./package.json').version") >> "$GITHUB_OUTPUT"
- name: Build notes
id: build_notes
uses: mikepenz/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
owner: Laboratoria
fromTag: main
toTag: next
fetchViaCommits: true
commitMode: true
- name: Make release draft
id: release_draft
run: |
echo ${{ steps.bump_version.outputs.updated_version }}
echo ${{ steps.build_notes.outputs.changelog }}
# gh release create ${{ steps.bump_version.outputs.updated_version }} \
# --repo="$GITHUB_REPOSITORY" \
# --title="${GITHUB_REPOSITORY#*/} ${{ steps.bump_version.outputs.updated_version }}" \
# --notes ${{steps.build_notes.outputs.changelog}} \
# --draft