diff --git a/packages/github/__tests__/lib.test.ts b/packages/github/__tests__/lib.test.ts index e77e79c627..12b283d23f 100644 --- a/packages/github/__tests__/lib.test.ts +++ b/packages/github/__tests__/lib.test.ts @@ -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) + }) + }) }) diff --git a/packages/github/src/context.ts b/packages/github/src/context.ts index 60554fd322..0840b13254 100644 --- a/packages/github/src/context.ts +++ b/packages/github/src/context.ts @@ -12,6 +12,8 @@ export class Context { eventName: string sha: string ref: string + refName: string + refType: string workflow: string action: string actor: string @@ -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 this.workflow = process.env.GITHUB_WORKFLOW as string this.action = process.env.GITHUB_ACTION as string this.actor = process.env.GITHUB_ACTOR as string