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

Replace deprecated GHA ::set-output syntax #980

Merged
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
33 changes: 30 additions & 3 deletions actions/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package actions

import (
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"io"
"log"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -62,8 +65,32 @@ func NewOutputs(uri string, latestVersion *semver.Version, additionalOutputs Out
return outputs, nil
}

func (o Outputs) Write(writer io.Writer) {
// createOrAppend works like os.Create, but instead of replacing (truncating) the file content, it will append to the file, if it already exits.
func createOrAppend(name string) (*os.File, error) {
return os.OpenFile(name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
}

func (o Outputs) Write() {
outputFileName, ok := os.LookupEnv("GITHUB_OUTPUT")
if !ok {
panic(errors.New("GITHUB_OUTPUT is not set, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter"))
}
writer, err := createOrAppend(outputFileName)
if err != nil {
panic(err)
}
defer writer.Close()
delimiter := generateDelimiter()
for k, v := range o {
_, _ = fmt.Fprintf(writer, "::set-output name=%s::%s\n", k, v)
_, _ = fmt.Fprintf(writer, "%s<<%s\n%s\n%s\n", k, delimiter, v, delimiter) // see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
}
}
dmikusa marked this conversation as resolved.
Show resolved Hide resolved

func generateDelimiter() string {
data := make([]byte, 16) // roughly the same entropy as uuid v4 used in https://github.com/actions/toolkit/blob/b36e70495fbee083eb20f600eafa9091d832577d/packages/core/src/file-command.ts#L28
_, err := rand.Read(data)
if err != nil {
log.Fatal("could not generate random delimiter", err)
}
return hex.EncodeToString(data)
}
3 changes: 1 addition & 2 deletions actions/adoptium-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"strings"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down Expand Up @@ -93,7 +92,7 @@ func main() {
outputs["cpe"] = fmt.Sprintf("update%d", latestVersion.Patch())
}

outputs.Write(os.Stdout)
outputs.Write()
}

type Asset struct {
Expand Down
3 changes: 1 addition & 2 deletions actions/alibaba-dragonwell-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"net/http"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -107,5 +106,5 @@ func main() {
outputs["cpe"] = fmt.Sprintf("update%d", latestVersion.Patch())
}

outputs.Write(os.Stdout)
outputs.Write()
}
3 changes: 1 addition & 2 deletions actions/amazon-corretto-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"net/http"
"os"
"regexp"

"github.com/google/go-github/v43/github"
Expand Down Expand Up @@ -117,5 +116,5 @@ func main() {
outputs["cpe"] = fmt.Sprintf("update%d", latestVersion.Patch())
}

outputs.Write(os.Stdout)
outputs.Write()
}
3 changes: 1 addition & 2 deletions actions/appdynamics-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"regexp"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down Expand Up @@ -64,7 +63,7 @@ func main() {
if o, err := versions.GetLatest(inputs, addToken); err != nil {
panic(fmt.Errorf("unable to get latest\n%w", err))
} else {
o.Write(os.Stdout)
o.Write()
}
}

Expand Down
3 changes: 1 addition & 2 deletions actions/aqua-security-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bufio"
"fmt"
"net/http"
"os"

"github.com/paketo-buildpacks/pipeline-builder/actions"
)
Expand Down Expand Up @@ -64,6 +63,6 @@ func main() {
if o, err := versions.GetLatest(inputs, actions.WithBasicAuth(u, p)); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/aternity-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"fmt"
"os"
"regexp"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -53,6 +52,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/azul-zulu-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"

"github.com/paketo-buildpacks/pipeline-builder/actions"
)
Expand Down Expand Up @@ -85,7 +84,7 @@ func main() {
outputs["cpe"] = fmt.Sprintf("update%d", latestVersion.Patch())
}

outputs.Write(os.Stdout)
outputs.Write()
}

type Bundle struct {
Expand Down
3 changes: 1 addition & 2 deletions actions/bellsoft-liberica-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"regexp"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down Expand Up @@ -124,7 +123,7 @@ func main() {
outputs["cpe"] = fmt.Sprintf("update%d", latestVersion.Patch())
}

outputs.Write(os.Stdout)
outputs.Write()
}

type Release struct {
Expand Down
3 changes: 1 addition & 2 deletions actions/ca-apm-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"fmt"
"os"
"regexp"

"github.com/gocolly/colly"
Expand Down Expand Up @@ -70,6 +69,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/cf-java-index-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"
"net/http"
"os"
"regexp"

"github.com/paketo-buildpacks/pipeline-builder/actions"
Expand Down Expand Up @@ -61,6 +60,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/clojure-tools-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"io"
"log"
"net/http"
"os"
"strings"

"github.com/google/go-github/v43/github"
Expand Down Expand Up @@ -105,7 +104,7 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
}
4 changes: 3 additions & 1 deletion actions/compute-artifact-description/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func main() {
}
sort.Strings(deps)

fmt.Printf("::set-output name=artifact-reference-description::%s", strings.Join(deps, "%0A")) // linefeed
actions.Outputs{
"artifact-reference-description": strings.Join(deps, "\n"),
}.Write()
}

func parseMappers(inputs actions.Inputs) []string {
Expand Down
3 changes: 1 addition & 2 deletions actions/foojay-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"regexp"
"strconv"

Expand Down Expand Up @@ -94,7 +93,7 @@ func main() {
outputs["cpe"] = fmt.Sprintf("update%d", latestVersion.Patch())
}

outputs.Write(os.Stdout)
outputs.Write()
}

func LoadPackages(d string, t string, v int) actions.Versions {
Expand Down
3 changes: 1 addition & 2 deletions actions/gcs-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"os"
"regexp"

"cloud.google.com/go/storage"
Expand Down Expand Up @@ -72,6 +71,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/github-release-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"net/http"
"os"
"regexp"
"sort"
"strconv"
Expand Down Expand Up @@ -131,6 +130,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/google-stackdriver-profiler-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"os"
"regexp"

"cloud.google.com/go/storage"
Expand Down Expand Up @@ -58,6 +57,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/graalvm-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"io/ioutil"
"net/http"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -132,7 +131,7 @@ func main() {
outputs["purl"] = matches[1]
}

outputs.Write(os.Stdout)
outputs.Write()
}

func GetVersion(uri string) string {
Expand Down
3 changes: 1 addition & 2 deletions actions/gradle-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"

"github.com/paketo-buildpacks/pipeline-builder/actions"
)
Expand Down Expand Up @@ -53,7 +52,7 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}

Expand Down
3 changes: 1 addition & 2 deletions actions/ibm-semeru-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -132,7 +131,7 @@ func main() {
}
outputs["cpe"] = matches[1]

outputs.Write(os.Stdout)
outputs.Write()
}

func getReleaseJSON(jsonURI string) ReleaseJSON {
Expand Down
3 changes: 1 addition & 2 deletions actions/jprofiler-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"fmt"
"os"
"regexp"

"github.com/gocolly/colly"
Expand Down Expand Up @@ -49,6 +48,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
3 changes: 1 addition & 2 deletions actions/jrebel-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"fmt"
"os"
"regexp"

"github.com/gocolly/colly"
Expand Down Expand Up @@ -49,6 +48,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
Loading