-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (69 loc) · 2.67 KB
/
ci.yaml
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
name: CI
on:
push:
branches:
- main
jobs:
Release:
name: Release
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
env:
CHANGELOG_FILE: "CHANGELOG.md"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version
id: get_version
run: |
RELEASE_VERSION=$(cat modular_cli/version.py | awk -F"__version__ =" {'print $2'} | sed -e 's|["'\'' '^',]||g' | xargs)
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "Name ${{ github.ref_name }}. Version $RELEASE_VERSION"
- name: Fetching previous version
id: get_previous_version
run: |
git fetch --tags
PREVIOUS_VERSION=$(git tag --sort=-creatordate | sed -n '1p' | sed 's/^v//')
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV
echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
echo "Previous version: $PREVIOUS_VERSION"
- name: Fetching release notes
id: release_notes
run: |
extract_release_notes() {
changelog_file=$1
current_version=$2
previous_version=$3
# Escape dots in version for regex
current_version_escaped=$(echo "$current_version" | sed 's/\./\\./g')
previous_version_escaped=$(echo "$previous_version" | sed 's/\./\\./g')
# Extract release notes
release_notes=$(awk "/# \[$current_version_escaped\]/,/# \[$previous_version_escaped\]/" "$changelog_file" | sed '$d')
echo "$release_notes"
}
RELEASE_NOTES=$(extract_release_notes ${{ env.CHANGELOG_FILE }} ${{ steps.get_version.outputs.release_version }} ${{ steps.get_previous_version.outputs.previous_version }})
echo "Release notes:"
echo "$RELEASE_NOTES"
echo "$RELEASE_NOTES" > release_notes.md
- name: Create tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.get_version.outputs.release_version }}',
sha: context.sha
})
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_version.outputs.release_version }}
name: ${{ steps.get_version.outputs.release_version }}
body_path: release_notes.md
prerelease: false
draft: false
make_latest: true