Skip to content

Commit

Permalink
Merge #10896
Browse files Browse the repository at this point in the history
10896: Remove experimental github support r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Remove experimental support of github releases for plugin sources. We now have support for this via `github:` download urls.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
  • Loading branch information
bors[bot] and Frassle committed Oct 4, 2022
2 parents ada82e6 + 6bfb453 commit ca6687f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
changes:
- type: feat
scope: cli/about,plugin
description: >
Remove experimental feature for plugins from private github releases.
This is now supported by `github:` plugin urls, see
https://www.pulumi.com/docs/guides/pulumi-packages/how-to-author/#support-for-github-releases.
69 changes: 4 additions & 65 deletions sdk/go/common/workspace/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,50 +411,17 @@ func urlMustParse(rawURL string) *url.URL {
func (source *fallbackSource) GetLatestVersion(
getHTTPResponse func(*http.Request) (io.ReadCloser, int64, error)) (*semver.Version, error) {

// Try and get this package from public pulumi github
// Try and get this package from our public pulumi github
public, err := newGithubSource(urlMustParse("github://api.github.com/pulumi"), source.name, source.kind)
if err != nil {
return nil, err
}
version, err := public.GetLatestVersion(getHTTPResponse)
if err == nil {
return version, nil
}

// Are we in experimental mode? Try a users private github release
if _, ok := os.LookupEnv("PULUMI_EXPERIMENTAL"); ok {
// Check if we have a repo owner set
repoOwner := os.Getenv("GITHUB_REPOSITORY_OWNER")
var privateErr error
if repoOwner == "" {
privateErr = errors.New("ENV[GITHUB_REPOSITORY_OWNER] not set")
} else {
// This could panic on user input, but this is experimental and will be removed at some point
private, err := newGithubSource(urlMustParse("github://api.github.com/"+repoOwner), source.name, source.kind)
if err != nil {
return nil, err
}
if !private.HasAuthentication() {
privateErr = errors.New("no GitHub authentication information provided")
} else {
logging.V(1).Infof("downloading plugins based on GITHUB_REPOSITORY_OWNER is deprecated, " +
"please use a github download URL instead: " +
"https://www.pulumi.com/docs/guides/pulumi-packages/how-to-author/#support-for-github-releases")
version, privateErr = private.GetLatestVersion(getHTTPResponse)
if privateErr == nil {
return version, nil
}
}
}

logging.V(1).Infof("cannot find plugin %s on private GitHub releases: %s", source.name, privateErr.Error())

return nil, fmt.Errorf(
"error getting version from Pulumi github: %w\nand from private github: %s",
err, privateErr.Error())
if err != nil {
return nil, err
}

return nil, err
return version, nil
}

func (source *fallbackSource) Download(
Expand All @@ -470,34 +437,6 @@ func (source *fallbackSource) Download(
return resp, length, nil
}

// Are we in experimental mode? Try a private github release
if _, ok := os.LookupEnv("PULUMI_EXPERIMENTAL"); ok {
// Check if we have a repo owner set
repoOwner := os.Getenv("GITHUB_REPOSITORY_OWNER")
if repoOwner == "" {
err = errors.New("ENV[GITHUB_REPOSITORY_OWNER] not set")
} else {
var private *githubSource
private, err = newGithubSource(urlMustParse("github://api.github.com/"+repoOwner), source.name, source.kind)
if err != nil {
return nil, -1, err
}
if !private.HasAuthentication() {
err = errors.New("no GitHub authentication information provided")
} else {
logging.V(1).Infof("downloading plugins based on GITHUB_REPOSITORY_OWNER is deprecated, " +
"please use a github download URL instead: " +
"https://www.pulumi.com/docs/guides/pulumi-packages/how-to-author/#support-for-github-releases")
resp, length, err := private.Download(version, opSy, arch, getHTTPResponse)
if err == nil {
return resp, length, nil
}
}
}

logging.V(1).Infof("cannot find plugin %s on private GitHub releases: %s", source.name, err.Error())
}

// Fallback to get.pulumi.com
pulumi := newGetPulumiSource(source.name, source.kind)
return pulumi.Download(version, opSy, arch, getHTTPResponse)
Expand Down
83 changes: 0 additions & 83 deletions sdk/go/common/workspace/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,56 +378,6 @@ func TestPluginDownload(t *testing.T) {
assert.Equal(t, int(l), len(readBytes))
assert.Equal(t, expectedBytes, readBytes)
})
t.Run("Test Downloading From GitHub Private Releases", func(t *testing.T) {
t.Setenv("PULUMI_EXPERIMENTAL", "true")
t.Setenv("GITHUB_REPOSITORY_OWNER", "private")
t.Setenv("GITHUB_TOKEN", token)
version := semver.MustParse("1.22.0")
spec := PluginSpec{
PluginDownloadURL: "",
Name: "private",
Version: &version,
Kind: PluginKind("resource"),
}
source, err := spec.GetSource()
assert.NoError(t, err)
getHTTPResponse := func(req *http.Request) (io.ReadCloser, int64, error) {
// Test that the asset isn't on pulumi github
if req.URL.String() == "https://api.github.com/repos/pulumi/pulumi-private/releases/tags/v1.22.0" {
return nil, -1, errors.New("404 not found")
}

if req.URL.String() == "https://api.github.com/repos/private/pulumi-private/releases/tags/v1.22.0" {
assert.Equal(t, fmt.Sprintf("token %s", token), req.Header.Get("Authorization"))
assert.Equal(t, "application/json", req.Header.Get("Accept"))
// Minimal JSON from the releases API to get the test to pass
return newMockReadCloserString(`{
"assets": [
{
"url": "https://api.github.com/repos/private/pulumi-private/releases/assets/654321",
"name": "pulumi-private_1.22.0_checksums.txt"
},
{
"url": "https://api.github.com/repos/private/pulumi-private/releases/assets/123456",
"name": "pulumi-resource-private-v1.22.0-darwin-amd64.tar.gz"
}
]
}
`)
}

assert.Equal(t, "https://api.github.com/repos/private/pulumi-private/releases/assets/123456", req.URL.String())
assert.Equal(t, fmt.Sprintf("token %s", token), req.Header.Get("Authorization"))
assert.Equal(t, "application/octet-stream", req.Header.Get("Accept"))
return newMockReadCloser(expectedBytes)
}
r, l, err := source.Download(*spec.Version, "darwin", "amd64", getHTTPResponse)
assert.NoError(t, err)
readBytes, err := ioutil.ReadAll(r)
assert.NoError(t, err)
assert.Equal(t, int(l), len(readBytes))
assert.Equal(t, expectedBytes, readBytes)
})
t.Run("Test Downloading From Private Pulumi GitHub Releases", func(t *testing.T) {
t.Setenv("GITHUB_TOKEN", token)
version := semver.MustParse("4.32.0")
Expand Down Expand Up @@ -632,39 +582,6 @@ func TestPluginGetLatestVersion(t *testing.T) {
assert.Nil(t, version)
assert.Equal(t, "GetLatestVersion is not supported for plugins using PluginDownloadURL", err.Error())
})
t.Run("Test GetLatestVersion From GitHub Private Releases", func(t *testing.T) {
t.Setenv("PULUMI_EXPERIMENTAL", "true")
t.Setenv("GITHUB_REPOSITORY_OWNER", "private")
t.Setenv("GITHUB_TOKEN", token)
spec := PluginSpec{
PluginDownloadURL: "",
Name: "private",
Kind: PluginKind("resource"),
}
expectedVersion := semver.MustParse("1.0.2")
source, err := spec.GetSource()
assert.NoError(t, err)
getHTTPResponse := func(req *http.Request) (io.ReadCloser, int64, error) {
// Test that the asset isn't on github
if req.URL.String() == "https://api.github.com/repos/pulumi/pulumi-private/releases/latest" {
return nil, -1, errors.New("404 not found")
}

if req.URL.String() == "https://api.github.com/repos/private/pulumi-private/releases/latest" {
assert.Equal(t, fmt.Sprintf("token %s", token), req.Header.Get("Authorization"))
assert.Equal(t, "application/json", req.Header.Get("Accept"))
// Minimal JSON from the releases API to get the test to pass
return newMockReadCloserString(`{
"tag_name": "v1.0.2"
}`)
}

panic("Unexpected call to getHTTPResponse")
}
version, err := source.GetLatestVersion(getHTTPResponse)
assert.NoError(t, err)
assert.Equal(t, expectedVersion, *version)
})
t.Run("Test GetLatestVersion From Private Pulumi GitHub Releases", func(t *testing.T) {
t.Setenv("GITHUB_TOKEN", token)
spec := PluginSpec{
Expand Down

0 comments on commit ca6687f

Please sign in to comment.