-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (123 loc) · 4.21 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Release
defaults:
run:
shell: bash
permissions:
contents: write
pull-requests: write
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
jobs:
check_commit:
name: Check Commit
runs-on: ubuntu-latest
outputs:
IS_RELEASE: ${{ steps.check_msg.outputs.IS_RELEASE }}
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Check latest commit message
id: check_msg
run: |
LATEST_COMMIT_MSG=$(git log -1 --pretty=%B | cat)
if [[ ${LATEST_COMMIT_MSG} == *"[release]"* ]]; then
echo "release message found - continuing with the release"
IS_RELEASE="true"
else
echo "no release message found - skipping..."
IS_RELEASE="false"
fi
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
release:
name: Release
needs: [check_commit]
runs-on: ubuntu-latest
if: ${{ needs.check_commit.outputs.IS_RELEASE == 'true' }}
env:
IS_RELEASE: ${{ needs.check_commit.outputs.IS_RELEASE }}
steps:
- name: Check out Git repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v6
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: ci.yml
workflow_conclusion: success
name: wasm-file
- name: Bump version
run: |
set -e
LATEST_COMMIT_MSG=$(git log -1 --pretty=%B | cat)
echo "Extract the latest tag version"
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
BUMP_TYPE="patch" # Initialize the default version bump type to patch
if [[ "${LATEST_COMMIT_MSG}" == *"[major]"* ]]; then
BUMP_TYPE="major"
elif [[ "${LATEST_COMMIT_MSG}" == *"[minor]"* ]]; then
BUMP_TYPE="minor"
fi
case ${BUMP_TYPE} in
"major")
NEW_TAG=$(echo "${LATEST_TAG}" | awk -F. '{OFS="."; $1="v" substr($1,2)+1; $2="0"; $3="0"; print}')
;;
"minor")
NEW_TAG=$(echo "${LATEST_TAG}" | awk -F. '{OFS="."; $2=$2+1; $3="0"; print}')
;;
"patch")
NEW_TAG=$(echo "${LATEST_TAG}" | awk -F. '{OFS="."; $3=$3+1; print}')
;;
esac
echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_ENV
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV
- name: Push tag
run: |
NEW_TAG=${{ env.NEW_TAG }}
git tag ${NEW_TAG}
git push origin ${NEW_TAG}
- name: Calculate sha256
run: |
SHA256_HASH=$(sha256sum plugin.wasm | awk '{ print $1 }')
echo "SHA256_HASH=${SHA256_HASH}" >> $GITHUB_ENV
echo "The calculated sha256 is $SHA256_HASH"
- name: Create release draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
LATEST_TAG=${{ env.LATEST_TAG }}
NEW_TAG=${{ env.NEW_TAG }}
SHA256_HASH=${{ env.SHA256_HASH }}
CHANGE_LOG=$(git --no-pager log ${LATEST_TAG}..HEAD --pretty=format:'%h - %an, %ar : %s')
# Define the release notes template
RELEASE_NOTES=$(cat <<EOF
## Release version ${NEW_TAG}
Release sha256 is \`${SHA256_HASH}\`
## Configuration example
\`\`\`yaml
version: '2'
plugins:
- name: csharp
wasm:
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/${NEW_TAG}/sqlc-gen-csharp.wasm
sha256: ${SHA256_HASH}
\`\`\`
## Changelog
${CHANGE_LOG}
## Contributors
* @SockworkOrange
EOF
)
# change file name to convention
mv plugin.wasm sqlc-gen-csharp.wasm
# Create a draft release
gh release create ${NEW_TAG} sqlc-gen-csharp.wasm \
--draft \
--title "${NEW_TAG}" \
--notes "${RELEASE_NOTES}"