Skip to content

Commit

Permalink
Replace deprecated GHA ::set-output syntax
Browse files Browse the repository at this point in the history
Fixes #867
  • Loading branch information
phil9909 committed Jan 24, 2023
1 parent 55ebdb5 commit d91eefc
Show file tree
Hide file tree
Showing 48 changed files with 95 additions and 101 deletions.
28 changes: 25 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,27 @@ func NewOutputs(uri string, latestVersion *semver.Version, additionalOutputs Out
return outputs, nil
}

func (o Outputs) Write(writer io.Writer) {
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 := os.OpenFile(outputFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
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
}
}

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()
}
}
3 changes: 1 addition & 2 deletions actions/leiningen-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"

"github.com/google/go-github/v43/github"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -59,6 +58,6 @@ func main() {
if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write(os.Stdout)
o.Write()
}
}
Loading

0 comments on commit d91eefc

Please sign in to comment.