diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index af4ae03e..0fd99f53 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,6 +9,8 @@ concurrency: jobs: validate-contributors: runs-on: ubuntu-latest + env: + actor: ${{ github.actor }} steps: - name: Check out code uses: actions/checkout@v4 diff --git a/cmd/github/githubactions.go b/cmd/github/githubactions.go new file mode 100644 index 00000000..5d97ab40 --- /dev/null +++ b/cmd/github/githubactions.go @@ -0,0 +1,21 @@ +// 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 +} diff --git a/cmd/readmevalidation/main.go b/cmd/readmevalidation/main.go index 789797ef..c9fe4e9e 100644 --- a/cmd/readmevalidation/main.go +++ b/cmd/readmevalidation/main.go @@ -8,9 +8,17 @@ package main import ( "log" + + "coder.com/coder-registry/cmd/github" ) func main() { + username, err := github.ActionsActor() + if err != nil { + log.Panic(err) + } + log.Println("running as %q", username) + log.Println("Starting README validation") allReadmeFiles, err := aggregateContributorReadmeFiles() if err != nil {