From 0a597c23f438be1259bda9ae7778c76c8a6fb972 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 14 Apr 2025 18:25:24 +0000 Subject: [PATCH] test: try logging refs --- .github/workflows/ci.yaml | 4 ++-- cmd/github/github.go | 38 +++++++++++++++++++++++++++++++++++++ cmd/github/githubactions.go | 21 -------------------- 3 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 cmd/github/github.go delete mode 100644 cmd/github/githubactions.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 710f6a31..0d3f9eab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest env: actor: ${{ github.actor }} + base_ref: ${{ github.base_ref }} + head_ref: ${{ github.head_ref }} steps: - name: Check out code uses: actions/checkout@v4 - - name: Feeling cute. Might (aka should) delete later - run: git branch --show-current - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/cmd/github/github.go b/cmd/github/github.go new file mode 100644 index 00000000..7ebb01df --- /dev/null +++ b/cmd/github/github.go @@ -0,0 +1,38 @@ +// Package github provides utilities to make it easier to deal with various +// GitHub APIs +package github + +import ( + "errors" + "fmt" + "os" +) + +const ( + actionsActorKey = "actor" + actionsBaseRefKey = "base_ref" + actionsHeadRefKey = "head_ref" +) + +// ActionsActor returns the username of the GitHub user who triggered the +// current CI run as part of GitHub Actions. The value must be loaded into the +// env as part of the Github Actions YAML file, or else the function fails. +func ActionsActor() (string, error) { + username := os.Getenv(actionsActorKey) + if username == "" { + return "", fmt.Errorf("value for %q is not in env. Please update the CI script to load the value in during CI", actionsActorKey) + } + return username, nil +} + +// ActionsRefs returns the name of the head ref and the base ref for current CI +// run, in that order. Both values must be loaded into the env as part of the +// GitHub Actions YAML file, or else the function fails. +func ActionsRefs() (string, string, error) { + baseRef := os.Getenv(actionsBaseRefKey) + headRef := os.Getenv(actionsHeadRefKey) + fmt.Println("Base ref: ", baseRef) + fmt.Println("Head ref: ", headRef) + + return "", "", errors.New("we ain't ready yet") +} diff --git a/cmd/github/githubactions.go b/cmd/github/githubactions.go deleted file mode 100644 index 5d97ab40..00000000 --- a/cmd/github/githubactions.go +++ /dev/null @@ -1,21 +0,0 @@ -// Package github provides utilities to make it easier to deal with various -// GitHub APIs -package github - -import ( - "fmt" - "os" -) - -const envActorUsernameKey = "actor" - -// ActionsActor returns the username of the GitHub user who triggered the -// current CI run as part of GitHub Actions.The value must be loaded into the -// env as part of the Github Actions script file, or else the function fails. -func ActionsActor() (string, error) { - username := os.Getenv(envActorUsernameKey) - if username == "" { - return "", fmt.Errorf("value for %q is not in env. Please update the CI script to load the value in during CI", envActorUsernameKey) - } - return username, nil -}