Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve update tool #3395

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions tools/update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ Above will update the rest of the dependencies to:
- flow-go-sdk `v0.31.0`
- flow-go `v0.26.0`

Instead of the version, it is also possible to provide a commit id.
Instead of the version, it is also possible to provide a commit,
in Go's expected format, i.e. the first 12 characters of the commit hash.

```sh
GH_TOKEN=`gh auth token` ts-node main.ts update --version v0.30.0 --versions onflow/flow-go@<commit_id>
GH_TOKEN=`gh auth token` ts-node main.ts update --version v0.30.0 --versions onflow/flow-go@<commit>
```

#### Configuring dependencies
Expand Down Expand Up @@ -195,20 +196,15 @@ Go to the link that is shown at the end to create a new GitHub (pre-)release for

Once the GitHub release has been published, re-run the `update` subcommand. The tool will determine that the next dependency needs to be updated.

> [!NOTE]
> The update tool only considers proper releases (i.e. not pre-releases)! (this is a GitHub API limitation)
>
> When updating to pre-releases, the version of a downstream has to be specified manually! This is not needed normally.

Versions are specified using the `--versions` flag, comma-separated.

```shell
GH_TOKEN=`gh auth token` ts-node main.ts update \
--version v1.0.0-M8 \
--versions onflow/flow-go-sdk@v1.0.0-M5
--version v1.0.0-M8
```

Again, the tool will determine the next downstream dependency that needs to get updated. This time is the `lint` module in the `onflow/cadence-tools` repo.
Again, the tool will determine the next downstream dependency that needs to get updated.
This time is the `lint` module in the `onflow/cadence-tools` repo.

<details>
<summary>
Expand Down Expand Up @@ -266,14 +262,14 @@ Checking repo onflow/cadence-tools ...

- Some downstream dependencies, like `flow-go`, are not tagged/released.

Use the latest commit instead.
Use the latest commit instead, in Go's expected format, i.e. the first 12 characters of the commit hash.

For example, to `flow-emulator` depends on `flow-go`, and it can be updated using:

```shell
$ GH_TOKEN=`gh auth token` ts-node main.ts update \
--version v1.0.0-M8 \
--versions onflow/flow-go-sdk@v1.0.0-M5,onflow/cadence-tools/lint@v1.0.0-M5,onflow/flow-go@3677206d445c
--versions onflow/flow-go@3677206d445c
```

- Some downstream dependencies are modules in the same repo.
Expand Down
13 changes: 11 additions & 2 deletions tools/update/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,20 @@ class Updater {
async fetchLatestReleaseTagName(fullRepoName: string): Promise<string | null> {
try {
const [owner, repoName] = fullRepoName.split('/')
const release = await this.octokit.rest.repos.getLatestRelease({
// Heuristic: Fetch as many releases on the first page as possible,
// and find the latest release by sorting the releases by semver
const releases = await this.octokit.rest.repos.listReleases({
owner,
repo: repoName,
per_page: 100
})
return release.data.tag_name
const release = releases.data.sort((a, b) => {
return a.created_at.localeCompare(b.created_at)
}).pop()
if (release === undefined) {
return null
}
return release.tag_name
} catch (e) {
if (e instanceof RequestError) {
if (e.status === 404) {
Expand Down
Loading