-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (82 loc) · 3.17 KB
/
Copy pathrelease.yml
File metadata and controls
91 lines (82 loc) · 3.17 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
name: Tag and Release
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from dbt_project.yml
id: version
run: |
VERSION=$(grep "^version:" dbt_project.yml | sed "s/version: *//;s/['\"]//g" | tr -d '\r\n ')
if [ -z "$VERSION" ]; then
echo "::error::Could not extract version from dbt_project.yml"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Detected version: $VERSION"
- name: Check if tag already exists
id: check_tag
run: |
if git rev-parse --verify "refs/tags/${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Tag ${{ steps.version.outputs.version }} already exists — skipping release."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Tag ${{ steps.version.outputs.version }} does not exist — will create release."
fi
- name: Extract changelog for this version
if: steps.check_tag.outputs.exists == 'false'
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
# Use Python for exact string matching (no regex dot issues)
# Outputs: release title (from header) and release notes (body)
# Changelog headers use 'v' prefix (e.g. ## v1.0.4)
python3 -c "
import sys
version = 'v' + sys.argv[1]
header_prefix = '## ' + version
found = False
title = ''
lines = []
for line in open('CHANGELOG.md'):
stripped = line.rstrip()
if stripped.startswith('## '):
if found:
break
if stripped == header_prefix or stripped.startswith(header_prefix + ' ') or stripped.startswith(header_prefix + '\t'):
found = True
title = stripped[3:].strip()
continue
if found:
lines.append(line.rstrip())
if not found:
print(f'::error::No changelog entry found for version {version}', file=sys.stderr)
sys.exit(1)
print('TITLE=' + title)
with open('/tmp/release_notes.md', 'w') as f:
f.write('\n'.join(lines))
" "$VERSION" > /tmp/release_meta.txt
TITLE=$(grep '^TITLE=' /tmp/release_meta.txt | cut -d= -f2-)
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
echo "Release title: $TITLE"
echo "Release notes:"
cat /tmp/release_notes.md
- name: Create GitHub release
if: steps.check_tag.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ steps.version.outputs.version }}" \
--title "${{ steps.changelog.outputs.title }}" \
--notes-file /tmp/release_notes.md \
--target "${{ github.sha }}"