Skip to content

Commit 860a633

Browse files
committed
wip: add support for reading env from CI
1 parent a2abeae commit 860a633

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ concurrency:
99
jobs:
1010
validate-contributors:
1111
runs-on: ubuntu-latest
12+
env:
13+
actor: ${{ github.actor }}
1214
steps:
1315
- name: Check out code
1416
uses: actions/checkout@v4

cmd/github/githubactions.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Package github provides utilities to make it easier to deal with various
2+
// GitHub APIs
3+
package github
4+
5+
import (
6+
"fmt"
7+
"os"
8+
)
9+
10+
const envActorUsernameKey = "actor"
11+
12+
// ActionsActor returns the username of the GitHub user who triggered the
13+
// current CI run as part of GitHub Actions.The value must be loaded into the
14+
// env as part of the Github Actions script file, or else the function fails.
15+
func ActionsActor() (string, error) {
16+
username := os.Getenv(envActorUsernameKey)
17+
if username == "" {
18+
return "", fmt.Errorf("value for %q is not in env. Please update the CI script to load the value in during CI", envActorUsernameKey)
19+
}
20+
return username, nil
21+
}

cmd/readmevalidation/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ package main
88

99
import (
1010
"log"
11+
12+
"coder.com/coder-registry/cmd/github"
1113
)
1214

1315
func main() {
16+
username, err := github.ActionsActor()
17+
if err != nil {
18+
log.Panic(err)
19+
}
20+
log.Println("running as %q", username)
21+
1422
log.Println("Starting README validation")
1523
allReadmeFiles, err := aggregateContributorReadmeFiles()
1624
if err != nil {

0 commit comments

Comments
 (0)