Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/github/__tests__/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,32 @@ describe('@actions/context', () => {
repo: 'test'
})
})

describe('refs', () => {
it.each([
'refs/heads/main',
'refs/heads/feature-branch',
'refs/pull/42/merge',
'refs/tags/v2.0.4'
])(`should set context.ref: %s`, ref => {
process.env.GITHUB_REF = ref

expect(new Context()).toHaveProperty(`ref`, ref)
})

it.each([`meh-${Date.now()}`, 'catpants', 'v1.2.3'])(
'should set context.refName: %s',
refName => {
process.env.GITHUB_REF_NAME = refName

expect(new Context()).toHaveProperty('refName', refName)
}
)

it.each(['branch', 'tag'])('should set context.refType: %s', refType => {
process.env.GITHUB_REF_TYPE = refType

expect(new Context()).toHaveProperty('refType', refType)
})
})
})
4 changes: 4 additions & 0 deletions packages/github/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class Context {
eventName: string
sha: string
ref: string
refName: string
refType: string
workflow: string
action: string
actor: string
Expand Down Expand Up @@ -41,6 +43,8 @@ export class Context {
this.eventName = process.env.GITHUB_EVENT_NAME as string
this.sha = process.env.GITHUB_SHA as string
this.ref = process.env.GITHUB_REF as string
this.refName = process.env.GITHUB_REF_NAME as string
this.refType = process.env.GITHUB_REF_TYPE as string
Comment on lines 43 to +47
this.workflow = process.env.GITHUB_WORKFLOW as string
this.action = process.env.GITHUB_ACTION as string
this.actor = process.env.GITHUB_ACTOR as string
Expand Down