Skip to content

Commit

Permalink
Skip publish for v1 canary and latest (#1641)
Browse files Browse the repository at this point in the history
* Change permalinks to prefix with canary/latest

I was running into conflict with how we detect versions with the other
tagging scheme (v1-latest would get flagged as a real release).
Switching the order so that it's latest-v1 will help avoid a bunch of
false positives and workarounds.

* Only publish v*, latest and canary

Do not publish latest-* or canary-* for simplicity

Signed-off-by: Carolyn Van Slyck <[email protected]>
  • Loading branch information
carolynvs committed Jun 15, 2021
1 parent 0eb6618 commit 976b4b6
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 101 deletions.
9 changes: 7 additions & 2 deletions build/azure-pipelines.release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
trigger:
branches:
tags:
include:
- refs/tags/v*
- "v*"
exclude:
# We tag a release for canary-v1 or latest-v1 because of how we host our binaries with GitHub releases.
# Do not trigger another release when we create these tags during the release process, preventing an infinite recursion of release builds.
- "latest*"
- "canary*"

# Do not run on pull requests
pr: none
Expand Down
2 changes: 1 addition & 1 deletion docs/content/project/version-strategy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ Porter v1 will include a number of breaking changes that we are grouping togethe
The final release from the v1 branch will be v1.0.0.
* The release/v1 branch will be merged into main, and then the v1.0.0 release is cut.
* The latest and canary builds continue to be based on builds of the main branch only.
We may provide v1-latest and v1-canary builds at a later date.
We may provide latest-v1 and canary-v1 builds at a later date.

[semver v2]: https://semver.org/spec/v2.0.0.html
15 changes: 10 additions & 5 deletions mage/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type GitMetadata struct {
IsTaggedRelease bool
}

func (m GitMetadata) ShouldPublishPermalink() bool {
// For now don't publish canary-v1 or latest-v1 to keep things simpler
return m.Permalink == "canary" || m.Permalink == "latest"
}

// LoadMetadata populates the status of the current working copy: current version, tag and permalink
func LoadMetadata() GitMetadata {
loadMetadata.Do(func() {
Expand Down Expand Up @@ -96,21 +101,21 @@ func getBranchName() string {
func getPermalink() (string, bool) {
// Use latest for tagged commits
taggedRelease := false
permalinkSuffix := "canary"
permalinkPrefix := "canary"
err := shx.RunS("git", "describe", "--tags", "--match=v*", "--exact")
if err == nil {
permalinkSuffix = "latest"
permalinkPrefix = "latest"
taggedRelease = true
}

// Get the current branch name, or the name of the branch we tagged from
branch := getBranchName()

// Build a permalink such as "canary", "latest", "v1-latest", etc
// Build a permalink such as "canary", "latest", "latest-v1", or "canary-v1"
switch branch {
case "main":
return permalinkSuffix, taggedRelease
return permalinkPrefix, taggedRelease
default:
return fmt.Sprintf("%s-%s", strings.TrimPrefix(branch, "release/"), permalinkSuffix), taggedRelease
return fmt.Sprintf("%s-%s", permalinkPrefix, strings.TrimPrefix(branch, "release/")), taggedRelease
}
}
33 changes: 21 additions & 12 deletions mage/releases/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"path/filepath"
"strings"

"get.porter.sh/porter/mage"
"get.porter.sh/porter/mage/tools"
Expand Down Expand Up @@ -95,15 +96,19 @@ func publishPackage(pkgType string, name string) {
remote := fmt.Sprintf("https://%s.git", repo)
versionDir := filepath.Join("bin", pkgType+"s", name, info.Version)

// Move the permalink tag. The existing release automatically points to the tag.
must.RunV("git", "tag", info.Permalink, info.Version+"^{}", "-f")
must.RunV("git", "push", "-f", remote, info.Permalink)

// Create or update GitHub release for the permalink (canary/latest) with the version's binaries
AddFilesToRelease(repo, info.Permalink, versionDir)
if info.ShouldPublishPermalink() {
// Move the permalink tag. The existing release automatically points to the tag.
must.RunV("git", "tag", info.Permalink, info.Version+"^{}", "-f")
must.RunV("git", "push", "-f", remote, info.Permalink)

AddFilesToRelease(repo, info.Permalink, versionDir)
} else {
fmt.Println("Skipping publish package for permalink", info.Permalink)
}

// Create GitHub release for the exact version (v1.2.3) and attach assets
if info.IsTaggedRelease {
// Create GitHub release for the exact version (v1.2.3) and attach assets
AddFilesToRelease(repo, info.Version, versionDir)
}
}
Expand All @@ -116,12 +121,16 @@ func PublishMixin(mixin string) {
// Publish a plugin's binaries.
func PublishPlugin(plugin string) {
publishPackage("plugin", plugin)

}

func publishPackageFeed(pkgType string, name string) {
info := mage.LoadMetadata()

if !info.ShouldPublishPermalink() {
fmt.Println("Skipping publish package feed for permalink", info.Permalink)
return
}

// Clone the packages repository
if _, err := os.Stat(packagesRepo); !os.IsNotExist(err) {
os.RemoveAll(packagesRepo)
Expand Down Expand Up @@ -168,20 +177,20 @@ func GeneratePluginFeed() {

// AddFilesToRelease uploads the files in the specified directory to a GitHub release.
// If the release does not exist already, it will be created with empty release notes.
func AddFilesToRelease(repo string, version string, dir string) {
func AddFilesToRelease(repo string, tag string, dir string) {
files := listFiles(dir)

// Mark canary releases as a draft
draft := ""
if version == "canary" {
if strings.HasPrefix(tag, "canary") {
draft = "-p"
}

if releaseExists(repo, version) {
must.Command("gh", "release", "upload", "--clobber", "-R", repo, version).
if releaseExists(repo, tag) {
must.Command("gh", "release", "upload", "--clobber", "-R", repo, tag).
Args(files...).RunV()
} else {
must.Command("gh", "release", "create", "-R", repo, "-t", version, "--notes=", draft, version).
must.Command("gh", "release", "create", "-R", repo, "-t", tag, "--notes=", draft, tag).
CollapseArgs().Args(files...).RunV()
}
}
Expand Down
86 changes: 76 additions & 10 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,86 @@ func getDualPublish() bool {

func BuildImages() {
info := mage.LoadMetadata()
registry := getRegistry()

must.Command("./scripts/build-images.sh").Env("VERSION="+info.Version, "PERMALINK="+info.Permalink, "REGISTRY="+getRegistry()).RunV()
buildImages(registry, info)
if getDualPublish() {
must.Command("./scripts/build-images.sh").Env("VERSION="+info.Version, "PERMALINK="+info.Permalink, "REGISTRY=ghcr.io/getporter").RunV()
buildImages("ghcr.io/getporter", info)
}
}

func buildImages(registry string, info mage.GitMetadata) {
var g errgroup.Group

g.Go(func() error {
img := fmt.Sprintf("%s/porter:%s", registry, info.Version)
err := shx.RunV("docker", "build", "-t", img, "-f", "build/images/client/Dockerfile", ".")
if err != nil {
return err
}

err = shx.Run("docker", "tag", img, fmt.Sprintf("%s/porter:%s", registry, info.Permalink))
if err != nil {
return err
}

// porter-agent does a FROM porter so they can't go in parallel
img = fmt.Sprintf("%s/porter-agent:%s", registry, info.Version)
err = shx.RunV("docker", "build", "-t", img, "--build-arg", "PORTER_VERSION="+info.Version, "--build-arg", "REGISTRY="+registry, "-f", "build/images/agent/Dockerfile", "build/images/agent")
if err != nil {
return err
}

return shx.Run("docker", "tag", img, fmt.Sprintf("%s/porter-agent:%s", registry, info.Permalink))
})

g.Go(func() error {
img := fmt.Sprintf("%s/workshop:%s", registry, info.Version)
err := shx.RunV("docker", "build", "-t", img, "-f", "build/images/workshop/Dockerfile", ".")
if err != nil {
return err
}

return shx.Run("docker", "tag", img, fmt.Sprintf("%s/workshop:%s", registry, info.Permalink))
})

mgx.Must(g.Wait())
}

func PublishImages() {
mg.Deps(BuildImages)

info := mage.LoadMetadata()

must.Command("./scripts/publish-images.sh").Env("VERSION="+info.Version, "PERMALINK="+info.Permalink, "REGISTRY="+getRegistry()).RunV()
pushImagesTo(getRegistry(), info)
if getDualPublish() {
must.Command("./scripts/publish-images.sh").Env("VERSION="+info.Version, "PERMALINK="+info.Permalink, "REGISTRY=ghcr.io/getporter").RunV()
pushImagesTo("ghcr.io/getporter", info)
}
}

// Only push tagged versions, canary and latest
func pushImagesTo(registry string, info mage.GitMetadata) {
if info.IsTaggedRelease {
pushImages(registry, info.Version)
}

if info.ShouldPublishPermalink() {
pushImages(registry, info.Permalink)
} else {
fmt.Println("Skipping image publish for permalink", info.Permalink)
}
}

func pushImages(registry string, tag string) {
pushImage(fmt.Sprintf("%s/porter:%s", registry, tag))
pushImage(fmt.Sprintf("%s/porter-agent:%s", registry, tag))
pushImage(fmt.Sprintf("%s/workshop:%s", registry, tag))
}

func pushImage(img string) {
must.RunV("docker", "push", img)
}

// Publish the porter binaries and install scripts.
func PublishPorter() {
mg.Deps(tools.EnsureGitHubClient, releases.ConfigureGitBot)
Expand All @@ -183,13 +245,17 @@ func PublishPorter() {
}
remote := fmt.Sprintf("https://%s.git", repo)

// Move the permalink tag. The existing release automatically points to the tag.
must.RunV("git", "tag", info.Permalink, info.Version+"^{}", "-f")
must.RunV("git", "push", "-f", remote, info.Permalink)

// Create or update GitHub release for the permalink (canary/latest) with the version's assets (porter binaries, exec binaries and install scripts)
releases.AddFilesToRelease(repo, info.Permalink, porterVersionDir)
releases.AddFilesToRelease(repo, info.Permalink, execVersionDir)
if info.ShouldPublishPermalink() {
// Move the permalink tag. The existing release automatically points to the tag.
must.RunV("git", "tag", info.Permalink, info.Version+"^{}", "-f")
must.RunV("git", "push", "-f", remote, info.Permalink)

releases.AddFilesToRelease(repo, info.Permalink, porterVersionDir)
releases.AddFilesToRelease(repo, info.Permalink, execVersionDir)
} else {
fmt.Println("Skipping publish binaries for permalink", info.Permalink)
}

if info.IsTaggedRelease {
// Create GitHub release for the exact version (v1.2.3) and attach assets
Expand Down
5 changes: 2 additions & 3 deletions pkg/pkgmgmt/feed/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"regexp"
"sort"
"strings"
"time"

"get.porter.sh/porter/pkg/context"
Expand Down Expand Up @@ -127,8 +126,8 @@ var versionRegex = regexp.MustCompile(`\d+-g[a-z0-9]+`)

// As a safety measure, skip versions that shouldn't be put in the feed, we only want canary and tagged releases.
func shouldPublishVersion(version string) bool {
if strings.HasSuffix(version, "canary") {
// Publish canary permalinks
// Publish canary permalinks, for now ignore canary-v1
if version == "canary" {
return true
}

Expand Down
16 changes: 3 additions & 13 deletions pkg/pkgmgmt/feed/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ func TestGenerate(t *testing.T) {
tc.FileSystem.Create("bin/latest/helm-linux-amd64")
tc.FileSystem.Create("bin/latest/helm-windows-amd64.exe")

tc.FileSystem.Create("bin/v2-latest/helm-darwin-amd64")
tc.FileSystem.Create("bin/v2-latest/helm-linux-amd64")
tc.FileSystem.Create("bin/v2-latest/helm-windows-amd64.exe")
tc.FileSystem.Chtimes("bin/v2-latest/helm-darwin-amd64", up4, up4)
tc.FileSystem.Chtimes("bin/v2-latest/helm-linux-amd64", up4, up4)
tc.FileSystem.Chtimes("bin/v2-latest/helm-windows-amd64.exe", up4, up4)
tc.FileSystem.Create("bin/canary-v1/exec-darwin-amd64")
tc.FileSystem.Create("bin/canary-v1/exec-linux-amd64")
tc.FileSystem.Create("bin/canary-v1/exec-windows-amd64.exe")

opts := GenerateOptions{
AtomFile: "atom.xml",
Expand Down Expand Up @@ -230,13 +227,6 @@ func TestGenerate_RegenerateDoesNotCreateDuplicates(t *testing.T) {
tc.FileSystem.Chtimes("bin/canary/exec-linux-amd64", up10, up10)
tc.FileSystem.Chtimes("bin/canary/exec-windows-amd64.exe", up10, up10)

tc.FileSystem.Create("bin/v2-latest/helm-darwin-amd64")
tc.FileSystem.Create("bin/v2-latest/helm-linux-amd64")
tc.FileSystem.Create("bin/v2-latest/helm-windows-amd64.exe")
tc.FileSystem.Chtimes("bin/v2-latest/helm-darwin-amd64", up4, up4)
tc.FileSystem.Chtimes("bin/v2-latest/helm-linux-amd64", up4, up4)
tc.FileSystem.Chtimes("bin/v2-latest/helm-windows-amd64.exe", up4, up4)

opts := GenerateOptions{
AtomFile: "atom.xml",
SearchDirectory: "bin",
Expand Down
11 changes: 0 additions & 11 deletions pkg/pkgmgmt/feed/testdata/atom-existing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
<uri>https://porter.sh/mixins</uri>
</author>
<category term="exec"/>
<category term="helm"/>
<entry>
<id>https://cdn.porter.sh/mixins/v2-latest/helm</id>
<title>helm @ v2-latest</title>
<updated>2013-02-4T00:00:00Z</updated>
<category term="helm"/>
<content>v2-latest</content>
<link rel="download" href="https://cdn.porter.sh/mixins/v2-latest/helm-darwin-amd64" />
<link rel="download" href="https://cdn.porter.sh/mixins/v2-latest/helm-linux-amd64" />
<link rel="download" href="https://cdn.porter.sh/mixins/v2-latest/helm-windows-amd64.exe" />
</entry>
<entry>
<id>https://cdn.porter.sh/mixins/canary/exec</id>
<title>exec @ canary</title>
Expand Down
10 changes: 0 additions & 10 deletions pkg/pkgmgmt/feed/testdata/atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@
<link rel="download" href="https://cdn.porter.sh/mixins/canary/exec-linux-amd64" />
<link rel="download" href="https://cdn.porter.sh/mixins/canary/exec-windows-amd64.exe" />
</entry>
<entry>
<id>https://cdn.porter.sh/mixins/v2-latest/helm</id>
<title>helm @ v2-latest</title>
<updated>2013-02-04T00:00:00Z</updated>
<category term="helm"/>
<content>v2-latest</content>
<link rel="download" href="https://cdn.porter.sh/mixins/v2-latest/helm-darwin-amd64" />
<link rel="download" href="https://cdn.porter.sh/mixins/v2-latest/helm-linux-amd64" />
<link rel="download" href="https://cdn.porter.sh/mixins/v2-latest/helm-windows-amd64.exe" />
</entry>
<entry>
<id>https://cdn.porter.sh/mixins/v1.2.4/helm</id>
<title>helm @ v1.2.4</title>
Expand Down
14 changes: 0 additions & 14 deletions scripts/build-images.sh

This file was deleted.

20 changes: 0 additions & 20 deletions scripts/publish-images.sh

This file was deleted.

0 comments on commit 976b4b6

Please sign in to comment.