test: try logging refs

This commit is contained in:
Michael Smith 2025-04-14 18:25:24 +00:00
parent ec1b4a72cb
commit 0a597c23f4
3 changed files with 40 additions and 23 deletions

View File

@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
actor: ${{ github.actor }} actor: ${{ github.actor }}
base_ref: ${{ github.base_ref }}
head_ref: ${{ github.head_ref }}
steps: steps:
- name: Check out code - name: Check out code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Feeling cute. Might (aka should) delete later
run: git branch --show-current
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:

38
cmd/github/github.go Normal file
View File

@ -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")
}

View File

@ -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
}