Skip to content

Commit

Permalink
Potential fix for env problem in Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenvandermeulen committed Aug 14, 2023
1 parent 550f94c commit 1e17e00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import {getRepoNames} from '../src/main'

describe('getRepoNames', () => {
let originalEnv: NodeJS.ProcessEnv

beforeAll(() => {
originalEnv = process.env
})

afterEach(() => {
process.env = originalEnv // Restore original process.env after each test
})
it('should fetch repository names for the given organization', async () => {
process.env = {
CI: 'true',
GH_ORG: 'myorg',
GH_API_KEY: 'apikey',
AWS_BUCKET_NAME: 'bucket',
Expand All @@ -20,6 +30,7 @@ describe('getRepoNames', () => {

it('should handle errors when fetching repository names', async () => {
process.env = {
CI: 'true',
GH_ORG: 'myorg',
GH_API_KEY: 'apikey',
AWS_BUCKET_NAME: 'bucket',
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
import {getInput} from '@actions/core'

// All the GitHub variables
const githubOrganization: string = process.env.GITHUB_ACTIONS
? getInput('github-organization', {required: true})
: (process.env.GH_ORG as string)
const githubOrganization: string =
process.env.GITHUB_ACTIONS && !process.env.CI
? getInput('github-organization', {required: true})
: (process.env.GH_ORG as string)
const octokit = new Octokit({
auth: process.env.GITHUB_ACTIONS
? getInput('github-api-key')
Expand Down

0 comments on commit 1e17e00

Please sign in to comment.