Skip to content

Commit 006a544

Browse files
authoredJun 7, 2024··
test release flow in CI (#46)
* add release flow to CI * fix typos in readme * fix repo name
1 parent 4bf521e commit 006a544

File tree

4 files changed

+129
-12
lines changed

4 files changed

+129
-12
lines changed
 

‎.github/workflows/main.yml

+104-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ defaults:
33
run:
44
shell: bash
55

6+
permissions:
7+
contents: write
8+
69
on:
710
push:
811
branches: [ "main" ]
@@ -13,7 +16,6 @@ on:
1316
- "!**.md"
1417

1518
jobs:
16-
1719
lint:
1820
name: Lint
1921
runs-on: ubuntu-latest
@@ -107,4 +109,104 @@ jobs:
107109
run: |
108110
chmod +x ./scripts/run_tests.sh
109111
./scripts/run_tests.sh
110-
shell: bash
112+
- name: upload wasm plugin as artifact
113+
uses: actions/upload-artifact@v2
114+
if: github.ref == 'refs/heads/add-automatic-release' && contains(github.event.head_commit.message, '[release]')
115+
with:
116+
name: wasm-file
117+
path: dist/plugin.wasm
118+
119+
release:
120+
name: Release test
121+
runs-on: ubuntu-latest
122+
if: github.ref == 'refs/heads/add-automatic-release' && contains(github.event.head_commit.message, '[release]')
123+
needs: [ci]
124+
steps:
125+
- name: Check out Git repository
126+
uses: actions/checkout@v4
127+
with:
128+
fetch-depth: 0 # fetches all history for all tags and branches
129+
- uses: actions/download-artifact@v2
130+
with:
131+
name: wasm-file
132+
- name: Bump version and create new tag
133+
id: bump_version
134+
run: |
135+
echo "Extract the last tag version"
136+
LAST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
137+
echo "Last tag version: $LAST_TAG"
138+
LATEST_COMMIT_MSG=$(git log -1 --pretty=%B)
139+
140+
# Initialize the default version bump type to patch
141+
BUMP_TYPE="patch"
142+
143+
# Check the latest commit message for [major] or [minor]
144+
if [[ $LATEST_COMMIT_MSG == *"[major]"* ]]; then
145+
BUMP_TYPE="major"
146+
elif [[ $LATEST_COMMIT_MSG == *"[minor]"* ]]; then
147+
BUMP_TYPE="minor"
148+
fi
149+
150+
# Bump the version based on the type
151+
case $BUMP_TYPE in
152+
"major")
153+
NEW_TAG=$(echo $LAST_TAG | awk -F. '{OFS="."; $1="v" substr($1,2)+1; $2="0"; $3="0"; print}')
154+
;;
155+
"minor")
156+
NEW_TAG=$(echo $LAST_TAG | awk -F. '{OFS="."; $2=$2+1; $3="0"; print}')
157+
;;
158+
"patch")
159+
NEW_TAG=$(echo $LAST_TAG | awk -F. '{OFS="."; $3=$3+1; print}')
160+
;;
161+
esac
162+
163+
echo "New tag version: $NEW_TAG"
164+
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
165+
166+
# Create a new tag
167+
git tag $NEW_TAG
168+
git push origin $NEW_TAG
169+
170+
- name: Calculate sha256
171+
run: |
172+
SHA256_HASH=$(sha256sum plugin.wasm | awk '{ print $1 }')
173+
echo "SHA256_HASH=$SHA256_HASH" >> $GITHUB_ENV
174+
echo "The calculated sha256 is $SHA256_HASH"
175+
- name: create relaese draft
176+
run: |
177+
NEW_TAG=${{ env.NEW_TAG }}
178+
SHA256_HASH=${{ env.SHA256_HASH }}
179+
180+
# Define the release notes template
181+
RELEASE_NOTES=$(cat <<EOF
182+
## Release version $NEW_TAG
183+
Release sha256 is \`$SHA256_HASH\`
184+
185+
## Configuration example
186+
\`\`\`yaml
187+
version: '2'
188+
plugins:
189+
- name: csharp
190+
wasm:
191+
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/$NEW_TAG/sqlc-gen-csharp.wasm
192+
sha256: $SHA256_HASH
193+
\`\`\`
194+
## Changelog
195+
* ADD CHANGES HERE...
196+
197+
## Contributors
198+
* @doron050 @SockworkOrange
199+
Anyone who wishes to contribute to the next releases is invited :)
200+
EOF
201+
)
202+
203+
# change file name to convention
204+
mv plugin.wasm sqlc-gen-csharp.wasm
205+
206+
# Create a draft release
207+
gh release create $NEW_TAG sqlc-gen-csharp.wasm \
208+
--draft \
209+
--title "$NEW_TAG" \
210+
--notes "$RELEASE_NOTES"
211+
env:
212+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 DionyOSS
3+
Copyright (c) 2024 DaredevilOSS
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test-process-plugin: sqlc-generate-process dockerfile-generate run-tests
3131

3232
# WASM type plugin
3333
dotnet-publish-wasm: protobuf-generate
34-
dotnet publish SqlcGenCsharpWasm -c release --output dist/
34+
dotnet publish WasmRunner -c release --output dist/
3535
./scripts/wasm/copy_to_dist.sh
3636

3737
update-wasm-plugin:

‎README.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version: "2"
88
plugins:
99
- name: csharp
1010
wasm:
11-
url: https://github.com/DionyOSS/sqlc-gen-csharp/releases/download/v0.10.0/sqlc-gen-csharp_0.10.0.wasm
11+
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/v0.10.0/sqlc-gen-csharp.wasm
1212
sha256: 613ae249a541ab95c97b362bd1b0b572970edcad5eb2a11806a52d3f95e0f65f
1313
sql:
1414
# PostgreSQL Example
@@ -36,7 +36,7 @@ sql:
3636
### Options Documentation
3737
| Option | Possible values | Info |
3838
|------------|---------------------------|-|
39-
| targetFramework | default: `net8.0`<br/>vaults: `netstandard2.0`, `netstandard2.1`, `net8.0` |Decide on the right target framework for your generated code, meaning the generated code will be compiled to the specified runtime.<br/>For more information and help deciding on the right value, refer to the [Microsoft .NET Standard documentation](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-1-0). |
39+
| targetFramework | default: `net8.0`<br/>values: `netstandard2.0`, `netstandard2.1`, `net8.0` |Decide on the right target framework for your generated code, meaning the generated code will be compiled to the specified runtime.<br/>For more information and help deciding on the right value, refer to the [Microsoft .NET Standard documentation](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-1-0). |
4040
| generateCsproj | default: `true`<br/>values: `false`,`true` | This option is designed to assist you with the integration of SQLC and csharp by generating a `.csproj` file. This converts the generated output to a dynamic link library (DLL), simply a project that you can easily incorporate into your build process. |
4141
| filePerQuery | default: `false`<br/>values: `false`,`true` | This option allows users control on which `.cs` files to generate, when false it's one file per `.sql` SQLC query file, and when true it's one file per query. |
4242

@@ -57,33 +57,48 @@ The below examples in here are automatically tested:
5757
<br/>
5858
<br/>
5959

60-
61-
# Local plugin development
62-
## Prerequisites
60+
# Contributing
61+
## Local plugin development
62+
### Prerequisites
6363
make sure that the following applications are installed and exposed in your path
6464

6565
Follow the instructions in each of these:
6666
* Dotnet CLI - [Dotnet Installation](https://github.com/dotnet/sdk) - use version `.NET 8.0 (latest)`
6767
* buf build - [Buf Build](https://buf.build/docs/installation)
6868
* WASM related - [WASM libs](https://www.strathweb.com/2023/09/dotnet-wasi-applications-in-net-8-0/)
6969

70-
## Protobuf
70+
### Protobuf
7171
SQLC protobuf are defined in sqlc-dev/sqlc repository.
7272
Generating C# code from protocol buffer files:
7373
```
7474
make protobuf-generate
7575
```
7676
77-
## Generating code
77+
### Generating code
7878
SQLC utilizes our process / WASM plugin to generate code
7979
```
8080
make sqlc-generate-process
8181
make sqlc-generate-wasm
8282
```
8383
84-
## Testing generated code
84+
### Testing generated code
8585
Testing the SQLC generated code via a predefined flow:
8686
```
8787
make test-process-plugin
8888
make test-wasm-plugin
8989
```
90+
91+
## Release flow
92+
The release flow in this repo follows the semver conventions, building tag as `v[major].[minor].[patch]`.
93+
94+
* In order to create a release you need to add `[release]` somewhere in your commit message when merging to master
95+
96+
### Version bumping (build on tags)
97+
**By default, the release script will bump the patch version.**, by adding `[release]` to your commit message the release script will create a new tag with `v[major].[minor].[patch]+1`.
98+
* Bump `minor` version by adding `[minor]` to your commit message resulting in a new tag with `v[major].[minor]+1.0`<br/>
99+
* Bump `major` version by adding `[major]` to your commit message resulting in a new tag with `v[major]+1.0.0`
100+
101+
### Release structure
102+
The new created tag will create a draft release with it, in the release there will be the wasm plugin embedded in the release.<br/>
103+
> All we have left to do now is to add the changelog and publish the draft
104+

0 commit comments

Comments
 (0)
Please sign in to comment.