Skip to content

Commit

Permalink
Update Rust document (#3336)
Browse files Browse the repository at this point in the history
* Update Rust document

* sdk-shell-rust target

* help me git command

* modify crate link

* tab issue

* publish rust sdk with sh file

* sdk-publish-rust target works

* uncomment cargo publish

* condition added to do actual cargo publish

* included API token link

* Script for Updating Agones Version in Cargo.toml

* Resolve lint issue

* suggested changes
  • Loading branch information
Kalaiselvi84 committed Aug 26, 2023
1 parent 1d56975 commit 176431c
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 8 deletions.
35 changes: 35 additions & 0 deletions build/build-sdk-images/rust/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Copyright 2023 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

cd ./sdks/rust/proto/sdk

# Authenticate with crates.io
read -p 'Crates.io API Token: ' TOKEN
cargo login $TOKEN

# Perform a dry run of cargo publish
dry_run_output=$(cargo publish --dry-run 2>&1)

# Check if the dry run output contains the warning about aborting upload
if echo "$dry_run_output" | grep -q "warning: aborting upload due to dry run"; then
echo "Actual Cargo Publish begins.."
# Dry run succeeded, proceed to actual publishing
cargo publish
else
echo "Dry run failed. Aborting actual publishing."
fi
8 changes: 8 additions & 0 deletions build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ sdk-publish-csharp: RELEASE_VERSION ?= $(base_version)
sdk-publish-csharp:
$(MAKE) run-sdk-command-csharp COMMAND=publish VERSION=$(RELEASE_VERSION) DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -it"

# SDK shell for rust
sdk-shell-rust:
$(MAKE) sdk-shell SDK_FOLDER=rust

# Publish the Rust SDK to crates.io
sdk-publish-rust:
$(MAKE) run-sdk-command-rust VERSION=$(RELEASE_VERSION) DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -it" COMMAND=publish

# difference in sdks before and after gen-all-sdk-grpc target
test-gen-all-sdk-grpc:
make gen-all-sdk-grpc
Expand Down
5 changes: 5 additions & 0 deletions build/includes/website.mk
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ site-config-update-version: ensure-build-image
docker run --rm $(common_mounts) --workdir=$(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) \
go run build/scripts/site-config-update-version/main.go

# update release version agones package in sdks/rust/Cargo.toml
sdks-rust-cargo-version-update: ensure-build-image
docker run --rm $(common_mounts) --workdir=$(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) \
go run build/scripts/sdks-rust-cargo-version-update/main.go

# Delete old release version in site/layouts/partials/navbar.html.
update-navbar-version: FILENAME ?= ""
update-navbar-version: ensure-build-image
Expand Down
118 changes: 118 additions & 0 deletions build/scripts/sdks-rust-cargo-version-update/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2023 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package main implements a program that updates the version of Agones package in sdks/rust/Cargo.toml file.
package main

import (
"bufio"
"log"
"os"
"regexp"
"strconv"
"strings"
)

func main() {
configFile := "sdks/rust/Cargo.toml"
content, err := os.ReadFile(configFile)
if err != nil {
log.Println("Read File: ", err)
}

var lines []string
lines = append(lines, strings.Split(string(content), "\n")...)

updatedLines := updateReleaseValues(lines)

err = writeLinesToFile(configFile, updatedLines)
if err != nil {
log.Println("Write File: ", err)
}
}

func updateReleaseValues(lines []string) []string {
var updatedLines []string

shouldUpdateVersion := false

for _, line := range lines {
updatedLine := line

if strings.Contains(line, `name = "agones"`) {
shouldUpdateVersion = true
}

// Update the version if the flag is set
if shouldUpdateVersion && strings.HasPrefix(line, "version") {
re := regexp.MustCompile(`"[^"]+"`)
match := re.FindString(line)
if match != "" {
version := strings.Trim(match, `"`)

segments := strings.Split(version, ".")

if len(segments) == 3 {
secondSegment, _ := strconv.Atoi(segments[1])
secondSegment++
segments[1] = strconv.Itoa(secondSegment)
updatedVersion := strings.Join(segments, ".")
updatedLine = strings.Replace(line, version, updatedVersion, 1)
}
}

// Reset the flag after updating the version
shouldUpdateVersion = false
}

updatedLines = append(updatedLines, updatedLine)
}

return updatedLines
}

func writeLinesToFile(filePath string, lines []string) error {
file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0o644)
if err != nil {
return err
}
defer func() {
if cerr := file.Close(); cerr != nil {
log.Println(err)
}
}()

writer := bufio.NewWriter(file)

for i, line := range lines {
if i < len(lines)-1 {
_, err := writer.WriteString(line + "\n")
if err != nil {
return err
}
} else {
_, err := writer.WriteString(line)
if err != nil {
return err
}
}
}

err = writer.Flush()
if err != nil {
return err
}

return nil
}
3 changes: 2 additions & 1 deletion docs/governance/templates/release_issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ and copy it into a release issue. Fill in relevant values, found inside {}
- [ ] Post to the [agonesdev](https://twitter.com/agonesdev) Twitter account.
- [ ] Run `git checkout main`.
- [ ] Run `make sdk-update-version release_stage=after version={version}` file. This command will update the version number in the sdks/install files to {version}+1-dev.
- [ ] Update the `agones` crate version in `sdks/rust/Cargo.toml` to {version}, then run `cargo publish --dry-run` and, if successful, proceed with `cargo publish`
- [ ] Run `make sdks-rust-cargo-version-update`. Commit the changes in a feature branch called `prep/{version}+1`.
- [ ] Run `make sdk-publish-rust`. This command executes `cargo login` for authentication, performs a dry-run publish, and if that succeeds, does the actual publish. Will need [crate's API TOKEN](https://crates.io/settings/tokens) from your crate's account.
- [ ] Create PR with these changes, and merge them with approval
- [ ] Close this issue. _Congratulations!_ - the release is now complete! :tada: :clap: :smile: :+1:

Expand Down
10 changes: 3 additions & 7 deletions site/content/en/docs/Guides/Client SDKs/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,20 @@ Check the [Client SDK Documentation]({{< relref "_index.md" >}}) for more detail
| Player Tracking | PlayerDisconnect | ✔️ |
| Player Tracking | SetPlayerCapacity | ✔️ |

## Download

Download the source {{< ghlink href="sdks/rust" >}}directly from GitHub{{< /ghlink >}}.

## Prerequisites

- [Rust >= 1.50](https://www.rust-lang.org/tools/install)

## Usage

Add this crate to `dependencies` section in your Cargo.toml. Specify a directory where this README.md is located to the `path`.
Add <a href="https://crates.io/crates/agones" data-proofer-ignore>this crate</a> to `dependencies` section in your Cargo.toml.

Also note that the SDK is [`async`](https://doc.rust-lang.org/std/keyword.async.html) only, so you will need an async runtime to execute the futures exposed by the SDK. It is recommended to use [tokio](https://docs.rs/tokio) as the SDK already depends on tokio due to its choice of gRPC library, [tonic](https://docs.rs/tonic).

```toml
[dependencies]
agones = { path = "../agones/sdks/rust" }
tokio = { version = "1.7", features = ["macros", "sync"] }
agones = "1.34.0"
tokio = { version = "1.32.0", features = ["macros", "sync"] }
```

To begin working with the SDK, create an instance of it.
Expand Down

0 comments on commit 176431c

Please sign in to comment.