Skip to content

Commit

Permalink
fix: define --repo option
Browse files Browse the repository at this point in the history
  • Loading branch information
d-koppenhagen committed Dec 29, 2023
1 parent 171cbc5 commit 96709e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
16 changes: 9 additions & 7 deletions __tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let execMock: jest.SpyInstance

const deployDir = '__tests__'

process.env.GITHUB_REPOSITORY = 'https://github.com/my-org/my-repo'

describe('deploy.ts', () => {
beforeEach(() => {
jest.clearAllMocks()
Expand All @@ -21,29 +23,29 @@ describe('deploy.ts', () => {
})

it('deploys the passed directory', async () => {
await deploy(deployDir)
await deploy('1234', deployDir)
expect(execMock).toHaveBeenCalledWith(
`npx angular-cli-ghpages --dir="${deployDir}"`
`npx angular-cli-ghpages --repo="https://1234@github.com/https:/.git" --dir="${deployDir}"`
)
})

it('deploys with deploy args', async () => {
await deploy(deployDir, '--no-silent')
await deploy('1234', deployDir, '--no-silent')
expect(execMock).toHaveBeenCalledWith(
`npx angular-cli-ghpages --dir="${deployDir}" --no-silent`
`npx angular-cli-ghpages --repo="https://1234@github.com/https:/.git" --dir="${deployDir}" --no-silent`
)
})

it('deploys with cname arg from file', async () => {
writeFile('CNAME', 'example.org')
await deploy(deployDir)
await deploy('1234', deployDir)
expect(execMock).toHaveBeenCalledWith(
`npx angular-cli-ghpages --dir="${deployDir}" --cname=example.org`
`npx angular-cli-ghpages --repo="https://1234@github.com/https:/.git" --dir="${deployDir}" --cname=example.org`
)
})

it('creates a .nojekyll file in the target directory', async () => {
await deploy(deployDir)
await deploy('1234', deployDir)
const noJekyllFile = await ioUtil.exists(`${deployDir}/.nojekyll`)
expect(noJekyllFile).toBe(true)
})
Expand Down
14 changes: 11 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as core from '@actions/core'
import * as github from '@actions/github'

export async function deploy(
accessToken: string,
targetDir: string,
deployArguments = ''
): Promise<void> {
Expand All @@ -31,14 +32,17 @@ export async function deploy(
writeFile(noJekyllPath, '')
}

const repo = `${github.context.repo.owner}/${github.context.repo.repo}`
const repoURL = `https://${accessToken}@github.com/${repo}.git`

await exec.exec(`git config user.name`, [github.context.actor])
await exec.exec(`git config user.email`, [
`${github.context.actor}@users.noreply.github.com`
])

core.info(`Deploy static site using angular-cli-ghpages`)
await exec.exec(
`npx angular-cli-ghpages --dir="${targetDir}"${cnameArg}${deployArgs}`
`npx angular-cli-ghpages --repo="${repoURL}" --dir="${targetDir}"${cnameArg}${deployArgs}`
)
core.info('Successfully deployed your site.')
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function run(): Promise<void> {
core.endGroup()

core.startGroup('Deploy')
await deploy(deployDir, deployArgs)
await deploy(accessToken, deployDir, deployArgs)
core.endGroup()

core.info('Enjoy! ✨')
Expand Down

0 comments on commit 96709e9

Please sign in to comment.