mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Unsets Persisted Credentials (#587)
* Persist * Config Setup/Tests * Assets * Update git.ts * Spacing * Update integration.yml
This commit is contained in:
parent
2963e5ecf1
commit
7fe0750a45
14
.github/ISSUE_TEMPLATE/BUG_REPORT.md
vendored
14
.github/ISSUE_TEMPLATE/BUG_REPORT.md
vendored
@ -8,14 +8,20 @@ labels:
|
||||
|
||||
<!-- Please check the Q&A before posting an issue: https://github.com/JamesIves/github-pages-deploy-action/discussions?discussions_q=category%3AQ%26A -->
|
||||
|
||||
**Describe the bug**
|
||||
### Describe the bug
|
||||
<!-- Please provide a clear and concise description of what the bug is. -->
|
||||
|
||||
**Reproduce**
|
||||
---
|
||||
|
||||
### Reproduction Steps
|
||||
<!-- Steps to reproduce the behavior. -->
|
||||
|
||||
**Logs**
|
||||
---
|
||||
|
||||
### Logs
|
||||
<!-- Please provide your deployment logs and a link or sample to/of your workflow. If the error message isn't revealing the problem please set ACTIONS_STEP_DEBUG to true in your repository's secrets menu and run the workflow again. -->
|
||||
|
||||
**Additional Comments**
|
||||
---
|
||||
|
||||
### Additional Comments
|
||||
<!--Add any other context about the problem here. -->
|
||||
|
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,8 +1,12 @@
|
||||
**Description**
|
||||
> Provide a description of what your changes do.
|
||||
### Description
|
||||
<!-- Provide a description of what your changes do. -->
|
||||
|
||||
**Testing Instructions**
|
||||
> Give us step by step instructions on how to test your changes.
|
||||
---
|
||||
|
||||
**Additional Notes**
|
||||
> Anything else that will help us test the pull request.
|
||||
### Testing Instructions
|
||||
<!-- Give us step by step instructions on how to test your changes. -->
|
||||
|
||||
---
|
||||
|
||||
### Additional Notes
|
||||
<!-- Anything else that will help us test the pull request. -->
|
BIN
.github/logo.png
vendored
BIN
.github/logo.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 63 KiB |
BIN
.github/screenshot.png
vendored
BIN
.github/screenshot.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 10 KiB |
17
.github/workflows/integration.yml
vendored
17
.github/workflows/integration.yml
vendored
@ -112,6 +112,23 @@ jobs:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branches: gh-pages
|
||||
|
||||
# Deploys cross repo with an access token.
|
||||
integration-cross-repo-push:
|
||||
needs: integration-container
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v4
|
||||
with:
|
||||
repository-name: MontezumaIves/lab
|
||||
token: ${{ secrets.CROSS_REPO_PUSH_TOKEN }}
|
||||
branch: gh-pages
|
||||
folder: integration
|
||||
single-commit: true
|
||||
|
||||
# Deploys using an SSH key.
|
||||
integration-ssh-third-party-client:
|
||||
needs: integration-container
|
||||
|
@ -1,6 +1,6 @@
|
||||
<p align="center">
|
||||
<a href="https://github.com/marketplace/actions/deploy-to-github-pages">
|
||||
<img alt="" width="300px" src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/.github/logo.png">
|
||||
<img alt="" width="300px" src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/assets/icon.png">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/.github/screenshot.png">
|
||||
<img src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/assets/screenshot.png">
|
||||
</p>
|
||||
|
||||
## Getting Started :airplane:
|
||||
|
@ -55,7 +55,7 @@ describe('git', () => {
|
||||
})
|
||||
|
||||
await init(action)
|
||||
expect(execute).toBeCalledTimes(4)
|
||||
expect(execute).toBeCalledTimes(5)
|
||||
})
|
||||
|
||||
it('should catch when a function throws an error', async () => {
|
||||
@ -85,6 +85,47 @@ describe('git', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('should correctly continue when it cannot unset a git config value', async () => {
|
||||
Object.assign(action, {
|
||||
silent: false,
|
||||
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
||||
token: '123',
|
||||
branch: 'branch',
|
||||
folder: '.',
|
||||
pusher: {
|
||||
name: 'asd',
|
||||
email: 'as@cat'
|
||||
},
|
||||
isTest: TestFlag.UNABLE_TO_UNSET_GIT_CONFIG
|
||||
})
|
||||
|
||||
await init(action)
|
||||
expect(execute).toBeCalledTimes(5)
|
||||
})
|
||||
|
||||
it('should not unset git config if a user is using ssh', async () => {
|
||||
// Sets and unsets the CI condition.
|
||||
process.env.CI = 'true'
|
||||
|
||||
Object.assign(action, {
|
||||
silent: false,
|
||||
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
||||
sshKey: true,
|
||||
branch: 'branch',
|
||||
folder: '.',
|
||||
pusher: {
|
||||
name: 'asd',
|
||||
email: 'as@cat'
|
||||
},
|
||||
isTest: false
|
||||
})
|
||||
|
||||
await init(action)
|
||||
expect(execute).toBeCalledTimes(4)
|
||||
|
||||
process.env.CI = undefined
|
||||
})
|
||||
|
||||
it('should correctly continue when it cannot remove origin', async () => {
|
||||
Object.assign(action, {
|
||||
silent: false,
|
||||
@ -100,7 +141,7 @@ describe('git', () => {
|
||||
})
|
||||
|
||||
await init(action)
|
||||
expect(execute).toBeCalledTimes(4)
|
||||
expect(execute).toBeCalledTimes(5)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -49,7 +49,7 @@ describe('main', () => {
|
||||
debug: true
|
||||
})
|
||||
await run(action)
|
||||
expect(execute).toBeCalledTimes(12)
|
||||
expect(execute).toBeCalledTimes(13)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(exportVariable).toBeCalledTimes(1)
|
||||
})
|
||||
@ -68,7 +68,7 @@ describe('main', () => {
|
||||
isTest: TestFlag.HAS_CHANGED_FILES
|
||||
})
|
||||
await run(action)
|
||||
expect(execute).toBeCalledTimes(15)
|
||||
expect(execute).toBeCalledTimes(16)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(exportVariable).toBeCalledTimes(1)
|
||||
})
|
||||
|
BIN
assets/icon.png
BIN
assets/icon.png
Binary file not shown.
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 63 KiB |
Binary file not shown.
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 10 KiB |
@ -7,9 +7,10 @@ const {pusher, repository} = github.context.payload
|
||||
/* Flags to signal different scenarios to test cases */
|
||||
export enum TestFlag {
|
||||
NONE = 0,
|
||||
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit
|
||||
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits
|
||||
UNABLE_TO_REMOVE_ORIGIN = 1 << 3 // Assume we can't remove origin
|
||||
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit.
|
||||
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits.
|
||||
UNABLE_TO_REMOVE_ORIGIN = 1 << 3, // Assume we can't remove origin.
|
||||
UNABLE_TO_UNSET_GIT_CONFIG = 1 << 4 // Assume we can't remove previously set git configs.
|
||||
}
|
||||
|
||||
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
|
||||
|
22
src/git.ts
22
src/git.ts
@ -23,6 +23,27 @@ export async function init(action: ActionInterface): Promise<void | Error> {
|
||||
action.silent
|
||||
)
|
||||
|
||||
try {
|
||||
if ((process.env.CI && !action.sshKey) || action.isTest) {
|
||||
/* Ensures that previously set Git configs do not interfere with the deployment.
|
||||
Only runs in the GitHub Actions CI environment if a user is not using an SSH key.
|
||||
*/
|
||||
await execute(
|
||||
`git config --local --unset-all http.https://github.com/.extraheader`,
|
||||
action.workspace,
|
||||
action.silent
|
||||
)
|
||||
}
|
||||
|
||||
if (action.isTest === TestFlag.UNABLE_TO_UNSET_GIT_CONFIG) {
|
||||
throw new Error()
|
||||
}
|
||||
} catch {
|
||||
info(
|
||||
'Unable to unset previous git config authentication as it may not exist, continuing…'
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
await execute(`git remote rm origin`, action.workspace, action.silent)
|
||||
|
||||
@ -38,7 +59,6 @@ export async function init(action: ActionInterface): Promise<void | Error> {
|
||||
action.workspace,
|
||||
action.silent
|
||||
)
|
||||
|
||||
info('Git configured… 🔧')
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
|
Loading…
Reference in New Issue
Block a user