Skip to content

Commit 09c6e70

Browse files
jonhopper-dataengineersCortex Code
andauthored
Unknown Member Boolean Cast Fix (#30)
* Add release workflow to auto-tag and create GitHub releases Extracts version from dbt_project.yml on push to main, checks if the tag already exists, and creates a GitHub release with changelog notes. .... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code) Co-Authored-By: Cortex Code <noreply@snowflake.com> * Address review: remove PyYAML dependency and fail on missing changelog - Replace python3 yaml import with grep/sed to extract version from dbt_project.yml (PyYAML not guaranteed on ubuntu-latest runners) - Add error check if version extraction fails - Fail workflow with clear error if CHANGELOG.md has no entry for the detected version instead of silently creating an empty release .... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code) Co-Authored-By: Cortex Code <noreply@snowflake.com> --------- Co-authored-by: Cortex Code <noreply@snowflake.com>
1 parent 1d56973 commit 09c6e70

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Tag and Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Extract version from dbt_project.yml
22+
id: version
23+
run: |
24+
VERSION=$(grep "^version:" dbt_project.yml | sed "s/version: *['\"]\\(.*\\)['\"/]/\\1/")
25+
if [ -z "$VERSION" ]; then
26+
echo "::error::Could not extract version from dbt_project.yml"
27+
exit 1
28+
fi
29+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
30+
echo "Detected version: $VERSION"
31+
32+
- name: Check if tag already exists
33+
id: check_tag
34+
run: |
35+
if git rev-parse --verify "refs/tags/${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
36+
echo "exists=true" >> "$GITHUB_OUTPUT"
37+
echo "Tag ${{ steps.version.outputs.version }} already exists — skipping release."
38+
else
39+
echo "exists=false" >> "$GITHUB_OUTPUT"
40+
echo "Tag ${{ steps.version.outputs.version }} does not exist — will create release."
41+
fi
42+
43+
- name: Extract changelog for this version
44+
if: steps.check_tag.outputs.exists == 'false'
45+
id: changelog
46+
run: |
47+
VERSION="${{ steps.version.outputs.version }}"
48+
# Use Python for exact string matching (no regex dot issues)
49+
# Outputs: release title (from header) and release notes (body)
50+
python3 -c "
51+
import sys
52+
version = sys.argv[1]
53+
header_prefix = '## ' + version
54+
found = False
55+
title = ''
56+
lines = []
57+
for line in open('CHANGELOG.md'):
58+
stripped = line.rstrip()
59+
if stripped.startswith('## '):
60+
if found:
61+
break
62+
if stripped == header_prefix or stripped.startswith(header_prefix + ' ') or stripped.startswith(header_prefix + '\t'):
63+
found = True
64+
title = stripped[3:].strip()
65+
continue
66+
if found:
67+
lines.append(line.rstrip())
68+
if not found:
69+
print(f'::error::No changelog entry found for version {version}')
70+
sys.exit(1)
71+
print('TITLE=' + title)
72+
with open('/tmp/release_notes.md', 'w') as f:
73+
f.write('\n'.join(lines))
74+
" "$VERSION" > /tmp/release_meta.txt
75+
76+
TITLE=$(grep '^TITLE=' /tmp/release_meta.txt | cut -d= -f2-)
77+
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
78+
echo "Release title: $TITLE"
79+
echo "Release notes:"
80+
cat /tmp/release_notes.md
81+
82+
- name: Create GitHub release
83+
if: steps.check_tag.outputs.exists == 'false'
84+
env:
85+
GH_TOKEN: ${{ github.token }}
86+
run: |
87+
gh release create "${{ steps.version.outputs.version }}" \
88+
--title "${{ steps.changelog.outputs.title }}" \
89+
--notes-file /tmp/release_notes.md \
90+
--target "${{ github.sha }}"

0 commit comments

Comments
 (0)