8000 Unsets Persisted Credentials (#587) · lyrl/github-pages-deploy-action@7fe0750 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fe0750

Browse files
authored
Unsets Persisted Credentials (JamesIves#587)
* Persist * Config Setup/Tests * Assets * Update git.ts * Spacing * Update integration.yml
1 parent 2963e5e commit 7fe0750

File tree

12 files changed

+109
-20
lines changed

12 files changed

+109
-20
lines changed

.github/ISSUE_TEMPLATE/BUG_REPORT.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ labels:
88

99
<!-- Please check the Q&A before posting an issue: https://github.com/JamesIves/github-pages-deploy-action/discussions?discussions_q=category%3AQ%26A -->
1010

11-
**Describe the bug**
11+
### Describe the bug
1212
<!-- Please provide a clear and concise description of what the bug is. -->
1313

14-
**Reproduce**
14+
---
15+
16+
### Reproduction Steps
1517
<!-- Steps to reproduce the behavior. -->
1618

17-
**Logs**
19+
---
20+
21+
### Logs
1822
<!-- 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. -->
1923

20-
**Additional Comments**
24+
---
25+
26+
### Additional Comments
2127
<!--Add any other context about the problem here. -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
**Description**
2-
> Provide a description of what your changes do.
1+
### Description
2+
<!-- Provide a description of what your changes do. -->
33

4-
**Testing Instructions**
5-
> Give us step by step instructions on how to test your changes.
4+
---
65

7-
**Additional Notes**
8-
> Anything else that will help us test the pull request.
6+
### Testing Instructions
7+
<!-- Give us step by step instructions on how to test your changes. -->
8+
9+
---
10+
11+
### Additional Notes
12+
<!-- Anything else that will help us test the pull request. -->

.github/logo.png

-62.7 KB
Binary file not shown.

.github/screenshot.png

-10.5 KB
Binary file not shown.

.github/workflows/integration.yml

Lines changed: 17 additions & 0 deletions
A3E2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ jobs:
112112
github_token: ${{ secrets.GITHUB_TOKEN }}
113113
branches: gh-pages
114114

115+
# Deploys cross repo with an access token.
116+
integration-cross-repo-push:
117+
needs: integration-container
118+
runs-on: ubuntu-latest
119+
steps:
120+
- name: Checkout
121+
uses: actions/checkout@v2
122+
123+
- name: Build and Deploy
124+
uses: JamesIves/github-pages-deploy-action@releases/v4
125+
with:
126+
repository-name: MontezumaIves/lab
127+
token: ${{ secrets.CROSS_REPO_PUSH_TOKEN }}
128+
branch: gh-pages
129+
folder: integration
130+
single-commit: true
131+
115132
# Deploys using an SSH key.
116133
integration-ssh-third-party-client:
117134
needs: integration-container

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<p align="center">
22
<a href="https://github.com/marketplace/actions/deploy-to-github-pages">
3-
<img alt="" width="300px" src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/.github/logo.png">
3+
<img alt="" width="300px" src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/assets/icon.png">
44
</a>
55
</p>
66

@@ -35,7 +35,7 @@
3535
</p>
3636

3737
<p align="center">
38-
<img src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/.github/screenshot.png">
38+
<img src="https://github.com/JamesIves/github-pages-deploy-action/raw/dev-v4/assets/screenshot.png">
3939
</p>
4040

4141
## Getting Started :airplane:

__tests__/git.test.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('git', () => {
5555
})
5656

5757
await init(action)
58-
expect(execute).toBeCalledTimes(4)
58+
expect(execute).toBeCalledTimes(5)
5959
})
6060

6161
it('should catch when a function throws an error', async () => {
@@ -85,6 +85,47 @@ describe('git', () => {
8585
}
8686
})
8787

88+
it('should correctly continue when it cannot unset a git config value', async () => {
89+
Object.assign(action, {
90+
silent: false,
91+
repositoryPath: 'JamesIves/github-pages-deploy-action',
92+
token: '123',
93+
branch: 'branch',
94+
folder: '.',
95+
pusher: {
96+
name: 'asd',
97+
email: 'as@cat'
98+
},
99+
isTest: TestFlag.UNABLE_TO_UNSET_GIT_CONFIG
100+
})
101+
102+
await init(action)
103+
expect(execute).toBeCalledTimes(5)
104+
})
105+
106+
it('should not unset git config if a user is using ssh', async () => {
107+
// Sets and unsets the CI condition.
108+
process.env.CI = 'true'
109+
110+
Object.assign(action, {
111+
silent: false,
112+
repositoryPath: 'JamesIves/github-pages-deploy-action',
113+
sshKey: true,
114+
branch: 'branch',
115+
folder: '.',
116+
pusher: {
117+
name: 'asd',
118+
email: 'as@cat'
119+
},
120+
isTest: false
121+
})
122+
123+
await init(action)
124+
expect(execute).toBeCalledTimes(4)
125+
126+
process.env.CI = undefined
127+
})
128+
88129
it('should correctly continue when it cannot remove origin', async () => {
89130
Object.assign(action, {
90131
silent: false,
@@ -100,7 +141,7 @@ describe('git', () => {
100141
})
101142

102143
await init(action)
103-
expect(execute).toBeCalledTimes(4)
144+
expect(execute).toBeCalledTimes(5)
104145
})
105146
})
106147

__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('main', () => {
4949
debug: true
5050
})
5151
await run(action)
52-
expect(execute).toBeCalledTimes(12)
52+
expect(execute).toBeCalledTimes(13)
5353
expect(rmRF).toBeCalledTimes(1)
5454
expect(exportVariable).toBeCalledTimes(1)
5555
})
@@ -68,7 +68,7 @@ describe('main', () => {
6868
isTest: TestFlag.HAS_CHANGED_FILES
6969
})
7070
await run(action)
71-
expect(execute).toBeCalledTimes(15)
71+
expect(execute).toBeCalledTimes(16)
7272
expect(rmRF).toBeCalledTimes(1)
7373
expect(exportVariable).toBeCalledTimes(1)
7474
})

assets/icon.png

-43.9 KB
Loading

assets/screenshot.png

-34.3 KB
Loading

src/constants.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ const {pusher, repository} = github.context.payload
77
/* Flags to signal different scenarios to test cases */
88
export enum TestFlag {
99
NONE = 0,
10-
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit
11-
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits
12-
UNABLE_TO_REMOVE_ORIGIN = 1 << 3 // Assume we can't remove origin
10+
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit.
11+
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits.
12+
UNABLE_TO_REMOVE_ORIGIN = 1 << 3, // Assume we can't remove origin.
13+
UNABLE_TO_UNSET_GIT_CONFIG = 1 << 4 // Assume we can't remove previously set git configs.
1314
}
1415

1516
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */

src/git.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ export async function init(action: ActionInterface): Promise<void | Error> {
2323
action.silent
2424
)
2525

26+
try {
27+
if ((process.env.CI && !action.sshKey) || action.isTest) {
28+
/* Ensures that previously set Git configs do not interfere with the deployment.
29+
Only runs in the GitHub Actions CI environment if a user is not using an SSH key.
30+
*/
31+
await execute(
32+
`git config --local --unset-all http.https://github.com/.extraheader`,
33+
action.workspace,
34+
action.silent
35+
)
36+
}
37+
38+
if (action.isTest === TestFlag.UNABLE_TO_UNSET_GIT_CONFIG) {
39+
throw new Error()
40+
}
41+
} catch {
42+
info(
43+
'Unable to unset previous git config authentication as it may not exist, continuing…'
44+
)
45+
}
46+
2647
try {
2748
await execute(`git remote rm origin`, action.workspace, action.silent)
2849

@@ -38,7 +59,6 @@ export async function init(action: ActionInterface): Promise<void | Error> {
3859
action.workspace,
3960
action.silent
4061
)
41-
4262
info('Git configured… 🔧')
4363
} catch (error) {
4464
throw new Error(

0 commit comments

Comments
 (0)
0