Skip to content

Commit 245dc20

Browse files
Show Docs site with links directly to changed files (#1078)
1 parent 187759c commit 245dc20

File tree

16 files changed

+455
-541
lines changed

16 files changed

+455
-541
lines changed

.github/workflows/test-docs.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
- uses: actions/checkout@v3
1212
with:
1313
fetch-depth: 0 # Get everything so that the `mkdocs-git-authors` plugin answers correctly
14+
ref: ${{ github.head_ref }}
1415
- uses: actions/setup-node@v3
1516
name: Setup Node v18
1617
with:
@@ -60,10 +61,14 @@ jobs:
6061
run: |
6162
echo "Deploying site ${{ env.DOCS_BRANCH_NAME }}"
6263
netlify deploy --site "${{ env.DOCS_BRANCH_NAME }}" --dir ./ --prod
64+
- name: Get Changed Docs
65+
id: docsite
66+
run: |
67+
python ./devops/build_sdks.py --language=docs_pr_automation --docs-branch-name=${{ env.DOCS_BRANCH_NAME }}
6368
- uses: mshick/add-pr-comment@v1
6469
with:
6570
message: |
66-
[Preview docs site for ${{ github.head_ref }}@${{ github.sha }}](https://${{ env.DOCS_BRANCH_NAME }}.netlify.app/)
71+
${{ steps.docsite.outputs.netlify_comment }}
6772
repo-token: ${{ secrets.GITHUB_TOKEN }}
6873
repo-token-user-login: 'github-actions[bot]'
6974
allow-repeats: false

devops/build_sdks.py

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
import platform
99
import shutil
1010
import subprocess
11+
12+
import pygit2
13+
import requests
1114
from os.path import join, abspath, dirname, isdir, split
1215
from typing import Dict
13-
14-
try:
15-
import requests
16-
except:
17-
os.system("pip install requests")
18-
import requests
16+
from pygit2 import Repository
1917

2018

2119
def parse_version_tag():
@@ -97,7 +95,8 @@ def get_language_dir(language_name: str) -> str:
9795
return abspath(join(dirname(abspath(__file__)), "..", language_name))
9896

9997

100-
def get_sdk_dir() -> str:
98+
@property
99+
def sdk_dir() -> str:
101100
"""Get the full path of the root of the sdk repository"""
102101
return abspath(join(dirname(abspath(__file__)), ".."))
103102

@@ -125,7 +124,9 @@ def build_java(args) -> None:
125124
)
126125
update_line(
127126
join(java_dir, "src", "main", "java", "trinsic", "TrinsicUtilities.java"),
128-
{"final String sdkVersion = ": f' final String sdkVersion = "{get_package_versions(args)}";'},
127+
{
128+
"final String sdkVersion = ": f' final String sdkVersion = "{get_package_versions(args)}";'
129+
},
129130
)
130131
copy_okapi_libs(abspath(join(java_dir, "..", "libs")))
131132

@@ -148,7 +149,9 @@ def build_golang(args) -> None:
148149
golang_dir = abspath(join(get_language_dir("go"), "services"))
149150
update_line(
150151
join(golang_dir, "services.go"),
151-
{"const sdkVersion = ": f' const sdkVersion = "{get_package_versions(args)}"'},
152+
{
153+
"const sdkVersion = ": f' const sdkVersion = "{get_package_versions(args)}"'
154+
},
152155
)
153156
# Copy in the binaries
154157
copy_okapi_libs(golang_dir, "windows-gnu")
@@ -195,7 +198,7 @@ def build_java_docs(args):
195198
# npm ci in the root of sdk
196199
subprocess.Popen(
197200
r"node ./node_modules/groovydoc-to-markdown/src/doc2md.js ./java java ./docs/reference/java",
198-
cwd=get_sdk_dir(),
201+
cwd=sdk_dir(),
199202
).wait()
200203

201204

@@ -204,10 +207,10 @@ def build_dotnet_docs(args) -> None:
204207
# dotnet tool install DefaultDocumentation.Console -g
205208
assembly_file = "./dotnet/Trinsic/bin/Debug/net6.0/Trinsic.dll"
206209
output_doc_folder = "./docs/reference/dotnet"
207-
clean_dir(abspath(join(get_sdk_dir(), output_doc_folder)))
210+
clean_dir(abspath(join(sdk_dir(), output_doc_folder)))
208211
subprocess.Popen(
209212
f"defaultdocumentation --AssemblyFilePath {assembly_file} --OutputDirectoryPath {output_doc_folder} --FileNameMode Name --GeneratedPages Namespaces",
210-
cwd=get_sdk_dir(),
213+
cwd=sdk_dir(),
211214
).wait()
212215

213216

@@ -238,6 +241,46 @@ def build_docs(args):
238241
build_go_docs(args)
239242

240243

244+
def build_docs_site(args):
245+
# git diff --name-only
246+
proc = subprocess.run(
247+
["git", "diff", "origin/main", "--name-only"], capture_output=True, text=True
248+
)
249+
output = proc.stdout.split("\n")
250+
# Skip the warning about line feed
251+
output = [
252+
line
253+
for line in output
254+
if not line.lower().startswith("warning:")
255+
and not line.lower().startswith("the file will have its")
256+
and line
257+
]
258+
# Get only markdown files
259+
output = [line for line in output if line.lower().endswith(".md")]
260+
261+
proc = subprocess.run(["git", "rev-parse", "--short", "HEAD"], capture_output=True, text=True)
262+
github_sha = proc.stdout.strip()
263+
proc = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True)
264+
github_head_ref = proc.stdout.strip()
265+
266+
267+
# Export a markdown formatted list of changed pages
268+
github_comment = [
269+
f"[Preview docs site for {github_head_ref}@{github_sha}](https://{args.docs_branch_name}.netlify.app/)"
270+
]
271+
github_comment.append("Changed paths:")
272+
github_comment.extend(
273+
[
274+
f"{ij + 1}. [{md_file}](https://{args.docs_branch_name}.netlify.app/{md_file.replace('.md', '').replace('docs/', '')})"
275+
for ij, md_file in enumerate(output)
276+
]
277+
)
278+
# TODO - maybe cap it if there are too many files to list?
279+
# This is a github action newline escape
280+
md_text = "%0A".join(github_comment)
281+
print(f"::set-output name=netlify_comment::{md_text}")
282+
283+
241284
def build_none(args) -> None:
242285
"""
243286
This is here, so you can specify no language to update - eg just download plugins
@@ -248,6 +291,7 @@ def build_none(args) -> None:
248291
def parse_arguments():
249292
parser = argparse.ArgumentParser(description="Process SDK building")
250293
parser.add_argument("--package-version", help="Manual override package version")
294+
parser.add_argument("--docs-branch-name", help="docs branch name")
251295
parser.add_argument(
252296
"--language", help="Comma-separated languages to build", default="all"
253297
)
@@ -267,6 +311,7 @@ def main():
267311
"java": build_java,
268312
"dart": build_dart,
269313
"typescript": build_typescript,
314+
"docs_pr_automation": build_docs_site,
270315
"none": build_none,
271316
}
272317
# If "all" is specified, set the array of languages to build to the list of all languages we _can_ build.

devops/generate_proto_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def update_golang():
185185
'okapiproto "github.com/trinsic-id/sdk/go/okapiproto"': 'okapiproto "github.com/trinsic-id/okapi/go/okapiproto"',
186186
'_ "services/options"': '_ "github.com/trinsic-id/sdk/go/proto/services/options"',
187187
'account "services/account/v1/account"': 'account "github.com/trinsic-id/sdk/go/proto/services/account/v1/account"',
188-
'common "services/common/v1/common"': 'account "github.com/trinsic-id/sdk/go/proto/services/common/v1/common"',
188+
'common "services/common/v1/common"': 'common "github.com/trinsic-id/sdk/go/proto/services/common/v1/common"',
189189
}
190190
for file_name in glob.glob(join(go_proto_path, "**", "*.go"), recursive=True):
191191
update_line(file_name, replace_pairs)

devops/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
git+https://github.com/danielgtaylor/python-betterproto.git@3ca092a72494f9225bcb124aab2d0675f9e8c125#egg=betterproto[compiler]
22
grpcio-tools
33
requests
4-
markupsafe==2.1.1
4+
markupsafe==2.1.1
5+
pygit2

docs/go/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ Once the go package is installed and configured, you're ready to start building!
2222

2323
[Start Walkthrough](../walkthroughs/vaccination.md){ .md-button .md-button--primary } [Explore API](../reference/index.md){ .md-button } [Go API Reference](../reference/index.md){ .md-button }
2424

25-

docs/java/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# The Trinsic Java SDK
1+
# The Trinsic Java / Kotlin SDK
22

3-
The Trinsic Java SDK makes it easy to interact with the Trinsic API from any Java application. The most recent version of the package is found on the [Github Release](https://github.com/trinsic-id/sdk/releases). You can find the SDKs source on [Github](https://github.com/trinsic-id/sdk/tree/main/java).
3+
The Trinsic Java / Kotlin SDK makes it easy to interact with the Trinsic API from any Java (or Kotlin) application. The most recent version of the package is found on the [Github Release](https://github.com/trinsic-id/sdk/releases). You can find the SDKs source on [Github](https://github.com/trinsic-id/sdk/tree/main/java).
44

55
## Installation
66
1. Add the `urlFile` code shown below to your `build.gradle`.

docs/roadmap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
- [:material-language-python: Python](python/index.md)
88
- [:fontawesome-brands-js-square: Web](web/index.md)
99
- [:material-language-java: Java](java/index.md)
10+
- [:material-menu: Go](go/index.md)
11+
- [:material-language-ruby: Ruby](ruby/index.md)
1012
### Coming Soon
1113
- :material-android: Android
1214
- :material-apple: iOS
13-
- :material-menu: Go
14-
- :material-language-ruby: Ruby
Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,74 @@
11
package trinsic;
22

3-
import com.google.protobuf.InvalidProtocolBufferException;
3+
import java.io.IOException;
4+
import java.util.concurrent.ExecutionException;
45
import org.junit.jupiter.api.Assertions;
56
import org.junit.jupiter.api.Disabled;
67
import org.junit.jupiter.api.Test;
78
import trinsic.okapi.DidException;
89
import trinsic.services.AccountService;
910
import trinsic.services.ProviderService;
1011
import trinsic.services.TrinsicService;
11-
import trinsic.services.account.v1.LoginRequest;
1212
import trinsic.services.common.v1.SupportedDidMethod;
1313
import trinsic.services.provider.v1.*;
1414

15-
import java.io.IOException;
16-
import java.util.concurrent.ExecutionException;
17-
1815
public class ProviderServiceTest {
19-
@Test
20-
@Disabled
21-
public void testProviderServiceInviteParticipant()
22-
throws IOException, DidException, ExecutionException, InterruptedException {
23-
var accountService = new AccountService(TrinsicUtilities.getTrinsicServiceOptions());
24-
var account = accountService.signIn().get();
16+
@Test
17+
@Disabled
18+
public void testProviderServiceInviteParticipant()
19+
throws IOException, DidException, ExecutionException, InterruptedException {
20+
var accountService = new AccountService(TrinsicUtilities.getTrinsicServiceOptions());
21+
var account = accountService.signIn().get();
2522

26-
var providerService = new ProviderService(TrinsicUtilities.getTrinsicServiceOptions(account));
27-
var ecosystem =
28-
providerService
29-
.createEcosystem(CreateEcosystemRequest.newBuilder().setName("Test Ecosystem").build())
30-
.get();
31-
var invitation =
32-
InviteRequest.newBuilder()
33-
.setParticipant(ParticipantType.participant_type_individual)
34-
.setDescription("I dunno")
35-
.build();
36-
var response = providerService.invite(invitation).get();
37-
Assertions.assertNotNull(response);
23+
var providerService = new ProviderService(TrinsicUtilities.getTrinsicServiceOptions(account));
24+
var ecosystem =
25+
providerService
26+
.createEcosystem(CreateEcosystemRequest.newBuilder().setName("Test Ecosystem").build())
27+
.get();
28+
var invitation =
29+
InviteRequest.newBuilder()
30+
.setParticipant(ParticipantType.participant_type_individual)
31+
.setDescription("I dunno")
32+
.build();
33+
var response = providerService.invite(invitation).get();
34+
Assertions.assertNotNull(response);
3835

39-
var status =
40-
providerService
41-
.invitationStatus(
42-
InvitationStatusRequest.newBuilder()
43-
.setInvitationId(response.getInvitationId())
44-
.build())
45-
.get();
46-
Assertions.assertNotNull(status);
47-
}
36+
var status =
37+
providerService
38+
.invitationStatus(
39+
InvitationStatusRequest.newBuilder()
40+
.setInvitationId(response.getInvitationId())
41+
.build())
42+
.get();
43+
Assertions.assertNotNull(status);
44+
}
4845

49-
@Test
50-
public void testUpgradeDid() throws IOException, DidException, ExecutionException, InterruptedException {
51-
var trinsic = new TrinsicService(TrinsicUtilities.getTrinsicServiceOptions());
46+
@Test
47+
public void testUpgradeDid()
48+
throws IOException, DidException, ExecutionException, InterruptedException {
49+
var trinsic = new TrinsicService(TrinsicUtilities.getTrinsicServiceOptions());
5250

53-
var ecoCreateResponse = trinsic.provider().createEcosystem(CreateEcosystemRequest.getDefaultInstance()).get();
51+
var ecoCreateResponse =
52+
trinsic.provider().createEcosystem(CreateEcosystemRequest.getDefaultInstance()).get();
5453

55-
var infoResponse = trinsic.account().info().get();
56-
var walletId = infoResponse.getWalletId();
54+
var infoResponse = trinsic.account().info().get();
55+
var walletId = infoResponse.getWalletId();
5756

58-
// Wrap in try-catch as ecosystems cannot upgrade DIDs by default presently
59-
try {
60-
// upgradeDid() {
61-
var upgradeRequest = UpgradeDidRequest.newBuilder()
62-
.setWalletId(walletId)
63-
.setMethod(SupportedDidMethod.ION)
64-
.setIonOptions(IonOptions.newBuilder()
65-
.setNetwork(IonOptions.IonNetwork.TestNet)
66-
.build()
67-
).build();
57+
// Wrap in try-catch as ecosystems cannot upgrade DIDs by default presently
58+
try {
59+
// upgradeDid() {
60+
var upgradeRequest =
61+
UpgradeDidRequest.newBuilder()
62+
.setWalletId(walletId)
63+
.setMethod(SupportedDidMethod.ION)
64+
.setIonOptions(
65+
IonOptions.newBuilder().setNetwork(IonOptions.IonNetwork.TestNet).build())
66+
.build();
6867

69-
var upgradeResponse = trinsic.provider().upgradeDID(upgradeRequest).get();
70-
// }
71-
} catch (Exception e) {
68+
var upgradeResponse = trinsic.provider().upgradeDID(upgradeRequest).get();
69+
// }
70+
} catch (Exception e) {
7271

73-
}
7472
}
73+
}
7574
}

java/src/test/java/trinsic/TrinsicServicesTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
import java.io.IOException;
44
import java.util.concurrent.ExecutionException;
55
import org.junit.jupiter.api.Assertions;
6-
import org.junit.jupiter.api.Disabled;
76
import org.junit.jupiter.api.Test;
87
import trinsic.okapi.DidException;
98
import trinsic.services.AccountService;
109
import trinsic.services.ProviderService;
1110
import trinsic.services.account.v1.AccountInfoRequest;
12-
import trinsic.services.provider.v1.CreateEcosystemRequest;
1311
import trinsic.services.provider.v1.InvitationStatusRequest;
1412
import trinsic.services.provider.v1.InviteRequest;
15-
import trinsic.services.provider.v1.ParticipantType;
1613

1714
class TrinsicServicesTest {
1815

python/samples/provider_demo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ async def provider_demo():
8484
request=UpgradeDidRequest(
8585
wallet_id=wallet_id,
8686
method=SupportedDidMethod.ION,
87-
ion_options=IonOptions(
88-
network=IonOptionsIonNetwork.TestNet
89-
)
87+
ion_options=IonOptions(network=IonOptionsIonNetwork.TestNet),
9088
)
9189
)
9290
# }

0 commit comments

Comments
 (0)