Skip to content

Commit 6f2d78d

Browse files
authored
chore: release 2.1.0
* feat: insert option to choose http method * feat: implement partially the region * feat: implement region option * chore: change build to supabase stack * chore: documentation method to avoid github warnings * chore: update readme * chore: add release-please * fix: remove some validation for workflow publish * chore: add doc comment * feat: insert region on client's constructor * chore: change validation on publish * chore: unify workflows similar used in python * fix: change _region to immutable * fix: change to use local region var Release-As: 2.1.0
1 parent 781d4f5 commit 6f2d78d

File tree

10 files changed

+321
-69
lines changed

10 files changed

+321
-69
lines changed

.github/workflows/build-and-test.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ jobs:
2424
- name: Build
2525
run: dotnet build --configuration Release --no-restore
2626

27-
- name: Initialize Testing Stack
28-
run: docker-compose up -d
27+
- uses: supabase/setup-cli@v1
28+
with:
29+
version: latest
30+
31+
- name: Start supabase
32+
run: supabase start
33+
34+
# - name: Initialize Testing Stack
35+
# run: docker-compose up -d
2936

3037
- name: Test
3138
run: dotnet test --no-restore

.github/workflows/release.yml

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
name: Publish NuGet Package
1+
name: Release - Publish NuGet Package
22

33
on:
44
push:
55
branches:
6-
- release/* # Default release branch
6+
- master
77

88
jobs:
9+
release-please:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
issues: write
15+
steps:
16+
- uses: googleapis/release-please-action@v4
17+
with:
18+
target-branch: ${{ github.ref_name }}
19+
manifest-file: .release-please-manifest.json
20+
config-file: release-please-config.json
21+
922
publish:
23+
needs: release-please
24+
if: ${{ github.repository_owner == 'supabase-community' && startsWith(github.event.head_commit.message, 'chore(master)') && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
1025
name: build, pack & publish
1126
runs-on: ubuntu-latest
1227
steps:
@@ -24,7 +39,7 @@ jobs:
2439
check-name: build-and-test
2540
repo-token: ${{ secrets.GITHUB_TOKEN }}
2641
wait-interval: 10
27-
42+
2843
- name: Restore dependencies
2944
run: dotnet restore
3045

.release-please-manifest.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "2.0.0"
3+
}

Functions/Client.cs

+52-23
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
using Newtonsoft.Json;
2-
using Supabase.Core;
3-
using Supabase.Core.Extensions;
4-
using Supabase.Functions.Interfaces;
5-
using Supabase.Functions.Responses;
6-
using System;
1+
using System;
72
using System.Collections.Generic;
83
using System.Net.Http;
94
using System.Runtime.CompilerServices;
105
using System.Text;
116
using System.Threading.Tasks;
127
using System.Web;
8+
using Newtonsoft.Json;
9+
using Supabase.Core;
10+
using Supabase.Core.Extensions;
1311
using Supabase.Functions.Exceptions;
12+
using Supabase.Functions.Interfaces;
1413

1514
[assembly: InternalsVisibleTo("FunctionsTests")]
1615

@@ -21,10 +20,11 @@ public partial class Client : IFunctionsClient
2120
{
2221
private HttpClient _httpClient = new HttpClient();
2322
private readonly string _baseUrl;
23+
private readonly FunctionRegion _region;
2424

2525
/// <summary>
2626
/// Function that can be set to return dynamic headers.
27-
///
27+
///
2828
/// Headers specified in the method parameters will ALWAYS take precedence over headers returned by this function.
2929
/// </summary>
3030
public Func<Dictionary<string, string>>? GetHeaders { get; set; }
@@ -33,9 +33,11 @@ public partial class Client : IFunctionsClient
3333
/// Initializes a functions client
3434
/// </summary>
3535
/// <param name="baseUrl"></param>
36-
public Client(string baseUrl)
36+
/// <param name="region"></param>
37+
public Client(string baseUrl, FunctionRegion? region = null)
3738
{
3839
_baseUrl = baseUrl;
40+
_region = region ?? FunctionRegion.Any;
3941
}
4042

4143
/// <summary>
@@ -45,8 +47,11 @@ public Client(string baseUrl)
4547
/// <param name="token">Anon Key.</param>
4648
/// <param name="options">Options</param>
4749
/// <returns></returns>
48-
public async Task<HttpContent> RawInvoke(string functionName, string? token = null,
49-
InvokeFunctionOptions? options = null)
50+
public async Task<HttpContent> RawInvoke(
51+
string functionName,
52+
string? token = null,
53+
InvokeFunctionOptions? options = null
54+
)
5055
{
5156
var url = $"{_baseUrl}/{functionName}";
5257

@@ -60,8 +65,11 @@ public async Task<HttpContent> RawInvoke(string functionName, string? token = nu
6065
/// <param name="token">Anon Key.</param>
6166
/// <param name="options">Options</param>
6267
/// <returns></returns>
63-
public async Task<string> Invoke(string functionName, string? token = null,
64-
InvokeFunctionOptions? options = null)
68+
public async Task<string> Invoke(
69+
string functionName,
70+
string? token = null,
71+
InvokeFunctionOptions? options = null
72+
)
6573
{
6674
var url = $"{_baseUrl}/{functionName}";
6775
var response = await HandleRequest(url, token, options);
@@ -77,8 +85,12 @@ public async Task<string> Invoke(string functionName, string? token = null,
7785
/// <param name="token">Anon Key.</param>
7886
/// <param name="options">Options</param>
7987
/// <returns></returns>
80-
public async Task<T?> Invoke<T>(string functionName, string? token = null,
81-
InvokeFunctionOptions? options = null) where T : class
88+
public async Task<T?> Invoke<T>(
89+
string functionName,
90+
string? token = null,
91+
InvokeFunctionOptions? options = null
92+
)
93+
where T : class
8294
{
8395
var url = $"{_baseUrl}/{functionName}";
8496
var response = await HandleRequest(url, token, options);
@@ -96,8 +108,11 @@ public async Task<string> Invoke(string functionName, string? token = null,
96108
/// <param name="options"></param>
97109
/// <returns></returns>
98110
/// <exception cref="FunctionsException"></exception>
99-
private async Task<HttpResponseMessage> HandleRequest(string url, string? token = null,
100-
InvokeFunctionOptions? options = null)
111+
private async Task<HttpResponseMessage> HandleRequest(
112+
string url,
113+
string? token = null,
114+
InvokeFunctionOptions? options = null
115+
)
101116
{
102117
options ??= new InvokeFunctionOptions();
103118

@@ -113,26 +128,40 @@ private async Task<HttpResponseMessage> HandleRequest(string url, string? token
113128

114129
options.Headers["X-Client-Info"] = Util.GetAssemblyVersion(typeof(Client));
115130

131+
var region = options.FunctionRegion;
132+
if (region == null)
133+
{
134+
region = _region;
135+
}
136+
137+
if (region != FunctionRegion.Any)
138+
{
139+
options.Headers["x-region"] = region.ToString();
140+
}
141+
116142
var builder = new UriBuilder(url);
117143
var query = HttpUtility.ParseQueryString(builder.Query);
118144

119145
builder.Query = query.ToString();
120146

121-
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, builder.Uri);
122-
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(options.Body), Encoding.UTF8,
123-
"application/json");
147+
using var requestMessage = new HttpRequestMessage(options.HttpMethod, builder.Uri);
148+
requestMessage.Content = new StringContent(
149+
JsonConvert.SerializeObject(options.Body),
150+
Encoding.UTF8,
151+
"application/json"
152+
);
124153

125154
foreach (var kvp in options.Headers)
126155
{
127156
requestMessage.Headers.TryAddWithoutValidation(kvp.Key, kvp.Value);
128157
}
129-
158+
130159
if (_httpClient.Timeout != options.HttpTimeout)
131160
{
132161
_httpClient = new HttpClient();
133162
_httpClient.Timeout = options.HttpTimeout;
134163
}
135-
164+
136165
var response = await _httpClient.SendAsync(requestMessage);
137166

138167
if (response.IsSuccessStatusCode && !response.Headers.Contains("x-relay-error"))
@@ -143,10 +172,10 @@ private async Task<HttpResponseMessage> HandleRequest(string url, string? token
143172
{
144173
Content = content,
145174
Response = response,
146-
StatusCode = (int)response.StatusCode
175+
StatusCode = (int)response.StatusCode,
147176
};
148177
exception.AddReason();
149178
throw exception;
150179
}
151180
}
152-
}
181+
}

Functions/Functions.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
<PackageIconUrl>https://avatars.githubusercontent.com/u/54469796?s=200&amp;v=4</PackageIconUrl>
1717
<PackageProjectUrl>https://github.com/supabase-community/functions-csharp</PackageProjectUrl>
1818
<PackageTags>supabase, functions</PackageTags>
19+
<!-- x-release-please-start-version -->
1920
<PackageVersion>2.0.0</PackageVersion>
2021
<ReleaseVersion>2.0.0</ReleaseVersion>
22+
<!-- x-release-please-end -->
2123
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2224
<PackageIcon>icon.png</PackageIcon>
2325
<PackageReadmeFile>README.md</PackageReadmeFile>
@@ -31,7 +33,7 @@
3133
</PropertyGroup>
3234

3335
<PropertyGroup Condition=" '$(Version)' == '' ">
34-
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">2.0.0</VersionPrefix>
36+
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">2.0.0</VersionPrefix> <!-- x-release-please-version -->
3537
<VersionSuffix Condition=" '$(VersionSuffix)' == '' "></VersionSuffix>
3638
<Version Condition=" '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
3739
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
@@ -46,4 +48,4 @@
4648
<None Include="..\.github\icon.png" Pack="true" Link="icon.png" PackagePath="\" />
4749
<None Include="..\README.md" Pack="true" Link="README.md" PackagePath="\" />
4850
</ItemGroup>
49-
</Project>
51+
</Project>

0 commit comments

Comments
 (0)