mirror of
https://github.com/actions/checkout.git
synced 2025-03-14 10:07:00 +00:00
Merge branch 'main' of ssh://github.com/actions/checkout into main
This commit is contained in:
commit
ebec667cd8
33 changed files with 757 additions and 392 deletions
6
.github/workflows/check-dist.yml
vendored
6
.github/workflows/check-dist.yml
vendored
|
@ -22,12 +22,12 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Set Node.js 16.x
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 16.x
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
|
@ -39,7 +39,7 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v1
|
||||||
|
|
2
.github/workflows/licensed.yml
vendored
2
.github/workflows/licensed.yml
vendored
|
@ -9,6 +9,6 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Check licenses
|
name: Check licenses
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run licensed-check
|
- run: npm run licensed-check
|
48
.github/workflows/test.yml
vendored
48
.github/workflows/test.yml
vendored
|
@ -13,8 +13,8 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 16.x
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm run format-check
|
- run: npm run format-check
|
||||||
|
@ -32,7 +32,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
# Clone this repo
|
# Clone this repo
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Basic checkout
|
# Basic checkout
|
||||||
- name: Checkout basic
|
- name: Checkout basic
|
||||||
|
@ -164,7 +164,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
# Clone this repo
|
# Clone this repo
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Basic checkout using git
|
# Basic checkout using git
|
||||||
- name: Checkout basic
|
- name: Checkout basic
|
||||||
|
@ -196,7 +196,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
# Clone this repo
|
# Clone this repo
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Basic checkout using git
|
# Basic checkout using git
|
||||||
- name: Checkout basic
|
- name: Checkout basic
|
||||||
|
@ -219,3 +219,41 @@ jobs:
|
||||||
path: basic
|
path: basic
|
||||||
- name: Verify basic
|
- name: Verify basic
|
||||||
run: __test__/verify-basic.sh --archive
|
run: __test__/verify-basic.sh --archive
|
||||||
|
|
||||||
|
test-git-container:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: bitnami/git:latest
|
||||||
|
steps:
|
||||||
|
# Clone this repo
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
path: v3
|
||||||
|
|
||||||
|
# Basic checkout using git
|
||||||
|
- name: Checkout basic
|
||||||
|
uses: ./v3
|
||||||
|
with:
|
||||||
|
ref: test-data/v2/basic
|
||||||
|
- name: Verify basic
|
||||||
|
run: |
|
||||||
|
if [ ! -f "./basic-file.txt" ]; then
|
||||||
|
echo "Expected basic file does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify .git folder
|
||||||
|
if [ ! -d "./.git" ]; then
|
||||||
|
echo "Expected ./.git folder to exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify auth token
|
||||||
|
git config --global --add safe.directory "*"
|
||||||
|
git fetch --no-tags --depth=1 origin +refs/heads/main:refs/remotes/origin/main
|
||||||
|
|
||||||
|
# needed to make checkout post cleanup succeed
|
||||||
|
- name: Fix Checkout v3
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
path: v3
|
30
.github/workflows/update-main-version.yml
vendored
Normal file
30
.github/workflows/update-main-version.yml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
name: Update Main Version
|
||||||
|
run-name: Move ${{ github.event.inputs.main_version }} to ${{ github.event.inputs.target }}
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
target:
|
||||||
|
description: The tag or reference to use
|
||||||
|
required: true
|
||||||
|
main_version:
|
||||||
|
type: choice
|
||||||
|
description: The main version to update
|
||||||
|
options:
|
||||||
|
- v3
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Git config
|
||||||
|
run: |
|
||||||
|
git config user.name github-actions
|
||||||
|
git config user.email github-actions@github.com
|
||||||
|
- name: Tag new target
|
||||||
|
run: git tag -f ${{ github.event.inputs.main_version }} ${{ github.event.inputs.target }}
|
||||||
|
- name: Push new tag
|
||||||
|
run: git push origin ${{ github.event.inputs.main_version }} --force
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
__test__/_temp
|
__test__/_temp
|
||||||
_temp/
|
_temp/
|
||||||
lib/
|
lib/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.vscode/
|
6
.licenses/npm/@actions/core.dep.yml
generated
6
.licenses/npm/@actions/core.dep.yml
generated
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
name: "@actions/core"
|
name: "@actions/core"
|
||||||
version: 1.2.6
|
version: 1.10.0
|
||||||
type: npm
|
type: npm
|
||||||
summary:
|
summary: Actions core lib
|
||||||
homepage:
|
homepage: https://github.com/actions/toolkit/tree/main/packages/core
|
||||||
license: mit
|
license: mit
|
||||||
licenses:
|
licenses:
|
||||||
- sources: LICENSE.md
|
- sources: LICENSE.md
|
||||||
|
|
32
.licenses/npm/@actions/http-client-2.0.1.dep.yml
generated
Normal file
32
.licenses/npm/@actions/http-client-2.0.1.dep.yml
generated
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
---
|
||||||
|
name: "@actions/http-client"
|
||||||
|
version: 2.0.1
|
||||||
|
type: npm
|
||||||
|
summary: Actions Http Client
|
||||||
|
homepage: https://github.com/actions/toolkit/tree/main/packages/http-client
|
||||||
|
license: mit
|
||||||
|
licenses:
|
||||||
|
- sources: LICENSE
|
||||||
|
text: |
|
||||||
|
Actions Http Client for Node.js
|
||||||
|
|
||||||
|
Copyright (c) GitHub, Inc.
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||||
|
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||||
|
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||||
|
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
|
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
notices: []
|
2
.licenses/npm/node-fetch.dep.yml
generated
2
.licenses/npm/node-fetch.dep.yml
generated
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: node-fetch
|
name: node-fetch
|
||||||
version: 2.6.5
|
version: 2.6.7
|
||||||
type: npm
|
type: npm
|
||||||
summary: A light-weight module that brings window.fetch to node.js
|
summary: A light-weight module that brings window.fetch to node.js
|
||||||
homepage: https://github.com/bitinn/node-fetch
|
homepage: https://github.com/bitinn/node-fetch
|
||||||
|
|
20
.licenses/npm/uuid-8.3.2.dep.yml
generated
Normal file
20
.licenses/npm/uuid-8.3.2.dep.yml
generated
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
name: uuid
|
||||||
|
version: 8.3.2
|
||||||
|
type: npm
|
||||||
|
summary: RFC4122 (v1, v4, and v5) UUIDs
|
||||||
|
homepage: https://github.com/uuidjs/uuid#readme
|
||||||
|
license: mit
|
||||||
|
licenses:
|
||||||
|
- sources: LICENSE.md
|
||||||
|
text: |
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
notices: []
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,10 +1,24 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v3.1.0
|
||||||
|
- [Use @actions/core `saveState` and `getState`](https://github.com/actions/checkout/pull/939)
|
||||||
|
- [Add `github-server-url` input](https://github.com/actions/checkout/pull/922)
|
||||||
|
|
||||||
|
## v3.0.2
|
||||||
|
- [Add input `set-safe-directory`](https://github.com/actions/checkout/pull/770)
|
||||||
|
|
||||||
|
## v3.0.1
|
||||||
|
- [Fixed an issue where checkout failed to run in container jobs due to the new git setting `safe.directory`](https://github.com/actions/checkout/pull/762)
|
||||||
|
- [Bumped various npm package versions](https://github.com/actions/checkout/pull/744)
|
||||||
|
|
||||||
|
## v3.0.0
|
||||||
|
|
||||||
|
- [Update to node 16](https://github.com/actions/checkout/pull/689)
|
||||||
|
|
||||||
## v2.3.1
|
## v2.3.1
|
||||||
|
|
||||||
- [Fix default branch resolution for .wiki and when using SSH](https://github.com/actions/checkout/pull/284)
|
- [Fix default branch resolution for .wiki and when using SSH](https://github.com/actions/checkout/pull/284)
|
||||||
|
|
||||||
|
|
||||||
## v2.3.0
|
## v2.3.0
|
||||||
|
|
||||||
- [Fallback to the default branch](https://github.com/actions/checkout/pull/278)
|
- [Fallback to the default branch](https://github.com/actions/checkout/pull/278)
|
||||||
|
|
56
README.md
56
README.md
|
@ -2,7 +2,7 @@
|
||||||
<a href="https://github.com/actions/checkout"><img alt="GitHub Actions status" src="https://github.com/actions/checkout/workflows/test-local/badge.svg"></a>
|
<a href="https://github.com/actions/checkout"><img alt="GitHub Actions status" src="https://github.com/actions/checkout/workflows/test-local/badge.svg"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Checkout V2
|
# Checkout V3
|
||||||
|
|
||||||
This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.
|
This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.
|
||||||
|
|
||||||
|
@ -14,27 +14,14 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
|
||||||
|
|
||||||
# What's new
|
# What's new
|
||||||
|
|
||||||
- Improved performance
|
- Updated to the node16 runtime by default
|
||||||
- Fetches only a single commit by default
|
- This requires a minimum [Actions Runner](https://github.com/actions/runner/releases/tag/v2.285.0) version of v2.285.0 to run, which is by default available in GHES 3.4 or later.
|
||||||
- Script authenticated git commands
|
|
||||||
- Auth token persisted in the local git config
|
|
||||||
- Supports SSH
|
|
||||||
- Creates a local branch
|
|
||||||
- No longer detached HEAD when checking out a branch
|
|
||||||
- Improved layout
|
|
||||||
- The input `path` is always relative to $GITHUB_WORKSPACE
|
|
||||||
- Aligns better with container actions, where $GITHUB_WORKSPACE gets mapped in
|
|
||||||
- Fallback to REST API download
|
|
||||||
- When Git 2.18 or higher is not in the PATH, the REST API will be used to download the files
|
|
||||||
- When using a job container, the container's PATH is used
|
|
||||||
|
|
||||||
Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous versions.
|
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
<!-- start usage -->
|
<!-- start usage -->
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
# Repository name with owner. For example, actions/checkout
|
# Repository name with owner. For example, actions/checkout
|
||||||
# Default: ${{ github.repository }}
|
# Default: ${{ github.repository }}
|
||||||
|
@ -113,6 +100,17 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
#
|
#
|
||||||
# Default: false
|
# Default: false
|
||||||
submodules: ''
|
submodules: ''
|
||||||
|
|
||||||
|
# Add repository path as safe.directory for Git global config by running `git
|
||||||
|
# config --global --add safe.directory <path>`
|
||||||
|
# Default: true
|
||||||
|
set-safe-directory: ''
|
||||||
|
|
||||||
|
# The base URL for the GitHub instance that you are trying to clone from, will use
|
||||||
|
# environment defaults to fetch from the same instance that the workflow is
|
||||||
|
# running from unless specified. Example URLs are https://github.com or
|
||||||
|
# https://my-ghes-server.example.com
|
||||||
|
github-server-url: ''
|
||||||
```
|
```
|
||||||
<!-- end usage -->
|
<!-- end usage -->
|
||||||
|
|
||||||
|
@ -131,7 +129,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
## Fetch all history for all tags and branches
|
## Fetch all history for all tags and branches
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
```
|
```
|
||||||
|
@ -139,7 +137,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
## Checkout a different branch
|
## Checkout a different branch
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: my-branch
|
ref: my-branch
|
||||||
```
|
```
|
||||||
|
@ -147,7 +145,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
## Checkout HEAD^
|
## Checkout HEAD^
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
- run: git checkout HEAD^
|
- run: git checkout HEAD^
|
||||||
|
@ -157,12 +155,12 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
path: main
|
path: main
|
||||||
|
|
||||||
- name: Checkout tools repo
|
- name: Checkout tools repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: my-org/my-tools
|
repository: my-org/my-tools
|
||||||
path: my-tools
|
path: my-tools
|
||||||
|
@ -172,10 +170,10 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Checkout tools repo
|
- name: Checkout tools repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: my-org/my-tools
|
repository: my-org/my-tools
|
||||||
path: my-tools
|
path: my-tools
|
||||||
|
@ -185,12 +183,12 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
path: main
|
path: main
|
||||||
|
|
||||||
- name: Checkout private tools
|
- name: Checkout private tools
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: my-org/my-private-tools
|
repository: my-org/my-private-tools
|
||||||
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT
|
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT
|
||||||
|
@ -203,7 +201,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
||||||
## Checkout pull request HEAD commit instead of merge commit
|
## Checkout pull request HEAD commit instead of merge commit
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
```
|
```
|
||||||
|
@ -219,7 +217,7 @@ jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
```
|
```
|
||||||
|
|
||||||
## Push a commit using the built-in token
|
## Push a commit using the built-in token
|
||||||
|
@ -230,7 +228,7 @@ jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- run: |
|
- run: |
|
||||||
date > generated.txt
|
date > generated.txt
|
||||||
git config user.name github-actions
|
git config user.name github-actions
|
||||||
|
|
|
@ -20,6 +20,7 @@ let tempHomedir: string
|
||||||
let git: IGitCommandManager & {env: {[key: string]: string}}
|
let git: IGitCommandManager & {env: {[key: string]: string}}
|
||||||
let settings: IGitSourceSettings
|
let settings: IGitSourceSettings
|
||||||
let sshPath: string
|
let sshPath: string
|
||||||
|
let githubServerUrl: string
|
||||||
|
|
||||||
describe('git-auth-helper tests', () => {
|
describe('git-auth-helper tests', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
@ -67,11 +68,18 @@ describe('git-auth-helper tests', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const configureAuth_configuresAuthHeader =
|
async function testAuthHeader(
|
||||||
'configureAuth configures auth header'
|
testName: string,
|
||||||
it(configureAuth_configuresAuthHeader, async () => {
|
serverUrl: string | undefined = undefined
|
||||||
|
) {
|
||||||
// Arrange
|
// Arrange
|
||||||
await setup(configureAuth_configuresAuthHeader)
|
let expectedServerUrl = 'https://github.com'
|
||||||
|
if (serverUrl) {
|
||||||
|
githubServerUrl = serverUrl
|
||||||
|
expectedServerUrl = githubServerUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
await setup(testName)
|
||||||
expect(settings.authToken).toBeTruthy() // sanity check
|
expect(settings.authToken).toBeTruthy() // sanity check
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
||||||
|
|
||||||
|
@ -88,9 +96,33 @@ describe('git-auth-helper tests', () => {
|
||||||
).toString('base64')
|
).toString('base64')
|
||||||
expect(
|
expect(
|
||||||
configContent.indexOf(
|
configContent.indexOf(
|
||||||
`http.https://github.com/.extraheader AUTHORIZATION: basic ${basicCredential}`
|
`http.${expectedServerUrl}/.extraheader AUTHORIZATION: basic ${basicCredential}`
|
||||||
)
|
)
|
||||||
).toBeGreaterThanOrEqual(0)
|
).toBeGreaterThanOrEqual(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
const configureAuth_configuresAuthHeader =
|
||||||
|
'configureAuth configures auth header'
|
||||||
|
it(configureAuth_configuresAuthHeader, async () => {
|
||||||
|
await testAuthHeader(configureAuth_configuresAuthHeader)
|
||||||
|
})
|
||||||
|
|
||||||
|
const configureAuth_AcceptsGitHubServerUrl =
|
||||||
|
'inject https://my-ghes-server.com as github server url'
|
||||||
|
it(configureAuth_AcceptsGitHubServerUrl, async () => {
|
||||||
|
await testAuthHeader(
|
||||||
|
configureAuth_AcceptsGitHubServerUrl,
|
||||||
|
'https://my-ghes-server.com'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const configureAuth_AcceptsGitHubServerUrlSetToGHEC =
|
||||||
|
'inject https://github.com as github server url'
|
||||||
|
it(configureAuth_AcceptsGitHubServerUrlSetToGHEC, async () => {
|
||||||
|
await testAuthHeader(
|
||||||
|
configureAuth_AcceptsGitHubServerUrl,
|
||||||
|
'https://github.com'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const configureAuth_configuresAuthHeaderEvenWhenPersistCredentialsFalse =
|
const configureAuth_configuresAuthHeaderEvenWhenPersistCredentialsFalse =
|
||||||
|
@ -643,10 +675,11 @@ describe('git-auth-helper tests', () => {
|
||||||
expect(gitConfigContent.indexOf('http.')).toBeLessThan(0)
|
expect(gitConfigContent.indexOf('http.')).toBeLessThan(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
const removeGlobalAuth_removesOverride = 'removeGlobalAuth removes override'
|
const removeGlobalConfig_removesOverride =
|
||||||
it(removeGlobalAuth_removesOverride, async () => {
|
'removeGlobalConfig removes override'
|
||||||
|
it(removeGlobalConfig_removesOverride, async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
await setup(removeGlobalAuth_removesOverride)
|
await setup(removeGlobalConfig_removesOverride)
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
||||||
await authHelper.configureAuth()
|
await authHelper.configureAuth()
|
||||||
await authHelper.configureGlobalAuth()
|
await authHelper.configureGlobalAuth()
|
||||||
|
@ -655,7 +688,7 @@ describe('git-auth-helper tests', () => {
|
||||||
await fs.promises.stat(path.join(git.env['HOME'], '.gitconfig'))
|
await fs.promises.stat(path.join(git.env['HOME'], '.gitconfig'))
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await authHelper.removeGlobalAuth()
|
await authHelper.removeGlobalConfig()
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(git.env['HOME']).toBeUndefined()
|
expect(git.env['HOME']).toBeUndefined()
|
||||||
|
@ -779,7 +812,9 @@ async function setup(testName: string): Promise<void> {
|
||||||
sshKey: sshPath ? 'some ssh private key' : '',
|
sshKey: sshPath ? 'some ssh private key' : '',
|
||||||
sshKnownHosts: '',
|
sshKnownHosts: '',
|
||||||
sshStrict: true,
|
sshStrict: true,
|
||||||
workflowOrganizationId: 123456
|
workflowOrganizationId: 123456,
|
||||||
|
setSafeDirectory: true,
|
||||||
|
githubServerUrl: githubServerUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ describe('input-helper tests', () => {
|
||||||
expect(settings.repositoryName).toBe('some-repo')
|
expect(settings.repositoryName).toBe('some-repo')
|
||||||
expect(settings.repositoryOwner).toBe('some-owner')
|
expect(settings.repositoryOwner).toBe('some-owner')
|
||||||
expect(settings.repositoryPath).toBe(gitHubWorkspace)
|
expect(settings.repositoryPath).toBe(gitHubWorkspace)
|
||||||
|
expect(settings.setSafeDirectory).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('qualifies ref', async () => {
|
it('qualifies ref', async () => {
|
||||||
|
|
|
@ -74,7 +74,13 @@ inputs:
|
||||||
When the `ssh-key` input is not provided, SSH URLs beginning with `git@github.com:` are
|
When the `ssh-key` input is not provided, SSH URLs beginning with `git@github.com:` are
|
||||||
converted to HTTPS.
|
converted to HTTPS.
|
||||||
default: false
|
default: false
|
||||||
|
set-safe-directory:
|
||||||
|
description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
|
||||||
|
default: true
|
||||||
|
github-server-url:
|
||||||
|
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: node12
|
using: node16
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
post: dist/index.js
|
post: dist/index.js
|
||||||
|
|
328
dist/index.js
vendored
328
dist/index.js
vendored
|
@ -1935,13 +1935,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getServerUrl = exports.getFetchUrl = void 0;
|
exports.isGhes = exports.getServerApiUrl = exports.getServerUrl = exports.getFetchUrl = void 0;
|
||||||
const assert = __importStar(__webpack_require__(357));
|
const assert = __importStar(__webpack_require__(357));
|
||||||
const url_1 = __webpack_require__(835);
|
const url_1 = __webpack_require__(835);
|
||||||
function getFetchUrl(settings) {
|
function getFetchUrl(settings) {
|
||||||
assert.ok(settings.repositoryOwner, 'settings.repositoryOwner must be defined');
|
assert.ok(settings.repositoryOwner, 'settings.repositoryOwner must be defined');
|
||||||
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined');
|
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined');
|
||||||
const serviceUrl = getServerUrl();
|
const serviceUrl = getServerUrl(settings.githubServerUrl);
|
||||||
const encodedOwner = encodeURIComponent(settings.repositoryOwner);
|
const encodedOwner = encodeURIComponent(settings.repositoryOwner);
|
||||||
const encodedName = encodeURIComponent(settings.repositoryName);
|
const encodedName = encodeURIComponent(settings.repositoryName);
|
||||||
if (settings.sshKey) {
|
if (settings.sshKey) {
|
||||||
|
@ -1951,13 +1951,27 @@ function getFetchUrl(settings) {
|
||||||
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
|
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
|
||||||
}
|
}
|
||||||
exports.getFetchUrl = getFetchUrl;
|
exports.getFetchUrl = getFetchUrl;
|
||||||
function getServerUrl() {
|
function getServerUrl(url) {
|
||||||
// todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
|
let urlValue = url && url.trim().length > 0
|
||||||
return new url_1.URL(process.env['GITHUB_SERVER_URL'] ||
|
? url
|
||||||
process.env['GITHUB_URL'] ||
|
: process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
||||||
'https://github.com');
|
return new url_1.URL(urlValue);
|
||||||
}
|
}
|
||||||
exports.getServerUrl = getServerUrl;
|
exports.getServerUrl = getServerUrl;
|
||||||
|
function getServerApiUrl(url) {
|
||||||
|
let apiUrl = 'https://api.github.com';
|
||||||
|
if (isGhes(url)) {
|
||||||
|
const serverUrl = getServerUrl(url);
|
||||||
|
apiUrl = new url_1.URL(`${serverUrl.origin}/api/v3`).toString();
|
||||||
|
}
|
||||||
|
return apiUrl;
|
||||||
|
}
|
||||||
|
exports.getServerApiUrl = getServerApiUrl;
|
||||||
|
function isGhes(url) {
|
||||||
|
const ghUrl = getServerUrl(url);
|
||||||
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||||
|
}
|
||||||
|
exports.isGhes = isGhes;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -3592,49 +3606,60 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.setSshKnownHostsPath = exports.setSshKeyPath = exports.setRepositoryPath = exports.SshKnownHostsPath = exports.SshKeyPath = exports.RepositoryPath = exports.IsPost = void 0;
|
exports.setSafeDirectory = exports.setSshKnownHostsPath = exports.setSshKeyPath = exports.setRepositoryPath = exports.SshKnownHostsPath = exports.SshKeyPath = exports.PostSetSafeDirectory = exports.RepositoryPath = exports.IsPost = void 0;
|
||||||
const coreCommand = __importStar(__webpack_require__(431));
|
const core = __importStar(__webpack_require__(470));
|
||||||
/**
|
/**
|
||||||
* Indicates whether the POST action is running
|
* Indicates whether the POST action is running
|
||||||
*/
|
*/
|
||||||
exports.IsPost = !!process.env['STATE_isPost'];
|
exports.IsPost = !!core.getState('isPost');
|
||||||
/**
|
/**
|
||||||
* The repository path for the POST action. The value is empty during the MAIN action.
|
* The repository path for the POST action. The value is empty during the MAIN action.
|
||||||
*/
|
*/
|
||||||
exports.RepositoryPath = process.env['STATE_repositoryPath'] || '';
|
exports.RepositoryPath = core.getState('repositoryPath');
|
||||||
|
/**
|
||||||
|
* The set-safe-directory for the POST action. The value is set if input: 'safe-directory' is set during the MAIN action.
|
||||||
|
*/
|
||||||
|
exports.PostSetSafeDirectory = core.getState('setSafeDirectory') === 'true';
|
||||||
/**
|
/**
|
||||||
* The SSH key path for the POST action. The value is empty during the MAIN action.
|
* The SSH key path for the POST action. The value is empty during the MAIN action.
|
||||||
*/
|
*/
|
||||||
exports.SshKeyPath = process.env['STATE_sshKeyPath'] || '';
|
exports.SshKeyPath = core.getState('sshKeyPath');
|
||||||
/**
|
/**
|
||||||
* The SSH known hosts path for the POST action. The value is empty during the MAIN action.
|
* The SSH known hosts path for the POST action. The value is empty during the MAIN action.
|
||||||
*/
|
*/
|
||||||
exports.SshKnownHostsPath = process.env['STATE_sshKnownHostsPath'] || '';
|
exports.SshKnownHostsPath = core.getState('sshKnownHostsPath');
|
||||||
/**
|
/**
|
||||||
* Save the repository path so the POST action can retrieve the value.
|
* Save the repository path so the POST action can retrieve the value.
|
||||||
*/
|
*/
|
||||||
function setRepositoryPath(repositoryPath) {
|
function setRepositoryPath(repositoryPath) {
|
||||||
coreCommand.issueCommand('save-state', { name: 'repositoryPath' }, repositoryPath);
|
core.saveState('repositoryPath', repositoryPath);
|
||||||
}
|
}
|
||||||
exports.setRepositoryPath = setRepositoryPath;
|
exports.setRepositoryPath = setRepositoryPath;
|
||||||
/**
|
/**
|
||||||
* Save the SSH key path so the POST action can retrieve the value.
|
* Save the SSH key path so the POST action can retrieve the value.
|
||||||
*/
|
*/
|
||||||
function setSshKeyPath(sshKeyPath) {
|
function setSshKeyPath(sshKeyPath) {
|
||||||
coreCommand.issueCommand('save-state', { name: 'sshKeyPath' }, sshKeyPath);
|
core.saveState('sshKeyPath', sshKeyPath);
|
||||||
}
|
}
|
||||||
exports.setSshKeyPath = setSshKeyPath;
|
exports.setSshKeyPath = setSshKeyPath;
|
||||||
/**
|
/**
|
||||||
* Save the SSH known hosts path so the POST action can retrieve the value.
|
* Save the SSH known hosts path so the POST action can retrieve the value.
|
||||||
*/
|
*/
|
||||||
function setSshKnownHostsPath(sshKnownHostsPath) {
|
function setSshKnownHostsPath(sshKnownHostsPath) {
|
||||||
coreCommand.issueCommand('save-state', { name: 'sshKnownHostsPath' }, sshKnownHostsPath);
|
core.saveState('sshKnownHostsPath', sshKnownHostsPath);
|
||||||
}
|
}
|
||||||
exports.setSshKnownHostsPath = setSshKnownHostsPath;
|
exports.setSshKnownHostsPath = setSshKnownHostsPath;
|
||||||
|
/**
|
||||||
|
* Save the sef-safe-directory input so the POST action can retrieve the value.
|
||||||
|
*/
|
||||||
|
function setSafeDirectory() {
|
||||||
|
core.saveState('setSafeDirectory', 'true');
|
||||||
|
}
|
||||||
|
exports.setSafeDirectory = setSafeDirectory;
|
||||||
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
|
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
|
||||||
// This is necessary since we don't have a separate entry point.
|
// This is necessary since we don't have a separate entry point.
|
||||||
if (!exports.IsPost) {
|
if (!exports.IsPost) {
|
||||||
coreCommand.issueCommand('save-state', { name: 'isPost' }, 'true');
|
core.saveState('isPost', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4055,6 +4080,51 @@ function authenticationPlugin(octokit, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 195:
|
||||||
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getOctokit = exports.Octokit = void 0;
|
||||||
|
const github = __importStar(__webpack_require__(469));
|
||||||
|
const url_helper_1 = __webpack_require__(81);
|
||||||
|
// Centralize all Octokit references by re-exporting
|
||||||
|
var rest_1 = __webpack_require__(0);
|
||||||
|
Object.defineProperty(exports, "Octokit", { enumerable: true, get: function () { return rest_1.Octokit; } });
|
||||||
|
function getOctokit(authToken, opts) {
|
||||||
|
const options = {
|
||||||
|
baseUrl: (0, url_helper_1.getServerApiUrl)(opts.baseUrl)
|
||||||
|
};
|
||||||
|
if (opts.userAgent) {
|
||||||
|
options.userAgent = opts.userAgent;
|
||||||
|
}
|
||||||
|
return new github.GitHub(authToken, options);
|
||||||
|
}
|
||||||
|
exports.getOctokit = getOctokit;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 197:
|
/***/ 197:
|
||||||
|
@ -4268,9 +4338,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0;
|
exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0;
|
||||||
const url_1 = __webpack_require__(835);
|
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const github = __importStar(__webpack_require__(469));
|
const github = __importStar(__webpack_require__(469));
|
||||||
|
const octokit_provider_1 = __webpack_require__(195);
|
||||||
|
const url_helper_1 = __webpack_require__(81);
|
||||||
exports.tagsRefSpec = '+refs/tags/*:refs/tags/*';
|
exports.tagsRefSpec = '+refs/tags/*:refs/tags/*';
|
||||||
function getCheckoutInfo(git, ref, commit) {
|
function getCheckoutInfo(git, ref, commit) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
@ -4420,12 +4491,12 @@ function testRef(git, ref, commit) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.testRef = testRef;
|
exports.testRef = testRef;
|
||||||
function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref, commit) {
|
function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref, commit, baseUrl) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
// GHES?
|
// GHES?
|
||||||
if (isGhes()) {
|
if ((0, url_helper_1.isGhes)(baseUrl)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Auth token?
|
// Auth token?
|
||||||
|
@ -4470,7 +4541,8 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
|
||||||
const actualHeadSha = match[1];
|
const actualHeadSha = match[1];
|
||||||
if (actualHeadSha !== expectedHeadSha) {
|
if (actualHeadSha !== expectedHeadSha) {
|
||||||
core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`);
|
core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`);
|
||||||
const octokit = new github.GitHub(token, {
|
const octokit = (0, octokit_provider_1.getOctokit)(token, {
|
||||||
|
baseUrl: baseUrl,
|
||||||
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload('number')};run_id=${process.env['GITHUB_RUN_ID']};expected_head_sha=${expectedHeadSha};actual_head_sha=${actualHeadSha})`
|
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload('number')};run_id=${process.env['GITHUB_RUN_ID']};expected_head_sha=${expectedHeadSha};actual_head_sha=${actualHeadSha})`
|
||||||
});
|
});
|
||||||
yield octokit.repos.get({ owner: repositoryOwner, repo: repositoryName });
|
yield octokit.repos.get({ owner: repositoryOwner, repo: repositoryName });
|
||||||
|
@ -4496,10 +4568,6 @@ function select(obj, path) {
|
||||||
const key = path.substr(0, i);
|
const key = path.substr(0, i);
|
||||||
return select(obj[key], path.substr(i + 1));
|
return select(obj[key], path.substr(i + 1));
|
||||||
}
|
}
|
||||||
function isGhes() {
|
|
||||||
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -6550,7 +6618,7 @@ class GitAuthHelper {
|
||||||
this.git = gitCommandManager;
|
this.git = gitCommandManager;
|
||||||
this.settings = gitSourceSettings || {};
|
this.settings = gitSourceSettings || {};
|
||||||
// Token auth header
|
// Token auth header
|
||||||
const serverUrl = urlHelper.getServerUrl();
|
const serverUrl = urlHelper.getServerUrl(this.settings.githubServerUrl);
|
||||||
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader`; // "origin" is SCHEME://HOSTNAME[:PORT]
|
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader`; // "origin" is SCHEME://HOSTNAME[:PORT]
|
||||||
const basicCredential = Buffer.from(`x-access-token:${this.settings.authToken}`, 'utf8').toString('base64');
|
const basicCredential = Buffer.from(`x-access-token:${this.settings.authToken}`, 'utf8').toString('base64');
|
||||||
core.setSecret(basicCredential);
|
core.setSecret(basicCredential);
|
||||||
|
@ -6572,9 +6640,13 @@ class GitAuthHelper {
|
||||||
yield this.configureToken();
|
yield this.configureToken();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
configureGlobalAuth() {
|
configureTempGlobalConfig() {
|
||||||
var _a;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Already setup global config
|
||||||
|
if (((_a = this.temporaryHomePath) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
||||||
|
return path.join(this.temporaryHomePath, '.gitconfig');
|
||||||
|
}
|
||||||
// Create a temp home directory
|
// Create a temp home directory
|
||||||
const runnerTemp = process.env['RUNNER_TEMP'] || '';
|
const runnerTemp = process.env['RUNNER_TEMP'] || '';
|
||||||
assert.ok(runnerTemp, 'RUNNER_TEMP is not defined');
|
assert.ok(runnerTemp, 'RUNNER_TEMP is not defined');
|
||||||
|
@ -6590,7 +6662,7 @@ class GitAuthHelper {
|
||||||
configExists = true;
|
configExists = true;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (((_a = err) === null || _a === void 0 ? void 0 : _a.code) !== 'ENOENT') {
|
if (((_b = err) === null || _b === void 0 ? void 0 : _b.code) !== 'ENOENT') {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6601,10 +6673,17 @@ class GitAuthHelper {
|
||||||
else {
|
else {
|
||||||
yield fs.promises.writeFile(newGitConfigPath, '');
|
yield fs.promises.writeFile(newGitConfigPath, '');
|
||||||
}
|
}
|
||||||
|
// Override HOME
|
||||||
|
core.info(`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`);
|
||||||
|
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath);
|
||||||
|
return newGitConfigPath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
configureGlobalAuth() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// 'configureTempGlobalConfig' noops if already set, just returns the path
|
||||||
|
const newGitConfigPath = yield this.configureTempGlobalConfig();
|
||||||
try {
|
try {
|
||||||
// Override HOME
|
|
||||||
core.info(`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`);
|
|
||||||
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath);
|
|
||||||
// Configure the token
|
// Configure the token
|
||||||
yield this.configureToken(newGitConfigPath, true);
|
yield this.configureToken(newGitConfigPath, true);
|
||||||
// Configure HTTPS instead of SSH
|
// Configure HTTPS instead of SSH
|
||||||
|
@ -6657,11 +6736,14 @@ class GitAuthHelper {
|
||||||
yield this.removeToken();
|
yield this.removeToken();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
removeGlobalAuth() {
|
removeGlobalConfig() {
|
||||||
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Unsetting HOME override`);
|
if (((_a = this.temporaryHomePath) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
||||||
this.git.removeEnvironmentVariable('HOME');
|
core.debug(`Unsetting HOME override`);
|
||||||
yield io.rmRF(this.temporaryHomePath);
|
this.git.removeEnvironmentVariable('HOME');
|
||||||
|
yield io.rmRF(this.temporaryHomePath);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
configureSsh() {
|
configureSsh() {
|
||||||
|
@ -7337,40 +7419,59 @@ function getSource(settings) {
|
||||||
core.startGroup('Getting Git version info');
|
core.startGroup('Getting Git version info');
|
||||||
const git = yield getGitCommandManager(settings);
|
const git = yield getGitCommandManager(settings);
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// Prepare existing directory, otherwise recreate
|
let authHelper = null;
|
||||||
if (isExisting) {
|
|
||||||
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean, settings.ref);
|
|
||||||
}
|
|
||||||
if (!git) {
|
|
||||||
// Downloading using REST API
|
|
||||||
core.info(`The repository will be downloaded using the GitHub REST API`);
|
|
||||||
core.info(`To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`);
|
|
||||||
if (settings.submodules) {
|
|
||||||
throw new Error(`Input 'submodules' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`);
|
|
||||||
}
|
|
||||||
else if (settings.sshKey) {
|
|
||||||
throw new Error(`Input 'ssh-key' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`);
|
|
||||||
}
|
|
||||||
yield githubApiHelper.downloadRepository(settings.authToken, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Save state for POST action
|
|
||||||
stateHelper.setRepositoryPath(settings.repositoryPath);
|
|
||||||
// Initialize the repository
|
|
||||||
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
|
|
||||||
core.startGroup('Initializing the repository');
|
|
||||||
yield git.init();
|
|
||||||
yield git.remoteAdd('origin', repositoryUrl);
|
|
||||||
core.endGroup();
|
|
||||||
}
|
|
||||||
// Disable automatic garbage collection
|
|
||||||
core.startGroup('Disabling automatic garbage collection');
|
|
||||||
if (!(yield git.tryDisableAutomaticGarbageCollection())) {
|
|
||||||
core.warning(`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`);
|
|
||||||
}
|
|
||||||
core.endGroup();
|
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git, settings);
|
|
||||||
try {
|
try {
|
||||||
|
if (git) {
|
||||||
|
authHelper = gitAuthHelper.createAuthHelper(git, settings);
|
||||||
|
if (settings.setSafeDirectory) {
|
||||||
|
// Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
|
||||||
|
// Otherwise all git commands we run in a container fail
|
||||||
|
yield authHelper.configureTempGlobalConfig();
|
||||||
|
core.info(`Adding repository directory to the temporary git global config as a safe directory`);
|
||||||
|
yield git
|
||||||
|
.config('safe.directory', settings.repositoryPath, true, true)
|
||||||
|
.catch(error => {
|
||||||
|
core.info(`Failed to initialize safe directory with error: ${error}`);
|
||||||
|
});
|
||||||
|
stateHelper.setSafeDirectory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Prepare existing directory, otherwise recreate
|
||||||
|
if (isExisting) {
|
||||||
|
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean, settings.ref);
|
||||||
|
}
|
||||||
|
if (!git) {
|
||||||
|
// Downloading using REST API
|
||||||
|
core.info(`The repository will be downloaded using the GitHub REST API`);
|
||||||
|
core.info(`To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`);
|
||||||
|
if (settings.submodules) {
|
||||||
|
throw new Error(`Input 'submodules' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`);
|
||||||
|
}
|
||||||
|
else if (settings.sshKey) {
|
||||||
|
throw new Error(`Input 'ssh-key' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`);
|
||||||
|
}
|
||||||
|
yield githubApiHelper.downloadRepository(settings.authToken, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath, settings.githubServerUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Save state for POST action
|
||||||
|
stateHelper.setRepositoryPath(settings.repositoryPath);
|
||||||
|
// Initialize the repository
|
||||||
|
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
|
||||||
|
core.startGroup('Initializing the repository');
|
||||||
|
yield git.init();
|
||||||
|
yield git.remoteAdd('origin', repositoryUrl);
|
||||||
|
core.endGroup();
|
||||||
|
}
|
||||||
|
// Disable automatic garbage collection
|
||||||
|
core.startGroup('Disabling automatic garbage collection');
|
||||||
|
if (!(yield git.tryDisableAutomaticGarbageCollection())) {
|
||||||
|
core.warning(`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`);
|
||||||
|
}
|
||||||
|
core.endGroup();
|
||||||
|
// If we didn't initialize it above, do it now
|
||||||
|
if (!authHelper) {
|
||||||
|
authHelper = gitAuthHelper.createAuthHelper(git, settings);
|
||||||
|
}
|
||||||
// Configure auth
|
// Configure auth
|
||||||
core.startGroup('Setting up auth');
|
core.startGroup('Setting up auth');
|
||||||
yield authHelper.configureAuth();
|
yield authHelper.configureAuth();
|
||||||
|
@ -7382,7 +7483,7 @@ function getSource(settings) {
|
||||||
settings.ref = yield git.getDefaultBranch(repositoryUrl);
|
settings.ref = yield git.getDefaultBranch(repositoryUrl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
settings.ref = yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName);
|
settings.ref = yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName, settings.githubServerUrl);
|
||||||
}
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
}
|
}
|
||||||
|
@ -7432,27 +7533,21 @@ function getSource(settings) {
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// Submodules
|
// Submodules
|
||||||
if (settings.submodules) {
|
if (settings.submodules) {
|
||||||
try {
|
// Temporarily override global config
|
||||||
// Temporarily override global config
|
core.startGroup('Setting up auth for fetching submodules');
|
||||||
core.startGroup('Setting up auth for fetching submodules');
|
yield authHelper.configureGlobalAuth();
|
||||||
yield authHelper.configureGlobalAuth();
|
core.endGroup();
|
||||||
|
// Checkout submodules
|
||||||
|
core.startGroup('Fetching submodules');
|
||||||
|
yield git.submoduleSync(settings.nestedSubmodules);
|
||||||
|
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
|
||||||
|
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
|
||||||
|
core.endGroup();
|
||||||
|
// Persist credentials
|
||||||
|
if (settings.persistCredentials) {
|
||||||
|
core.startGroup('Persisting credentials for submodules');
|
||||||
|
yield authHelper.configureSubmoduleAuth();
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// Checkout submodules
|
|
||||||
core.startGroup('Fetching submodules');
|
|
||||||
yield git.submoduleSync(settings.nestedSubmodules);
|
|
||||||
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
|
|
||||||
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
|
|
||||||
core.endGroup();
|
|
||||||
// Persist credentials
|
|
||||||
if (settings.persistCredentials) {
|
|
||||||
core.startGroup('Persisting credentials for submodules');
|
|
||||||
yield authHelper.configureSubmoduleAuth();
|
|
||||||
core.endGroup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Remove temporary global config override
|
|
||||||
yield authHelper.removeGlobalAuth();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get commit information
|
// Get commit information
|
||||||
|
@ -7460,14 +7555,17 @@ function getSource(settings) {
|
||||||
// Log commit sha
|
// Log commit sha
|
||||||
yield git.log1("--format='%H'");
|
yield git.log1("--format='%H'");
|
||||||
// Check for incorrect pull request merge commit
|
// Check for incorrect pull request merge commit
|
||||||
yield refHelper.checkCommitInfo(settings.authToken, commitInfo, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit);
|
yield refHelper.checkCommitInfo(settings.authToken, commitInfo, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.githubServerUrl);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Remove auth
|
// Remove auth
|
||||||
if (!settings.persistCredentials) {
|
if (authHelper) {
|
||||||
core.startGroup('Removing auth');
|
if (!settings.persistCredentials) {
|
||||||
yield authHelper.removeAuth();
|
core.startGroup('Removing auth');
|
||||||
core.endGroup();
|
yield authHelper.removeAuth();
|
||||||
|
core.endGroup();
|
||||||
|
}
|
||||||
|
authHelper.removeGlobalConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -7489,7 +7587,23 @@ function cleanup(repositoryPath) {
|
||||||
}
|
}
|
||||||
// Remove auth
|
// Remove auth
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git);
|
const authHelper = gitAuthHelper.createAuthHelper(git);
|
||||||
yield authHelper.removeAuth();
|
try {
|
||||||
|
if (stateHelper.PostSetSafeDirectory) {
|
||||||
|
// Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
|
||||||
|
// Otherwise all git commands we run in a container fail
|
||||||
|
yield authHelper.configureTempGlobalConfig();
|
||||||
|
core.info(`Adding repository directory to the temporary git global config as a safe directory`);
|
||||||
|
yield git
|
||||||
|
.config('safe.directory', repositoryPath, true, true)
|
||||||
|
.catch(error => {
|
||||||
|
core.info(`Failed to initialize safe directory with error: ${error}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
yield authHelper.removeAuth();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
yield authHelper.removeGlobalConfig();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.cleanup = cleanup;
|
exports.cleanup = cleanup;
|
||||||
|
@ -10900,24 +11014,24 @@ exports.getDefaultBranch = exports.downloadRepository = void 0;
|
||||||
const assert = __importStar(__webpack_require__(357));
|
const assert = __importStar(__webpack_require__(357));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const github = __importStar(__webpack_require__(469));
|
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const retryHelper = __importStar(__webpack_require__(587));
|
const retryHelper = __importStar(__webpack_require__(587));
|
||||||
const toolCache = __importStar(__webpack_require__(533));
|
const toolCache = __importStar(__webpack_require__(533));
|
||||||
const v4_1 = __importDefault(__webpack_require__(826));
|
const v4_1 = __importDefault(__webpack_require__(826));
|
||||||
|
const octokit_provider_1 = __webpack_require__(195);
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath) {
|
function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, baseUrl) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Determine the default branch
|
// Determine the default branch
|
||||||
if (!ref && !commit) {
|
if (!ref && !commit) {
|
||||||
core.info('Determining the default branch');
|
core.info('Determining the default branch');
|
||||||
ref = yield getDefaultBranch(authToken, owner, repo);
|
ref = yield getDefaultBranch(authToken, owner, repo, baseUrl);
|
||||||
}
|
}
|
||||||
// Download the archive
|
// Download the archive
|
||||||
let archiveData = yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
let archiveData = yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info('Downloading the archive');
|
core.info('Downloading the archive');
|
||||||
return yield downloadArchive(authToken, owner, repo, ref, commit);
|
return yield downloadArchive(authToken, owner, repo, ref, commit, baseUrl);
|
||||||
}));
|
}));
|
||||||
// Write archive to disk
|
// Write archive to disk
|
||||||
core.info('Writing archive to disk');
|
core.info('Writing archive to disk');
|
||||||
|
@ -10961,12 +11075,12 @@ exports.downloadRepository = downloadRepository;
|
||||||
/**
|
/**
|
||||||
* Looks up the default branch name
|
* Looks up the default branch name
|
||||||
*/
|
*/
|
||||||
function getDefaultBranch(authToken, owner, repo) {
|
function getDefaultBranch(authToken, owner, repo, baseUrl) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
||||||
var _a;
|
var _a;
|
||||||
core.info('Retrieving the default branch name');
|
core.info('Retrieving the default branch name');
|
||||||
const octokit = new github.GitHub(authToken);
|
const octokit = (0, octokit_provider_1.getOctokit)(authToken, { baseUrl: baseUrl });
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
// Get the default branch from the repo info
|
// Get the default branch from the repo info
|
||||||
|
@ -10996,9 +11110,9 @@ function getDefaultBranch(authToken, owner, repo) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getDefaultBranch = getDefaultBranch;
|
exports.getDefaultBranch = getDefaultBranch;
|
||||||
function downloadArchive(authToken, owner, repo, ref, commit) {
|
function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const octokit = new github.GitHub(authToken);
|
const octokit = (0, octokit_provider_1.getOctokit)(authToken, { baseUrl: baseUrl });
|
||||||
const params = {
|
const params = {
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
|
@ -17271,6 +17385,12 @@ function getInputs() {
|
||||||
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
|
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
|
||||||
// Workflow organization ID
|
// Workflow organization ID
|
||||||
result.workflowOrganizationId = yield workflowContextHelper.getOrganizationId();
|
result.workflowOrganizationId = yield workflowContextHelper.getOrganizationId();
|
||||||
|
// Set safe.directory in git global config.
|
||||||
|
result.setSafeDirectory =
|
||||||
|
(core.getInput('set-safe-directory') || 'true').toUpperCase() === 'TRUE';
|
||||||
|
// Determine the GitHub URL that the repository is being hosted from
|
||||||
|
result.githubServerUrl = core.getInput('github-server-url');
|
||||||
|
core.debug(`GitHub Host URL = ${result.githubServerUrl}`);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
101
package-lock.json
generated
101
package-lock.json
generated
|
@ -1,13 +1,32 @@
|
||||||
{
|
{
|
||||||
"name": "checkout",
|
"name": "checkout",
|
||||||
"version": "2.0.2",
|
"version": "3.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.2.6",
|
"version": "1.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
|
||||||
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
|
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
|
||||||
|
"requires": {
|
||||||
|
"@actions/http-client": "^2.0.1",
|
||||||
|
"uuid": "^8.3.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/http-client": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
|
||||||
|
"requires": {
|
||||||
|
"tunnel": "^0.0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uuid": {
|
||||||
|
"version": "8.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"@actions/exec": {
|
"@actions/exec": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
|
@ -1929,12 +1948,6 @@
|
||||||
"picomatch": "^2.2.3"
|
"picomatch": "^2.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -3325,12 +3338,6 @@
|
||||||
"picomatch": "^2.2.3"
|
"picomatch": "^2.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -5389,12 +5396,6 @@
|
||||||
"picomatch": "^2.2.3"
|
"picomatch": "^2.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -7714,12 +7715,6 @@
|
||||||
"minimist": "^1.2.5"
|
"minimist": "^1.2.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "6.3.0",
|
"version": "6.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||||
|
@ -9368,12 +9363,6 @@
|
||||||
"picomatch": "^2.2.3"
|
"picomatch": "^2.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -11389,12 +11378,6 @@
|
||||||
"picomatch": "^2.2.3"
|
"picomatch": "^2.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -12940,12 +12923,6 @@
|
||||||
"picomatch": "^2.2.3"
|
"picomatch": "^2.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -13700,12 +13677,6 @@
|
||||||
"picomatch": "^2.2.3"
|
"picomatch": "^2.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -14633,12 +14604,6 @@
|
||||||
"integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
|
"integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"normalize-path": {
|
"normalize-path": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||||
|
@ -15730,14 +15695,6 @@
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "^1.2.0"
|
"minimist": "^1.2.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"kleur": {
|
"kleur": {
|
||||||
|
@ -15934,9 +15891,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.5",
|
"version": "1.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
|
||||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
|
@ -15957,9 +15914,9 @@
|
||||||
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
|
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
|
||||||
},
|
},
|
||||||
"node-fetch": {
|
"node-fetch": {
|
||||||
"version": "2.6.5",
|
"version": "2.6.7",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
|
||||||
"integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
|
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"whatwg-url": "^5.0.0"
|
"whatwg-url": "^5.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "checkout",
|
"name": "checkout",
|
||||||
"version": "2.0.2",
|
"version": "3.1.0",
|
||||||
"description": "checkout action",
|
"description": "checkout action",
|
||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/actions/checkout#readme",
|
"homepage": "https://github.com/actions/checkout#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.0.1",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/github": "^2.2.0",
|
"@actions/github": "^2.2.0",
|
||||||
"@actions/io": "^1.0.1",
|
"@actions/io": "^1.0.1",
|
||||||
|
|
|
@ -19,8 +19,9 @@ export interface IGitAuthHelper {
|
||||||
configureAuth(): Promise<void>
|
configureAuth(): Promise<void>
|
||||||
configureGlobalAuth(): Promise<void>
|
configureGlobalAuth(): Promise<void>
|
||||||
configureSubmoduleAuth(): Promise<void>
|
configureSubmoduleAuth(): Promise<void>
|
||||||
|
configureTempGlobalConfig(): Promise<string>
|
||||||
removeAuth(): Promise<void>
|
removeAuth(): Promise<void>
|
||||||
removeGlobalAuth(): Promise<void>
|
removeGlobalConfig(): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createAuthHelper(
|
export function createAuthHelper(
|
||||||
|
@ -51,7 +52,7 @@ class GitAuthHelper {
|
||||||
this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings)
|
this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings)
|
||||||
|
|
||||||
// Token auth header
|
// Token auth header
|
||||||
const serverUrl = urlHelper.getServerUrl()
|
const serverUrl = urlHelper.getServerUrl(this.settings.githubServerUrl)
|
||||||
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT]
|
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT]
|
||||||
const basicCredential = Buffer.from(
|
const basicCredential = Buffer.from(
|
||||||
`x-access-token:${this.settings.authToken}`,
|
`x-access-token:${this.settings.authToken}`,
|
||||||
|
@ -80,7 +81,11 @@ class GitAuthHelper {
|
||||||
await this.configureToken()
|
await this.configureToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
async configureGlobalAuth(): Promise<void> {
|
async configureTempGlobalConfig(): Promise<string> {
|
||||||
|
// Already setup global config
|
||||||
|
if (this.temporaryHomePath?.length > 0) {
|
||||||
|
return path.join(this.temporaryHomePath, '.gitconfig')
|
||||||
|
}
|
||||||
// Create a temp home directory
|
// Create a temp home directory
|
||||||
const runnerTemp = process.env['RUNNER_TEMP'] || ''
|
const runnerTemp = process.env['RUNNER_TEMP'] || ''
|
||||||
assert.ok(runnerTemp, 'RUNNER_TEMP is not defined')
|
assert.ok(runnerTemp, 'RUNNER_TEMP is not defined')
|
||||||
|
@ -110,13 +115,19 @@ class GitAuthHelper {
|
||||||
await fs.promises.writeFile(newGitConfigPath, '')
|
await fs.promises.writeFile(newGitConfigPath, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// Override HOME
|
||||||
// Override HOME
|
core.info(
|
||||||
core.info(
|
`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`
|
||||||
`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`
|
)
|
||||||
)
|
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath)
|
||||||
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath)
|
|
||||||
|
|
||||||
|
return newGitConfigPath
|
||||||
|
}
|
||||||
|
|
||||||
|
async configureGlobalAuth(): Promise<void> {
|
||||||
|
// 'configureTempGlobalConfig' noops if already set, just returns the path
|
||||||
|
const newGitConfigPath = await this.configureTempGlobalConfig()
|
||||||
|
try {
|
||||||
// Configure the token
|
// Configure the token
|
||||||
await this.configureToken(newGitConfigPath, true)
|
await this.configureToken(newGitConfigPath, true)
|
||||||
|
|
||||||
|
@ -181,10 +192,12 @@ class GitAuthHelper {
|
||||||
await this.removeToken()
|
await this.removeToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeGlobalAuth(): Promise<void> {
|
async removeGlobalConfig(): Promise<void> {
|
||||||
core.debug(`Unsetting HOME override`)
|
if (this.temporaryHomePath?.length > 0) {
|
||||||
this.git.removeEnvironmentVariable('HOME')
|
core.debug(`Unsetting HOME override`)
|
||||||
await io.rmRF(this.temporaryHomePath)
|
this.git.removeEnvironmentVariable('HOME')
|
||||||
|
await io.rmRF(this.temporaryHomePath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async configureSsh(): Promise<void> {
|
private async configureSsh(): Promise<void> {
|
||||||
|
|
|
@ -36,68 +36,95 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
const git = await getGitCommandManager(settings)
|
const git = await getGitCommandManager(settings)
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
// Prepare existing directory, otherwise recreate
|
let authHelper: gitAuthHelper.IGitAuthHelper | null = null
|
||||||
if (isExisting) {
|
try {
|
||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
if (git) {
|
||||||
git,
|
authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
||||||
settings.repositoryPath,
|
if (settings.setSafeDirectory) {
|
||||||
repositoryUrl,
|
// Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
|
||||||
settings.clean,
|
// Otherwise all git commands we run in a container fail
|
||||||
settings.ref
|
await authHelper.configureTempGlobalConfig()
|
||||||
)
|
core.info(
|
||||||
}
|
`Adding repository directory to the temporary git global config as a safe directory`
|
||||||
|
)
|
||||||
|
|
||||||
if (!git) {
|
await git
|
||||||
// Downloading using REST API
|
.config('safe.directory', settings.repositoryPath, true, true)
|
||||||
core.info(`The repository will be downloaded using the GitHub REST API`)
|
.catch(error => {
|
||||||
core.info(
|
core.info(
|
||||||
`To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`
|
`Failed to initialize safe directory with error: ${error}`
|
||||||
)
|
)
|
||||||
if (settings.submodules) {
|
})
|
||||||
throw new Error(
|
|
||||||
`Input 'submodules' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`
|
stateHelper.setSafeDirectory()
|
||||||
)
|
}
|
||||||
} else if (settings.sshKey) {
|
}
|
||||||
throw new Error(
|
|
||||||
`Input 'ssh-key' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`
|
// Prepare existing directory, otherwise recreate
|
||||||
|
if (isExisting) {
|
||||||
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
|
git,
|
||||||
|
settings.repositoryPath,
|
||||||
|
repositoryUrl,
|
||||||
|
settings.clean,
|
||||||
|
settings.ref
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
await githubApiHelper.downloadRepository(
|
if (!git) {
|
||||||
settings.authToken,
|
// Downloading using REST API
|
||||||
settings.repositoryOwner,
|
core.info(`The repository will be downloaded using the GitHub REST API`)
|
||||||
settings.repositoryName,
|
core.info(
|
||||||
settings.ref,
|
`To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`
|
||||||
settings.commit,
|
)
|
||||||
settings.repositoryPath
|
if (settings.submodules) {
|
||||||
)
|
throw new Error(
|
||||||
return
|
`Input 'submodules' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`
|
||||||
}
|
)
|
||||||
|
} else if (settings.sshKey) {
|
||||||
|
throw new Error(
|
||||||
|
`Input 'ssh-key' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Save state for POST action
|
await githubApiHelper.downloadRepository(
|
||||||
stateHelper.setRepositoryPath(settings.repositoryPath)
|
settings.authToken,
|
||||||
|
settings.repositoryOwner,
|
||||||
|
settings.repositoryName,
|
||||||
|
settings.ref,
|
||||||
|
settings.commit,
|
||||||
|
settings.repositoryPath,
|
||||||
|
settings.githubServerUrl
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the repository
|
// Save state for POST action
|
||||||
if (
|
stateHelper.setRepositoryPath(settings.repositoryPath)
|
||||||
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
|
|
||||||
) {
|
// Initialize the repository
|
||||||
core.startGroup('Initializing the repository')
|
if (
|
||||||
await git.init()
|
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
|
||||||
await git.remoteAdd('origin', repositoryUrl)
|
) {
|
||||||
|
core.startGroup('Initializing the repository')
|
||||||
|
await git.init()
|
||||||
|
await git.remoteAdd('origin', repositoryUrl)
|
||||||
|
core.endGroup()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable automatic garbage collection
|
||||||
|
core.startGroup('Disabling automatic garbage collection')
|
||||||
|
if (!(await git.tryDisableAutomaticGarbageCollection())) {
|
||||||
|
core.warning(
|
||||||
|
`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`
|
||||||
|
)
|
||||||
|
}
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
}
|
|
||||||
|
|
||||||
// Disable automatic garbage collection
|
// If we didn't initialize it above, do it now
|
||||||
core.startGroup('Disabling automatic garbage collection')
|
if (!authHelper) {
|
||||||
if (!(await git.tryDisableAutomaticGarbageCollection())) {
|
authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
||||||
core.warning(
|
}
|
||||||
`Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
core.endGroup()
|
|
||||||
|
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
|
||||||
try {
|
|
||||||
// Configure auth
|
// Configure auth
|
||||||
core.startGroup('Setting up auth')
|
core.startGroup('Setting up auth')
|
||||||
await authHelper.configureAuth()
|
await authHelper.configureAuth()
|
||||||
|
@ -112,7 +139,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
settings.ref = await githubApiHelper.getDefaultBranch(
|
settings.ref = await githubApiHelper.getDefaultBranch(
|
||||||
settings.authToken,
|
settings.authToken,
|
||||||
settings.repositoryOwner,
|
settings.repositoryOwner,
|
||||||
settings.repositoryName
|
settings.repositoryName,
|
||||||
|
settings.githubServerUrl
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
@ -177,34 +205,26 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
|
|
||||||
// Submodules
|
// Submodules
|
||||||
if (settings.submodules) {
|
if (settings.submodules) {
|
||||||
try {
|
// Temporarily override global config
|
||||||
// Temporarily override global config
|
core.startGroup('Setting up auth for fetching submodules')
|
||||||
core.startGroup('Setting up auth for fetching submodules')
|
await authHelper.configureGlobalAuth()
|
||||||
await authHelper.configureGlobalAuth()
|
core.endGroup()
|
||||||
core.endGroup()
|
|
||||||
|
|
||||||
// Checkout submodules
|
// Checkout submodules
|
||||||
core.startGroup('Fetching submodules')
|
core.startGroup('Fetching submodules')
|
||||||
await git.submoduleSync(settings.nestedSubmodules)
|
await git.submoduleSync(settings.nestedSubmodules)
|
||||||
await git.submoduleUpdate(
|
await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules)
|
||||||
settings.fetchDepth,
|
await git.submoduleForeach(
|
||||||
settings.nestedSubmodules
|
'git config --local gc.auto 0',
|
||||||
)
|
settings.nestedSubmodules
|
||||||
await git.submoduleForeach(
|
)
|
||||||
'git config --local gc.auto 0',
|
core.endGroup()
|
||||||
settings.nestedSubmodules
|
|
||||||
)
|
|
||||||
core.endGroup()
|
|
||||||
|
|
||||||
// Persist credentials
|
// Persist credentials
|
||||||
if (settings.persistCredentials) {
|
if (settings.persistCredentials) {
|
||||||
core.startGroup('Persisting credentials for submodules')
|
core.startGroup('Persisting credentials for submodules')
|
||||||
await authHelper.configureSubmoduleAuth()
|
await authHelper.configureSubmoduleAuth()
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
// Remove temporary global config override
|
|
||||||
await authHelper.removeGlobalAuth()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,14 +241,18 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
settings.repositoryOwner,
|
settings.repositoryOwner,
|
||||||
settings.repositoryName,
|
settings.repositoryName,
|
||||||
settings.ref,
|
settings.ref,
|
||||||
settings.commit
|
settings.commit,
|
||||||
|
settings.githubServerUrl
|
||||||
)
|
)
|
||||||
} finally {
|
} finally {
|
||||||
// Remove auth
|
// Remove auth
|
||||||
if (!settings.persistCredentials) {
|
if (authHelper) {
|
||||||
core.startGroup('Removing auth')
|
if (!settings.persistCredentials) {
|
||||||
await authHelper.removeAuth()
|
core.startGroup('Removing auth')
|
||||||
core.endGroup()
|
await authHelper.removeAuth()
|
||||||
|
core.endGroup()
|
||||||
|
}
|
||||||
|
authHelper.removeGlobalConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +275,26 @@ export async function cleanup(repositoryPath: string): Promise<void> {
|
||||||
|
|
||||||
// Remove auth
|
// Remove auth
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git)
|
const authHelper = gitAuthHelper.createAuthHelper(git)
|
||||||
await authHelper.removeAuth()
|
try {
|
||||||
|
if (stateHelper.PostSetSafeDirectory) {
|
||||||
|
// Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
|
||||||
|
// Otherwise all git commands we run in a container fail
|
||||||
|
await authHelper.configureTempGlobalConfig()
|
||||||
|
core.info(
|
||||||
|
`Adding repository directory to the temporary git global config as a safe directory`
|
||||||
|
)
|
||||||
|
|
||||||
|
await git
|
||||||
|
.config('safe.directory', repositoryPath, true, true)
|
||||||
|
.catch(error => {
|
||||||
|
core.info(`Failed to initialize safe directory with error: ${error}`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
await authHelper.removeAuth()
|
||||||
|
} finally {
|
||||||
|
await authHelper.removeGlobalConfig()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGitCommandManager(
|
async function getGitCommandManager(
|
||||||
|
|
|
@ -79,6 +79,16 @@ export interface IGitSourceSettings {
|
||||||
*/
|
*/
|
||||||
workflowOrganizationId: number | undefined
|
workflowOrganizationId: number | undefined
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether to add repositoryPath as safe.directory in git global config
|
||||||
|
*/
|
||||||
|
setSafeDirectory: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User override on the GitHub Server/Host URL that hosts the repository to be cloned
|
||||||
|
*/
|
||||||
|
githubServerUrl: string | undefined
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patterns to do a sparse checkout on
|
* Patterns to do a sparse checkout on
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import * as assert from 'assert'
|
import * as assert from 'assert'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as github from '@actions/github'
|
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as retryHelper from './retry-helper'
|
import * as retryHelper from './retry-helper'
|
||||||
import * as toolCache from '@actions/tool-cache'
|
import * as toolCache from '@actions/tool-cache'
|
||||||
import {default as uuid} from 'uuid/v4'
|
import {default as uuid} from 'uuid/v4'
|
||||||
import {Octokit} from '@octokit/rest'
|
import {getOctokit, Octokit} from './octokit-provider'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
|
@ -17,18 +16,19 @@ export async function downloadRepository(
|
||||||
repo: string,
|
repo: string,
|
||||||
ref: string,
|
ref: string,
|
||||||
commit: string,
|
commit: string,
|
||||||
repositoryPath: string
|
repositoryPath: string,
|
||||||
|
baseUrl?: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Determine the default branch
|
// Determine the default branch
|
||||||
if (!ref && !commit) {
|
if (!ref && !commit) {
|
||||||
core.info('Determining the default branch')
|
core.info('Determining the default branch')
|
||||||
ref = await getDefaultBranch(authToken, owner, repo)
|
ref = await getDefaultBranch(authToken, owner, repo, baseUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download the archive
|
// Download the archive
|
||||||
let archiveData = await retryHelper.execute(async () => {
|
let archiveData = await retryHelper.execute(async () => {
|
||||||
core.info('Downloading the archive')
|
core.info('Downloading the archive')
|
||||||
return await downloadArchive(authToken, owner, repo, ref, commit)
|
return await downloadArchive(authToken, owner, repo, ref, commit, baseUrl)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Write archive to disk
|
// Write archive to disk
|
||||||
|
@ -79,11 +79,12 @@ export async function downloadRepository(
|
||||||
export async function getDefaultBranch(
|
export async function getDefaultBranch(
|
||||||
authToken: string,
|
authToken: string,
|
||||||
owner: string,
|
owner: string,
|
||||||
repo: string
|
repo: string,
|
||||||
|
baseUrl?: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return await retryHelper.execute(async () => {
|
return await retryHelper.execute(async () => {
|
||||||
core.info('Retrieving the default branch name')
|
core.info('Retrieving the default branch name')
|
||||||
const octokit = new github.GitHub(authToken)
|
const octokit = getOctokit(authToken, {baseUrl: baseUrl})
|
||||||
let result: string
|
let result: string
|
||||||
try {
|
try {
|
||||||
// Get the default branch from the repo info
|
// Get the default branch from the repo info
|
||||||
|
@ -121,9 +122,10 @@ async function downloadArchive(
|
||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
ref: string,
|
ref: string,
|
||||||
commit: string
|
commit: string,
|
||||||
|
baseUrl?: string
|
||||||
): Promise<Buffer> {
|
): Promise<Buffer> {
|
||||||
const octokit = new github.GitHub(authToken)
|
const octokit = getOctokit(authToken, {baseUrl: baseUrl})
|
||||||
const params: Octokit.ReposGetArchiveLinkParams = {
|
const params: Octokit.ReposGetArchiveLinkParams = {
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
|
|
|
@ -135,5 +135,13 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||||
// Workflow organization ID
|
// Workflow organization ID
|
||||||
result.workflowOrganizationId = await workflowContextHelper.getOrganizationId()
|
result.workflowOrganizationId = await workflowContextHelper.getOrganizationId()
|
||||||
|
|
||||||
|
// Set safe.directory in git global config.
|
||||||
|
result.setSafeDirectory =
|
||||||
|
(core.getInput('set-safe-directory') || 'true').toUpperCase() === 'TRUE'
|
||||||
|
|
||||||
|
// Determine the GitHub URL that the repository is being hosted from
|
||||||
|
result.githubServerUrl = core.getInput('github-server-url')
|
||||||
|
core.debug(`GitHub Host URL = ${result.githubServerUrl}`)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ function updateUsage(
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUsage(
|
updateUsage(
|
||||||
'actions/checkout@v2',
|
'actions/checkout@v3',
|
||||||
path.join(__dirname, '..', '..', 'action.yml'),
|
path.join(__dirname, '..', '..', 'action.yml'),
|
||||||
path.join(__dirname, '..', '..', 'README.md')
|
path.join(__dirname, '..', '..', 'README.md')
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,4 +5,4 @@ set -e
|
||||||
src/misc/licensed-download.sh
|
src/misc/licensed-download.sh
|
||||||
|
|
||||||
echo 'Running: licensed cached'
|
echo 'Running: licensed cached'
|
||||||
_temp/licensed-3.3.1/licensed status
|
_temp/licensed-3.6.0/licensed status
|
|
@ -2,23 +2,23 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ ! -f _temp/licensed-3.3.1.done ]; then
|
if [ ! -f _temp/licensed-3.6.0.done ]; then
|
||||||
echo 'Clearing temp'
|
echo 'Clearing temp'
|
||||||
rm -rf _temp/licensed-3.3.1 || true
|
rm -rf _temp/licensed-3.6.0 || true
|
||||||
|
|
||||||
echo 'Downloading licensed'
|
echo 'Downloading licensed'
|
||||||
mkdir -p _temp/licensed-3.3.1
|
mkdir -p _temp/licensed-3.6.0
|
||||||
pushd _temp/licensed-3.3.1
|
pushd _temp/licensed-3.6.0
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.3.1/licensed-3.3.1-darwin-x64.tar.gz
|
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.6.0/licensed-3.6.0-darwin-x64.tar.gz
|
||||||
else
|
else
|
||||||
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.3.1/licensed-3.3.1-linux-x64.tar.gz
|
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.6.0/licensed-3.6.0-linux-x64.tar.gz
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo 'Extracting licenesed'
|
echo 'Extracting licenesed'
|
||||||
tar -xzf licensed.tar.gz
|
tar -xzf licensed.tar.gz
|
||||||
popd
|
popd
|
||||||
touch _temp/licensed-3.3.1.done
|
touch _temp/licensed-3.6.0.done
|
||||||
else
|
else
|
||||||
echo 'Licensed already downloaded'
|
echo 'Licensed already downloaded'
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -5,4 +5,4 @@ set -e
|
||||||
src/misc/licensed-download.sh
|
src/misc/licensed-download.sh
|
||||||
|
|
||||||
echo 'Running: licensed cached'
|
echo 'Running: licensed cached'
|
||||||
_temp/licensed-3.3.1/licensed cache
|
_temp/licensed-3.6.0/licensed cache
|
23
src/octokit-provider.ts
Normal file
23
src/octokit-provider.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import * as github from '@actions/github'
|
||||||
|
import {Octokit} from '@octokit/rest'
|
||||||
|
import {getServerApiUrl} from './url-helper'
|
||||||
|
|
||||||
|
// Centralize all Octokit references by re-exporting
|
||||||
|
export {Octokit} from '@octokit/rest'
|
||||||
|
|
||||||
|
export type OctokitOptions = {
|
||||||
|
baseUrl?: string
|
||||||
|
userAgent?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getOctokit(authToken: string, opts: OctokitOptions) {
|
||||||
|
const options: Octokit.Options = {
|
||||||
|
baseUrl: getServerApiUrl(opts.baseUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts.userAgent) {
|
||||||
|
options.userAgent = opts.userAgent
|
||||||
|
}
|
||||||
|
|
||||||
|
return new github.GitHub(authToken, options)
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
import {URL} from 'url'
|
|
||||||
import {IGitCommandManager} from './git-command-manager'
|
import {IGitCommandManager} from './git-command-manager'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
|
import {getOctokit} from './octokit-provider'
|
||||||
|
import {isGhes} from './url-helper'
|
||||||
|
|
||||||
export const tagsRefSpec = '+refs/tags/*:refs/tags/*'
|
export const tagsRefSpec = '+refs/tags/*:refs/tags/*'
|
||||||
|
|
||||||
|
@ -183,11 +184,12 @@ export async function checkCommitInfo(
|
||||||
repositoryOwner: string,
|
repositoryOwner: string,
|
||||||
repositoryName: string,
|
repositoryName: string,
|
||||||
ref: string,
|
ref: string,
|
||||||
commit: string
|
commit: string,
|
||||||
|
baseUrl?: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// GHES?
|
// GHES?
|
||||||
if (isGhes()) {
|
if (isGhes(baseUrl)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +245,8 @@ export async function checkCommitInfo(
|
||||||
core.debug(
|
core.debug(
|
||||||
`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`
|
`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`
|
||||||
)
|
)
|
||||||
const octokit = new github.GitHub(token, {
|
const octokit = getOctokit(token, {
|
||||||
|
baseUrl: baseUrl,
|
||||||
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
|
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
|
||||||
'number'
|
'number'
|
||||||
)};run_id=${
|
)};run_id=${
|
||||||
|
@ -276,10 +279,3 @@ function select(obj: any, path: string): any {
|
||||||
const key = path.substr(0, i)
|
const key = path.substr(0, i)
|
||||||
return select(obj[key], path.substr(i + 1))
|
return select(obj[key], path.substr(i + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
function isGhes(): boolean {
|
|
||||||
const ghUrl = new URL(
|
|
||||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
||||||
)
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,58 +1,60 @@
|
||||||
import * as coreCommand from '@actions/core/lib/command'
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether the POST action is running
|
* Indicates whether the POST action is running
|
||||||
*/
|
*/
|
||||||
export const IsPost = !!process.env['STATE_isPost']
|
export const IsPost = !!core.getState('isPost')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The repository path for the POST action. The value is empty during the MAIN action.
|
* The repository path for the POST action. The value is empty during the MAIN action.
|
||||||
*/
|
*/
|
||||||
export const RepositoryPath =
|
export const RepositoryPath = core.getState('repositoryPath')
|
||||||
(process.env['STATE_repositoryPath'] as string) || ''
|
|
||||||
|
/**
|
||||||
|
* The set-safe-directory for the POST action. The value is set if input: 'safe-directory' is set during the MAIN action.
|
||||||
|
*/
|
||||||
|
export const PostSetSafeDirectory = core.getState('setSafeDirectory') === 'true'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SSH key path for the POST action. The value is empty during the MAIN action.
|
* The SSH key path for the POST action. The value is empty during the MAIN action.
|
||||||
*/
|
*/
|
||||||
export const SshKeyPath = (process.env['STATE_sshKeyPath'] as string) || ''
|
export const SshKeyPath = core.getState('sshKeyPath')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SSH known hosts path for the POST action. The value is empty during the MAIN action.
|
* The SSH known hosts path for the POST action. The value is empty during the MAIN action.
|
||||||
*/
|
*/
|
||||||
export const SshKnownHostsPath =
|
export const SshKnownHostsPath = core.getState('sshKnownHostsPath')
|
||||||
(process.env['STATE_sshKnownHostsPath'] as string) || ''
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the repository path so the POST action can retrieve the value.
|
* Save the repository path so the POST action can retrieve the value.
|
||||||
*/
|
*/
|
||||||
export function setRepositoryPath(repositoryPath: string) {
|
export function setRepositoryPath(repositoryPath: string) {
|
||||||
coreCommand.issueCommand(
|
core.saveState('repositoryPath', repositoryPath)
|
||||||
'save-state',
|
|
||||||
{name: 'repositoryPath'},
|
|
||||||
repositoryPath
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the SSH key path so the POST action can retrieve the value.
|
* Save the SSH key path so the POST action can retrieve the value.
|
||||||
*/
|
*/
|
||||||
export function setSshKeyPath(sshKeyPath: string) {
|
export function setSshKeyPath(sshKeyPath: string) {
|
||||||
coreCommand.issueCommand('save-state', {name: 'sshKeyPath'}, sshKeyPath)
|
core.saveState('sshKeyPath', sshKeyPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the SSH known hosts path so the POST action can retrieve the value.
|
* Save the SSH known hosts path so the POST action can retrieve the value.
|
||||||
*/
|
*/
|
||||||
export function setSshKnownHostsPath(sshKnownHostsPath: string) {
|
export function setSshKnownHostsPath(sshKnownHostsPath: string) {
|
||||||
coreCommand.issueCommand(
|
core.saveState('sshKnownHostsPath', sshKnownHostsPath)
|
||||||
'save-state',
|
}
|
||||||
{name: 'sshKnownHostsPath'},
|
|
||||||
sshKnownHostsPath
|
/**
|
||||||
)
|
* Save the sef-safe-directory input so the POST action can retrieve the value.
|
||||||
|
*/
|
||||||
|
export function setSafeDirectory() {
|
||||||
|
core.saveState('setSafeDirectory', 'true')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
|
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
|
||||||
// This is necessary since we don't have a separate entry point.
|
// This is necessary since we don't have a separate entry point.
|
||||||
if (!IsPost) {
|
if (!IsPost) {
|
||||||
coreCommand.issueCommand('save-state', {name: 'isPost'}, 'true')
|
core.saveState('isPost', 'true')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as assert from 'assert'
|
import * as assert from 'assert'
|
||||||
import {IGitSourceSettings} from './git-source-settings'
|
|
||||||
import {URL} from 'url'
|
import {URL} from 'url'
|
||||||
|
import {IGitSourceSettings} from './git-source-settings'
|
||||||
|
|
||||||
export function getFetchUrl(settings: IGitSourceSettings): string {
|
export function getFetchUrl(settings: IGitSourceSettings): string {
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
@ -8,7 +8,7 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
|
||||||
'settings.repositoryOwner must be defined'
|
'settings.repositoryOwner must be defined'
|
||||||
)
|
)
|
||||||
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
|
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
|
||||||
const serviceUrl = getServerUrl()
|
const serviceUrl = getServerUrl(settings.githubServerUrl)
|
||||||
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
|
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
|
||||||
const encodedName = encodeURIComponent(settings.repositoryName)
|
const encodedName = encodeURIComponent(settings.repositoryName)
|
||||||
if (settings.sshKey) {
|
if (settings.sshKey) {
|
||||||
|
@ -19,11 +19,27 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
|
||||||
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
|
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getServerUrl(): URL {
|
export function getServerUrl(url?: string): URL {
|
||||||
// todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
|
let urlValue =
|
||||||
return new URL(
|
url && url.trim().length > 0
|
||||||
process.env['GITHUB_SERVER_URL'] ||
|
? url
|
||||||
process.env['GITHUB_URL'] ||
|
: process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
'https://github.com'
|
return new URL(urlValue)
|
||||||
)
|
}
|
||||||
|
|
||||||
|
export function getServerApiUrl(url?: string): string {
|
||||||
|
let apiUrl = 'https://api.github.com'
|
||||||
|
|
||||||
|
if (isGhes(url)) {
|
||||||
|
const serverUrl = getServerUrl(url)
|
||||||
|
apiUrl = new URL(`${serverUrl.origin}/api/v3`).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isGhes(url?: string): boolean {
|
||||||
|
const ghUrl = getServerUrl(url)
|
||||||
|
|
||||||
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue