8000 [WIP] Create Go scripts which automate individual release steps by galargh · Pull Request #9493 · ipfs/kubo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[WIP] Create Go scripts which automate individual release steps #9493

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b816e65
feat: start expressing release checlist items as mage targets
galargh Dec 7, 2022
2770954
feat: handle repo modifications
galargh Dec 8, 2022
5c7df3b
feat: add func for creating and linking changelog
galargh Dec 8, 2022
4198879
feat: add funcs for cutting release and updating version
galargh Dec 9, 2022
41c0f88
fix: oustanding tasks check
galargh Dec 13, 2022
93bcac1
feat: add script for updating dev version in main
galargh Dec 13, 2022
75132f0
feat: add script for checking release PR CI
galargh Dec 13, 2022
c582c70
fix: version string in the release branch
galargh Dec 13, 2022
51abe0b
feat: add script for creating distributions PRs
galargh Dec 13, 2022
fc4750c
docs: document TODOs
galargh Dec 13, 2022
527d4c4
feat: automate checking dist.ipfs.tech
galargh Dec 13, 2022
2f2104b
feat: add scripts automating npm publishing
galargh Dec 13, 2022
da74510
feat: add scripts for creating github releases
galargh Dec 13, 2022
cde8b15
feat: perform npm publishing
galargh Dec 13, 2022
cf99f59
feat: replace dagger with git-go
galargh Dec 13, 2022
f39955a
chore: add todo
galargh Dec 13, 2022
877743b
feat: add script for syncing release assets
galargh Dec 13, 2022
1765565
fix: how we use git-go to interact with git inside docker
galargh Dec 15, 2022
40be88d
feat: add script for creating signed tags
galargh Dec 15, 2022
ee87161
feat: test ipfs-desktop
galargh Dec 16, 2022
c0475bf
chore: simplify running km in docker
galargh Dec 20, 2022
6eec43a
chore: go mod tidy
galargh Dec 20, 2022
b311d2f
feat: fix logs retrieval and implement companion test automation
galargh Dec 22, 2022
2e34bbc
chore: combined improvements from v0.18.0-rc2
galargh Jan 4, 2023
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
3 changes: 3 additions & 0 deletions internal/mage/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
build
run
11 changes: 11 additions & 0 deletions internal/mage/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -ex

GITHUB_TOKEN="${GITHUB_TOKEN}"
GITHUB_USER_NAME="${GITHUB_USER_NAME:-$(git config --global user.name)}"
GITHUB_USER_EMAIL="${GITHUB_USER_EMAIL:-$(git config --global user.email)}"

GPG_ID="${GPG_ID:-$(git config --global user.signingkey)}"
GPG_KEY="$(echo "${GPG_KEY:-$(gpg --armor --pinentry-mode=loopback --passphrase "$GPG_PASSPHRASE" --export-secret-key "$GPG_ID" -w0)}" | base64 -w0)"
GPG_PASSPHRASE="${GPG_PASSPHRASE}"
19 changes: 19 additions & 0 deletions internal/mage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.19-alpine3.17 AS builder

RUN apk update && apk add --no-cache \
build-base
ADD . /src
WORKDIR /src
RUN go run main.go -compile /usr/bin/km

FROM alpine:3.17

RUN apk update && apk add --no-cache \
bash \
zsh \
npm \
diffutils

COPY --from=builder /usr/bin/km /usr/bin/km

ENTRYPOINT [ "/usr/bin/km" ]
17 changes: 17 additions & 10000 ; 0 deletions internal/mage/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- [x] tag creation
- [ ] auto-merge
- [ ] reviewer assignment
- [ ] checking the status of a PR: mergeability, conflicts, open/closed, etc.
- [x] run commands in Docker
- [x] test git-go
- [ ] check if protocol.version 2 is used for fetch
- [x] fix util.GetWorkflowRunLogs
- [ ] check if there's discourse API
- [ ] mention early testers through GitHub API
- [ ] run exec commands with streaming output
- [ ] when checking if PR exists, check if it wasn't closed too
- [ ] check worklow run status in distribution
- [ ] npm ci check should retrieve the latest run
- [ ] check sync status through command
- [ ] fix creating comment in the bifrost issue
- [ ] automate rc* announcement in the release issue
87 changes: 87 additions & 0 deletions internal/mage/bifrost/issue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package bifrost

import (
"context"
"fmt"

"github.com/ipfs/kubo/internal/mage/kubo"
"github.com/ipfs/kubo/internal/mage/util"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
)

type Issue mg.Namespace

const (
owner = "protocol"
repo = "bifrost-infra"
)

func getIssueTitle(version string) string {
return "Rollout Kubo " + version + " to a Cluster, Gateway and Bootstrapper bank"
}

func getIssueBody(version, url string) string {
return fmt.Sprintf(
`Related to %s

This issue is to track the rollout of Kubo %s to a Cluster, Gateway and Bootstrapper bank.`,
url, version)
}

func getCommentBody(version string) string {
return "TEST"
}

func (Issue) CreateIssue(ctx context.Context, version string) error {
title := getIssueTitle(version)

i, err := util.GetIssue(ctx, owner, repo, title)
if err != nil {
return err
}
if i != nil {
fmt.Printf("Issue already exists: %s", i.GetHTMLURL())
return nil
}

ki, err := kubo.GetIssue(ctx, version)
if err != nil {
return err
}
if ki == nil {
return fmt.Errorf("kubo issue not found")
}

body := getIssueBody(version, ki.GetHTMLURL())

i, err = util.CreateIssue(ctx, owner, repo, title, body)
if err != nil {
return err
}

fmt.Printf("Issue created: %s", i.GetHTMLURL())
return nil
}

func (Issue) CreateIssueComment(ctx context.Context, version string) error {
title := getIssueTitle(version)
body := getCommentBody(version)

comment, err := util.GetIssueComment(ctx, owner, repo, title, body)
if err != nil {
return err
}

if comment != nil {
fmt.Printf("Comment already exists: %s", comment.GetHTMLURL())
return nil
}

comment, err = util.CreateIssueComment(ctx, owner, repo, title, body)
if err != nil {
return err
}

fmt.Printf("Comment created: %s", comment.GetHTMLURL())
return nil
}
54 changes: 54 additions & 0 deletions internal/mage/companion/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package companion

import (
"context"
"fmt"
"strings"

"github.com/ipfs/kubo/internal/mage/util"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
)

type Test mg.Namespace

const (
Owner = "ipfs"
Repo = "ipfs-companion"
DefaultBranchName = "main"
TestWorklowFile = "e2e.yml"
)

func (Test) InitTest(ctx context.Context, version string) error {
return util.CreateWorkflowRun(ctx, Owner, Repo, TestWorklowFile, DefaultBranchName, util.WorkflowRunInput{Name: "kubo-version", Value: version})
}

func (Test) CheckTest(ctx context.Context, version string) error {
run, err := util.GetWorkflowRun(ctx, Owner, Repo, TestWorklowFile, false)
if err != nil {
return err
}

if (run.GetStatus() != "completed") {
return fmt.Errorf("the latest run is not completed yet")
}

logs, err := util.GetWorkflowRunLogs(ctx, Owner, Repo, run.GetID())
if err != nil {
return err
}

test := logs.JobLogs["test"]
if test == nil {
return fmt.Errorf("the latest run does not have a test job")
}

if ! strings.Contains(test.RawLogs, fmt.Sprintf("KUBO_VERSION: %s", version)) {
return fmt.Errorf("the latest run is not for version %s", version)
}

if run.GetConclusion() == "success" {
fmt.Println("The latest run succeeded")
return nil
}
return fmt.Errorf("the latest run did not succeed")
}
147 changes: 147 additions & 0 deletions internal/mage/desktop/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package desktop

import (
"context"
"fmt"
"os"
"os/exec"
"strings"

"github.com/ipfs/kubo/internal/mage/kubo"
"github.com/ipfs/kubo/internal/mage/util"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
"golang.org/x/mod/semver"
)

type Main mg.Namespace

const (
Owner = "ipfs"
Repo = "ipfs-desktop"
DefaultBranchName = "main"
)

func getUpgradeBranchName(version string) string {
return "kubo-upgrade-" + semver.MajorMinor(version)
}

func getUpgradePRTitle(version string) string {
return "Kubo Upgrade: " + semver.MajorMinor(version)
}

func getUpgradePRBody(version, url string) string {
return fmt.Sprintf(
`Related to %s

This PR is to upgrade Kubo to %s.`,
url, version)
}

func (Main) CreateOrUpdateUpgradePR(ctx context.Context, version string) error {
versions, err := util.GetFile(ctx, Owner, Repo, "package.json", DefaultBranchName)
if err != nil {
return err
}

if strings.Contains(*versions.Content, version) {
fmt.Println("Dist has already been released")
return nil
}

head := getUpgradeBranchName(version)

branch, err := util.GetBranch(ctx, Owner, Repo, head)
if err != nil {
return err
}
if branch == nil {
branch, err = util.CreateBranch(ctx, Owner, Repo, head, DefaultBranchName)
if err != nil {
return err
}
}

versions, err = util.GetFile(ctx, Owner, Repo, "package.json", head)
if err != nil {
return err
}

pr, err := util.GetPR(ctx, Owner, Repo, head)
if err != nil {
return err
}

if ! strings.Contains(*versions.Content, version) {
dir, err := os.MkdirTemp("", "desktop")
if err != nil {
return err
}
defer os.RemoveAll(dir)

err = util.GitClone(dir, Owner, Repo, branch.GetName(), branch.GetCommit().GetSHA())
if err != nil {
return err
}

cmd := exec.Command("npm", "install", "go-ipfs@" + version, "--save")
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(string(out))
return err
}

err = util.GitCommit(dir, "package*.json", "chore: upgrade go-ipfs "+version)
if err != nil {
return err
}
err = util.GitPushBranch(dir, head)
if err != nil {
return err
}
} else {
fmt.Println("Branch has already been updated")
}

if pr == nil {
ki, err := kubo.GetIssue(ctx, version)
if err != nil {
return err
}

title := getUpgradePRTitle(version)
body := getUpgradePRBody(version, ki.GetHTMLURL())

pr, err = util.CreatePR(ctx, Owner, Repo, head, DefaultBranchName, title, body, true)
if err != nil {
return err
}

fmt.Printf("PR created: %s", pr.GetHTMLURL())
} else {
fmt.Println("PR has already been created")
}

return nil
}

func (Main) CheckCI(ctx context.Context, version string) error {
head := getUpgradeBranchName(version)

runs, err := util.GetCheckRuns(ctx, Owner, Repo, head)
if err != nil {
return err
}

for _, run := range runs {
if run.GetStatus() != "completed" {
return fmt.Errorf("check %s is not completed", run.GetName())
}
if run.GetConclusion() != "success" {
return fmt.Errorf("check %s is not successful", run.GetName())
}
}

fmt.Println("All checks are successful")
return nil
}
31 changes: 31 additions & 0 deletions internal/mage/discourse/post.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package discourse

import (
"context"
"fmt"

"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
"golang.org/x/mod/semver"
)

type Post mg.Namespace

func (Post) GetTitle(ctx context.Context, version string) error {
fmt.Printf("Kubo %s Release Candidate is out!\n", version)
return nil
}

func (Post) GetBody(ctx context.Context, version string) error {
mm := semver.MajorMinor(version)
fmt.Printf(
`## Kubo %s Release Candidate is out!

See:
- Code: https://github.com/ipfs/kubo/releases/tag/%s
- Binaries: https://dist.ipfs.tech/kubo/%s/
- Docker: `+"`"+`docker pull ipfs/kubo:%s`+"`"+`
- Release Notes (WIP): https://github.com/ipfs/kubo/blob/release-%s/docs/changelogs/%s.md
`,
version, version, version, version, mm, mm)
return nil
}
Loading
0