generated from snowplow-incubator/dbt-template
-
Notifications
You must be signed in to change notification settings - Fork 6
118 lines (98 loc) · 4.64 KB
/
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
116
117
118
name: Release
#####
# Your changelog must be called CHANGELOG (no ext) and use the expected format (Package_Name tag_number (date) \n ------- \n changes...)
# Any text between the previous and new version in the changelog will be used as the text for the release, so use markdown syntax as needed
# The package_name variable must match what is in your CHANELOG and will be used as part of the release name
# This workflow maybe supports pre-release versions (with rc in the version) - but no promises.
#####
on:
push:
branches:
- main
env:
package_name: snowplow-ecommerce
jobs:
version_check:
runs-on: ubuntu-latest
outputs:
v_package: ${{ steps.version.outputs.dbt_package_version}}
v_old: ${{ steps.previoustag.outputs.tag}}
new_version: ${{ steps.new_version_flag.outputs.new_version}}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed to get tags
- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: 0.0.1 # Optional fallback tag to use when no tag can be found
- name: Get tag and package versions
id: version
# Grab the version number of from the project.yml file as the pushed version of the package, set to variable dbt_package_version
run: |
echo "dbt_package_version=$(grep -oP "(?<=version: ')(.*)(?=')" dbt_project.yml)" >> $GITHUB_OUTPUT
echo "Project YAML version: $(grep -oP "(?<=version: ')(.*)(?=')" dbt_project.yml)"
- name: Echo if version already match
if: ${{ steps.previoustag.outputs.tag == steps.version.outputs.dbt_package_version }}
run: |
echo "Tag version (${{ steps.previoustag.outputs.tag }}) is the same as the version in project (${{ steps.version.outputs.dbt_package_version }}), no need to release."
- name: Ensure future steps continue if version doesn't match
id: new_version_flag
if: ${{ steps.previoustag.outputs.tag != steps.version.outputs.dbt_package_version }}
# Set a flag to check if we need to run the future steps, if this is not set they won't run.
run: |
echo "Tag version (${{ steps.previoustag.outputs.tag }}) is different from the version in project (${{ steps.version.outputs.dbt_package_version }}), will release."
echo "new_version=yes" >> $GITHUB_OUTPUT
tagging:
if: ${{ needs.version_check.outputs.new_version == 'yes' }}
needs: ['version_check']
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup git
uses: oleksiyrudenko/[email protected]
with:
token: '${{ secrets.GITHUB_TOKEN }}'
name: github-actions[bot]
email: 41898282+github-actions[bot]@users.noreply.github.com
- name: Generate Release Information
id: tag_version
uses: mathieudutour/[email protected]
# Use this to avoid overwriting existing tags
with:
dry_run: true
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_prefix: ''
default_bump: false
custom_tag: ${{ needs.version_check.outputs.v_package }}
- name: Tag release
run: |
git tag ${{ steps.tag_version.outputs.new_tag }}
git push --tags
release:
if: ${{ needs.version_check.outputs.new_version == 'yes' }}
needs: ["version_check", "tagging"]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prep release body
id: release_prep
# Grep the CHANGELOG to get the text between the new version line and the previous version line (tail to cut off the ----- line, can't have variable length lookbacks in regex)
# Due to multiline output, need to use this EOF approach https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
echo 'release_body<<EOF' >> $GITHUB_OUTPUT
echo "$(grep -Pzo "(?<=${{env.package_name}} ${{ needs.version_check.outputs.v_package }} \(\d{4}-\d{2}-\d{2}\)\n)-*\n(?s)(.*)(?=${{env.package_name}} ${{ needs.version_check.outputs.v_old }} \(\d{4}-\d{2}-\d{2}\))" CHANGELOG | tail -n +2)" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.version_check.outputs.v_package }}
name: ${{env.package_name}} v${{ needs.version_check.outputs.v_package }}
draft: false
body: ${{ steps.release_prep.outputs.release_body }}
prerelease: ${{ contains(needs.version_check.outputs.v_package, 'rc') }}
token: ${{ secrets.GITHUB_TOKEN }}