Skip to content

Commit

Permalink
test release flow in CI (#46)
Browse files Browse the repository at this point in the history
* add release flow to CI

* fix typos in readme

* fix repo name
  • Loading branch information
doron050 authored Jun 7, 2024
1 parent 4bf521e commit 006a544
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 12 deletions.
106 changes: 104 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ defaults:
run:
shell: bash

permissions:
contents: write

on:
push:
branches: [ "main" ]
Expand All @@ -13,7 +16,6 @@ on:
- "!**.md"

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
Expand Down Expand Up @@ -107,4 +109,104 @@ jobs:
run: |
chmod +x ./scripts/run_tests.sh
./scripts/run_tests.sh
shell: bash
- name: upload wasm plugin as artifact
uses: actions/upload-artifact@v2
if: github.ref == 'refs/heads/add-automatic-release' && contains(github.event.head_commit.message, '[release]')
with:
name: wasm-file
path: dist/plugin.wasm

release:
name: Release test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/add-automatic-release' && contains(github.event.head_commit.message, '[release]')
needs: [ci]
steps:
- name: Check out Git repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # fetches all history for all tags and branches
- uses: actions/download-artifact@v2
with:
name: wasm-file
- name: Bump version and create new tag
id: bump_version
run: |
echo "Extract the last tag version"
LAST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "Last tag version: $LAST_TAG"
LATEST_COMMIT_MSG=$(git log -1 --pretty=%B)
# Initialize the default version bump type to patch
BUMP_TYPE="patch"
# Check the latest commit message for [major] or [minor]
if [[ $LATEST_COMMIT_MSG == *"[major]"* ]]; then
BUMP_TYPE="major"
elif [[ $LATEST_COMMIT_MSG == *"[minor]"* ]]; then
BUMP_TYPE="minor"
fi
# Bump the version based on the type
case $BUMP_TYPE in
"major")
NEW_TAG=$(echo $LAST_TAG | awk -F. '{OFS="."; $1="v" substr($1,2)+1; $2="0"; $3="0"; print}')
;;
"minor")
NEW_TAG=$(echo $LAST_TAG | awk -F. '{OFS="."; $2=$2+1; $3="0"; print}')
;;
"patch")
NEW_TAG=$(echo $LAST_TAG | awk -F. '{OFS="."; $3=$3+1; print}')
;;
esac
echo "New tag version: $NEW_TAG"
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
# Create a 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 relaese draft
run: |
NEW_TAG=${{ env.NEW_TAG }}
SHA256_HASH=${{ env.SHA256_HASH }}
# 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
* ADD CHANGES HERE...
## Contributors
* @doron050 @SockworkOrange
Anyone who wishes to contribute to the next releases is invited :)
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"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 DionyOSS
Copyright (c) 2024 DaredevilOSS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test-process-plugin: sqlc-generate-process dockerfile-generate run-tests

# WASM type plugin
dotnet-publish-wasm: protobuf-generate
dotnet publish SqlcGenCsharpWasm -c release --output dist/
dotnet publish WasmRunner -c release --output dist/
./scripts/wasm/copy_to_dist.sh

update-wasm-plugin:
Expand Down
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version: "2"
plugins:
- name: csharp
wasm:
url: https://github.com/DionyOSS/sqlc-gen-csharp/releases/download/v0.10.0/sqlc-gen-csharp_0.10.0.wasm
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/v0.10.0/sqlc-gen-csharp.wasm
sha256: 613ae249a541ab95c97b362bd1b0b572970edcad5eb2a11806a52d3f95e0f65f
sql:
# PostgreSQL Example
Expand Down Expand Up @@ -36,7 +36,7 @@ sql:
### Options Documentation
| Option | Possible values | Info |
|------------|---------------------------|-|
| 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). |
| 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). |
| 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. |
| 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. |

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


# Local plugin development
## Prerequisites
# Contributing
## Local plugin development
### Prerequisites
make sure that the following applications are installed and exposed in your path

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

## Protobuf
### Protobuf
SQLC protobuf are defined in sqlc-dev/sqlc repository.
Generating C# code from protocol buffer files:
```
make protobuf-generate
```
## Generating code
### Generating code
SQLC utilizes our process / WASM plugin to generate code
```
make sqlc-generate-process
make sqlc-generate-wasm
```
## Testing generated code
### Testing generated code
Testing the SQLC generated code via a predefined flow:
```
make test-process-plugin
make test-wasm-plugin
```
## Release flow
The release flow in this repo follows the semver conventions, building tag as `v[major].[minor].[patch]`.
* In order to create a release you need to add `[release]` somewhere in your commit message when merging to master
### Version bumping (build on tags)
**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`.
* Bump `minor` version by adding `[minor]` to your commit message resulting in a new tag with `v[major].[minor]+1.0`<br/>
* Bump `major` version by adding `[major]` to your commit message resulting in a new tag with `v[major]+1.0.0`
### Release structure
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/>
> All we have left to do now is to add the changelog and publish the draft

0 comments on commit 006a544

Please sign in to comment.