mirror of
				https://github.com/actions/checkout.git
				synced 2025-11-04 07:48:09 +08:00 
			
		
		
		
	Compare commits
	
		
			6 Commits
		
	
	
		
			users/eric
			...
			v2.1.0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					01aecccf73 | ||
| 
						 | 
					85b1f35505 | ||
| 
						 | 
					574281d34c | ||
| 
						 | 
					fbb30c60ab | ||
| 
						 | 
					58070a9fc3 | ||
| 
						 | 
					9a3a9ade82 | 
							
								
								
									
										27
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								README.md
									
									
									
									
									
								
							@@ -18,6 +18,7 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
 | 
				
			|||||||
  - Fetches only a single commit by default
 | 
					  - Fetches only a single commit by default
 | 
				
			||||||
- Script authenticated git commands
 | 
					- Script authenticated git commands
 | 
				
			||||||
  - Auth token persisted in the local git config
 | 
					  - Auth token persisted in the local git config
 | 
				
			||||||
 | 
					- Supports SSH
 | 
				
			||||||
- Creates a local branch
 | 
					- Creates a local branch
 | 
				
			||||||
  - No longer detached HEAD when checking out a branch
 | 
					  - No longer detached HEAD when checking out a branch
 | 
				
			||||||
- Improved layout
 | 
					- Improved layout
 | 
				
			||||||
@@ -26,7 +27,6 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
 | 
				
			|||||||
- Fallback to REST API download
 | 
					- 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 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
 | 
					  - When using a job container, the container's PATH is used
 | 
				
			||||||
- Removed input `submodules`
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous versions.
 | 
					Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous versions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -49,19 +49,19 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
 | 
				
			|||||||
    # with the local git config, which enables your scripts to run authenticated git
 | 
					    # with the local git config, which enables your scripts to run authenticated git
 | 
				
			||||||
    # commands. The post-job step removes the PAT.
 | 
					    # commands. The post-job step removes the PAT.
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # We recommend creating a service account with the least permissions necessary.
 | 
					    # We recommend using a service account with the least permissions necessary. Also
 | 
				
			||||||
    # Also when generating a new PAT, select the least scopes necessary.
 | 
					    # when generating a new PAT, select the least scopes necessary.
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
					    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # Default: ${{ github.token }}
 | 
					    # Default: ${{ github.token }}
 | 
				
			||||||
    token: ''
 | 
					    token: ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # SSH key used to fetch the repository. SSH key is configured with the local git
 | 
					    # SSH key used to fetch the repository. The SSH key is configured with the local
 | 
				
			||||||
    # config, which enables your scripts to run authenticated git commands. The
 | 
					    # git config, which enables your scripts to run authenticated git commands. The
 | 
				
			||||||
    # post-job step removes the SSH key.
 | 
					    # post-job step removes the SSH key.
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # We recommend creating a service account with the least permissions necessary.
 | 
					    # We recommend using a service account with the least permissions necessary.
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
					    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
				
			||||||
    ssh-key: ''
 | 
					    ssh-key: ''
 | 
				
			||||||
@@ -117,7 +117,6 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
 | 
				
			|||||||
- [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
 | 
					- [Checkout multiple repos (private)](#Checkout-multiple-repos-private)
 | 
				
			||||||
- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit)
 | 
					- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit)
 | 
				
			||||||
- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event)
 | 
					- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event)
 | 
				
			||||||
- [Checkout submodules](#Checkout-submodules)
 | 
					 | 
				
			||||||
- [Fetch all tags](#Fetch-all-tags)
 | 
					- [Fetch all tags](#Fetch-all-tags)
 | 
				
			||||||
- [Fetch all branches](#Fetch-all-branches)
 | 
					- [Fetch all branches](#Fetch-all-branches)
 | 
				
			||||||
- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches)
 | 
					- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches)
 | 
				
			||||||
@@ -208,20 +207,6 @@ jobs:
 | 
				
			|||||||
      - uses: actions/checkout@v2
 | 
					      - uses: actions/checkout@v2
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Checkout submodules
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```yaml
 | 
					 | 
				
			||||||
- uses: actions/checkout@v2
 | 
					 | 
				
			||||||
- name: Checkout submodules
 | 
					 | 
				
			||||||
  shell: bash
 | 
					 | 
				
			||||||
  run: |
 | 
					 | 
				
			||||||
    # If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
 | 
					 | 
				
			||||||
    # git config --global url."https://github.com/".insteadOf "git@github.com:"
 | 
					 | 
				
			||||||
    auth_header="$(git config --local --get http.https://github.com/.extraheader)"
 | 
					 | 
				
			||||||
    git submodule sync --recursive
 | 
					 | 
				
			||||||
    git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Fetch all tags
 | 
					## Fetch all tags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```yaml
 | 
					```yaml
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -320,6 +320,8 @@ describe('git-auth-helper tests', () => {
 | 
				
			|||||||
    ).toString()
 | 
					    ).toString()
 | 
				
			||||||
    expect(actualSshKeyContent).toBe(settings.sshKey + '\n')
 | 
					    expect(actualSshKeyContent).toBe(settings.sshKey + '\n')
 | 
				
			||||||
    if (!isWindows) {
 | 
					    if (!isWindows) {
 | 
				
			||||||
 | 
					      // Assert read/write for user, not group or others.
 | 
				
			||||||
 | 
					      // Otherwise SSH client will error.
 | 
				
			||||||
      expect((await fs.promises.stat(actualSshKeyPath)).mode & 0o777).toBe(
 | 
					      expect((await fs.promises.stat(actualSshKeyPath)).mode & 0o777).toBe(
 | 
				
			||||||
        0o600
 | 
					        0o600
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
@@ -437,14 +439,74 @@ describe('git-auth-helper tests', () => {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeyNotSet =
 | 
					  const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeyNotSet =
 | 
				
			||||||
    'configureSubmoduleAuth configures token when persist credentials true and SSH key not set'
 | 
					    'configureSubmoduleAuth configures submodules when persist credentials false and SSH key not set'
 | 
				
			||||||
  it(
 | 
					  it(
 | 
				
			||||||
    configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeyNotSet,
 | 
					    configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeyNotSet,
 | 
				
			||||||
    async () => {
 | 
					    async () => {
 | 
				
			||||||
      // Arrange
 | 
					      // Arrange
 | 
				
			||||||
      await setup(
 | 
					      await setup(
 | 
				
			||||||
        configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeyNotSet
 | 
					        configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeyNotSet
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      settings.persistCredentials = false
 | 
				
			||||||
 | 
					      settings.sshKey = ''
 | 
				
			||||||
 | 
					      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
				
			||||||
 | 
					      await authHelper.configureAuth()
 | 
				
			||||||
 | 
					      const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
 | 
				
			||||||
 | 
					      mockSubmoduleForeach.mockClear() // reset calls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Act
 | 
				
			||||||
 | 
					      await authHelper.configureSubmoduleAuth()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Assert
 | 
				
			||||||
 | 
					      expect(mockSubmoduleForeach).toBeCalledTimes(1)
 | 
				
			||||||
 | 
					      expect(mockSubmoduleForeach.mock.calls[0][0] as string).toMatch(
 | 
				
			||||||
 | 
					        /unset-all.*insteadOf/
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet =
 | 
				
			||||||
 | 
					    'configureSubmoduleAuth configures submodules when persist credentials false and SSH key set'
 | 
				
			||||||
 | 
					  it(
 | 
				
			||||||
 | 
					    configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet,
 | 
				
			||||||
 | 
					    async () => {
 | 
				
			||||||
 | 
					      if (!sshPath) {
 | 
				
			||||||
 | 
					        process.stdout.write(
 | 
				
			||||||
 | 
					          `Skipped test "${configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet}". Executable 'ssh' not found in the PATH.\n`
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Arrange
 | 
				
			||||||
 | 
					      await setup(
 | 
				
			||||||
 | 
					        configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      settings.persistCredentials = false
 | 
				
			||||||
 | 
					      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
				
			||||||
 | 
					      await authHelper.configureAuth()
 | 
				
			||||||
 | 
					      const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
 | 
				
			||||||
 | 
					      mockSubmoduleForeach.mockClear() // reset calls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Act
 | 
				
			||||||
 | 
					      await authHelper.configureSubmoduleAuth()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Assert
 | 
				
			||||||
 | 
					      expect(mockSubmoduleForeach).toHaveBeenCalledTimes(1)
 | 
				
			||||||
 | 
					      expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch(
 | 
				
			||||||
 | 
					        /unset-all.*insteadOf/
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeyNotSet =
 | 
				
			||||||
 | 
					    'configureSubmoduleAuth configures submodules when persist credentials true and SSH key not set'
 | 
				
			||||||
 | 
					  it(
 | 
				
			||||||
 | 
					    configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeyNotSet,
 | 
				
			||||||
 | 
					    async () => {
 | 
				
			||||||
 | 
					      // Arrange
 | 
				
			||||||
 | 
					      await setup(
 | 
				
			||||||
 | 
					        configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeyNotSet
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      settings.sshKey = ''
 | 
					      settings.sshKey = ''
 | 
				
			||||||
      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
					      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
				
			||||||
@@ -465,21 +527,21 @@ describe('git-auth-helper tests', () => {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet =
 | 
					  const configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet =
 | 
				
			||||||
    'configureSubmoduleAuth configures token when persist credentials true and SSH key set'
 | 
					    'configureSubmoduleAuth configures submodules when persist credentials true and SSH key set'
 | 
				
			||||||
  it(
 | 
					  it(
 | 
				
			||||||
    configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet,
 | 
					    configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet,
 | 
				
			||||||
    async () => {
 | 
					    async () => {
 | 
				
			||||||
      if (!sshPath) {
 | 
					      if (!sshPath) {
 | 
				
			||||||
        process.stdout.write(
 | 
					        process.stdout.write(
 | 
				
			||||||
          `Skipped test "${configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet}". Executable 'ssh' not found in the PATH.\n`
 | 
					          `Skipped test "${configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet}". Executable 'ssh' not found in the PATH.\n`
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Arrange
 | 
					      // Arrange
 | 
				
			||||||
      await setup(
 | 
					      await setup(
 | 
				
			||||||
        configureSubmoduleAuth_configuresTokenWhenPersistCredentialsTrueAndSshKeySet
 | 
					        configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
					      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
				
			||||||
      await authHelper.configureAuth()
 | 
					      await authHelper.configureAuth()
 | 
				
			||||||
@@ -490,96 +552,12 @@ describe('git-auth-helper tests', () => {
 | 
				
			|||||||
      await authHelper.configureSubmoduleAuth()
 | 
					      await authHelper.configureSubmoduleAuth()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Assert
 | 
					      // Assert
 | 
				
			||||||
      expect(mockSubmoduleForeach).toHaveBeenCalledTimes(2)
 | 
					      expect(mockSubmoduleForeach).toHaveBeenCalledTimes(3)
 | 
				
			||||||
      expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch(
 | 
					      expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch(
 | 
				
			||||||
        /unset-all.*insteadOf/
 | 
					        /unset-all.*insteadOf/
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/)
 | 
					      expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/)
 | 
				
			||||||
    }
 | 
					      expect(mockSubmoduleForeach.mock.calls[2][0]).toMatch(/core\.sshCommand/)
 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  const configureSubmoduleAuth_doesNotConfigureTokenWhenPersistCredentialsFalse =
 | 
					 | 
				
			||||||
    'configureSubmoduleAuth does not configure token when persist credentials false'
 | 
					 | 
				
			||||||
  it(
 | 
					 | 
				
			||||||
    configureSubmoduleAuth_doesNotConfigureTokenWhenPersistCredentialsFalse,
 | 
					 | 
				
			||||||
    async () => {
 | 
					 | 
				
			||||||
      // Arrange
 | 
					 | 
				
			||||||
      await setup(
 | 
					 | 
				
			||||||
        configureSubmoduleAuth_doesNotConfigureTokenWhenPersistCredentialsFalse
 | 
					 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
      settings.persistCredentials = false
 | 
					 | 
				
			||||||
      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
					 | 
				
			||||||
      await authHelper.configureAuth()
 | 
					 | 
				
			||||||
      const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
 | 
					 | 
				
			||||||
      mockSubmoduleForeach.mockClear() // reset calls
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Act
 | 
					 | 
				
			||||||
      await authHelper.configureSubmoduleAuth()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Assert
 | 
					 | 
				
			||||||
      expect(mockSubmoduleForeach).toBeCalledTimes(1)
 | 
					 | 
				
			||||||
      expect(mockSubmoduleForeach.mock.calls[0][0] as string).toMatch(
 | 
					 | 
				
			||||||
        /unset-all.*insteadOf/
 | 
					 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  const configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet =
 | 
					 | 
				
			||||||
    'configureSubmoduleAuth does not configure URL insteadOf when persist credentials true and SSH key set'
 | 
					 | 
				
			||||||
  it(
 | 
					 | 
				
			||||||
    configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet,
 | 
					 | 
				
			||||||
    async () => {
 | 
					 | 
				
			||||||
      if (!sshPath) {
 | 
					 | 
				
			||||||
        process.stdout.write(
 | 
					 | 
				
			||||||
          `Skipped test "${configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet}". Executable 'ssh' not found in the PATH.\n`
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        return
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Arrange
 | 
					 | 
				
			||||||
      await setup(
 | 
					 | 
				
			||||||
        configureSubmoduleAuth_doesNotConfigureUrlInsteadOfWhenPersistCredentialsTrueAndSshKeySet
 | 
					 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
					 | 
				
			||||||
      await authHelper.configureAuth()
 | 
					 | 
				
			||||||
      const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
 | 
					 | 
				
			||||||
      mockSubmoduleForeach.mockClear() // reset calls
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Act
 | 
					 | 
				
			||||||
      await authHelper.configureSubmoduleAuth()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Assert
 | 
					 | 
				
			||||||
      expect(mockSubmoduleForeach).toHaveBeenCalledTimes(2)
 | 
					 | 
				
			||||||
      expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch(
 | 
					 | 
				
			||||||
        /unset-all.*insteadOf/
 | 
					 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
      expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  const configureSubmoduleAuth_removesUrlInsteadOfWhenPersistCredentialsFalse =
 | 
					 | 
				
			||||||
    'configureSubmoduleAuth removes URL insteadOf when persist credentials false'
 | 
					 | 
				
			||||||
  it(
 | 
					 | 
				
			||||||
    configureSubmoduleAuth_removesUrlInsteadOfWhenPersistCredentialsFalse,
 | 
					 | 
				
			||||||
    async () => {
 | 
					 | 
				
			||||||
      // Arrange
 | 
					 | 
				
			||||||
      await setup(
 | 
					 | 
				
			||||||
        configureSubmoduleAuth_removesUrlInsteadOfWhenPersistCredentialsFalse
 | 
					 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
      settings.persistCredentials = false
 | 
					 | 
				
			||||||
      const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
					 | 
				
			||||||
      await authHelper.configureAuth()
 | 
					 | 
				
			||||||
      const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
 | 
					 | 
				
			||||||
      mockSubmoduleForeach.mockClear() // reset calls
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Act
 | 
					 | 
				
			||||||
      await authHelper.configureSubmoduleAuth()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Assert
 | 
					 | 
				
			||||||
      expect(mockSubmoduleForeach).toBeCalledTimes(1)
 | 
					 | 
				
			||||||
      expect(mockSubmoduleForeach.mock.calls[0][0] as string).toMatch(
 | 
					 | 
				
			||||||
        /unset-all.*insteadOf/
 | 
					 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,7 @@ inputs:
 | 
				
			|||||||
      commands. The post-job step removes the PAT.
 | 
					      commands. The post-job step removes the PAT.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      We recommend creating a service account with the least permissions necessary.
 | 
					      We recommend using a service account with the least permissions necessary.
 | 
				
			||||||
      Also when generating a new PAT, select the least scopes necessary.
 | 
					      Also when generating a new PAT, select the least scopes necessary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -24,12 +24,12 @@ inputs:
 | 
				
			|||||||
    default: ${{ github.token }}
 | 
					    default: ${{ github.token }}
 | 
				
			||||||
  ssh-key:
 | 
					  ssh-key:
 | 
				
			||||||
    description: >
 | 
					    description: >
 | 
				
			||||||
      SSH key used to fetch the repository. SSH key is configured with the local
 | 
					      SSH key used to fetch the repository. The SSH key is configured with the local
 | 
				
			||||||
      git config, which enables your scripts to run authenticated git commands.
 | 
					      git config, which enables your scripts to run authenticated git commands.
 | 
				
			||||||
      The post-job step removes the SSH key.
 | 
					      The post-job step removes the SSH key.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      We recommend creating a service account with the least permissions necessary.
 | 
					      We recommend using a service account with the least permissions necessary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      [Learn more about creating and using
 | 
					      [Learn more about creating and using
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,14 +29,26 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
 | 
				
			|||||||
    description: >
 | 
					    description: >
 | 
				
			||||||
      Personal access token (PAT) used to fetch the repository. The PAT is configured
 | 
					      Personal access token (PAT) used to fetch the repository. The PAT is configured
 | 
				
			||||||
      with the local git config, which enables your scripts to run authenticated git
 | 
					      with the local git config, which enables your scripts to run authenticated git
 | 
				
			||||||
      commands. The post-job step removes the PAT. [Learn more about creating and using
 | 
					      commands. The post-job step removes the PAT.
 | 
				
			||||||
      encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      We recommend using a service account with the least permissions necessary.
 | 
				
			||||||
 | 
					      Also when generating a new PAT, select the least scopes necessary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
				
			||||||
    default: ${{ github.token }}
 | 
					    default: ${{ github.token }}
 | 
				
			||||||
  ssh-key:
 | 
					  ssh-key:
 | 
				
			||||||
    description: >
 | 
					    description: >
 | 
				
			||||||
      SSH key used to fetch the repository. SSH key is configured with the local
 | 
					      SSH key used to fetch the repository. The SSH key is configured with the local
 | 
				
			||||||
      git config, which enables your scripts to run authenticated git commands.
 | 
					      git config, which enables your scripts to run authenticated git commands.
 | 
				
			||||||
      The post-job step removes the SSH key. [Learn more about creating and using
 | 
					      The post-job step removes the SSH key.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      We recommend using a service account with the least permissions necessary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      [Learn more about creating and using
 | 
				
			||||||
      encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
					      encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
 | 
				
			||||||
  ssh-known-hosts:
 | 
					  ssh-known-hosts:
 | 
				
			||||||
    description: >
 | 
					    description: >
 | 
				
			||||||
@@ -44,7 +56,10 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
 | 
				
			|||||||
      SSH keys for a host may be obtained using the utility `ssh-keyscan`. For example,
 | 
					      SSH keys for a host may be obtained using the utility `ssh-keyscan`. For example,
 | 
				
			||||||
      `ssh-keyscan github.com`. The public key for github.com is always implicitly added.
 | 
					      `ssh-keyscan github.com`. The public key for github.com is always implicitly added.
 | 
				
			||||||
  ssh-strict:
 | 
					  ssh-strict:
 | 
				
			||||||
    description: 'Whether to perform strict host key checking'
 | 
					    description: >
 | 
				
			||||||
 | 
					      Whether to perform strict host key checking. When true, adds the options `StrictHostKeyChecking=yes`
 | 
				
			||||||
 | 
					      and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to
 | 
				
			||||||
 | 
					      configure additional hosts.
 | 
				
			||||||
    default: true
 | 
					    default: true
 | 
				
			||||||
  persist-credentials:
 | 
					  persist-credentials:
 | 
				
			||||||
    description: 'Whether to configure the token or SSH key with the local git config'
 | 
					    description: 'Whether to configure the token or SSH key with the local git config'
 | 
				
			||||||
@@ -64,7 +79,11 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
 | 
				
			|||||||
    description: >
 | 
					    description: >
 | 
				
			||||||
      Whether to checkout submodules: `true` to checkout submodules or `recursive` to
 | 
					      Whether to checkout submodules: `true` to checkout submodules or `recursive` to
 | 
				
			||||||
      recursively checkout submodules.
 | 
					      recursively checkout submodules.
 | 
				
			||||||
    default: 'false'
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      When the `ssh-key` input is not provided, SSH URLs beginning with `git@github.com:` are
 | 
				
			||||||
 | 
					      converted to HTTPS.
 | 
				
			||||||
 | 
					    default: false
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Note:
 | 
					Note:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										118
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										118
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							@@ -1266,6 +1266,46 @@ const windowsRelease = release => {
 | 
				
			|||||||
module.exports = windowsRelease;
 | 
					module.exports = windowsRelease;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/***/ }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/***/ 81:
 | 
				
			||||||
 | 
					/***/ (function(__unusedmodule, exports, __webpack_require__) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var __importStar = (this && this.__importStar) || function (mod) {
 | 
				
			||||||
 | 
					    if (mod && mod.__esModule) return mod;
 | 
				
			||||||
 | 
					    var result = {};
 | 
				
			||||||
 | 
					    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
 | 
				
			||||||
 | 
					    result["default"] = mod;
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					const assert = __importStar(__webpack_require__(357));
 | 
				
			||||||
 | 
					const url_1 = __webpack_require__(835);
 | 
				
			||||||
 | 
					function getApiUrl() {
 | 
				
			||||||
 | 
					    return process.env['GITHUB_API_URL'] || 'https://api.github.com';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.getApiUrl = getApiUrl;
 | 
				
			||||||
 | 
					function getFetchUrl(settings) {
 | 
				
			||||||
 | 
					    assert.ok(settings.repositoryOwner, 'settings.repositoryOwner must be defined');
 | 
				
			||||||
 | 
					    assert.ok(settings.repositoryName, 'settings.repositoryName must be defined');
 | 
				
			||||||
 | 
					    const serviceUrl = getServerUrl();
 | 
				
			||||||
 | 
					    const encodedOwner = encodeURIComponent(settings.repositoryOwner);
 | 
				
			||||||
 | 
					    const encodedName = encodeURIComponent(settings.repositoryName);
 | 
				
			||||||
 | 
					    if (settings.sshKey) {
 | 
				
			||||||
 | 
					        return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // "origin" is SCHEME://HOSTNAME[:PORT]
 | 
				
			||||||
 | 
					    return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.getFetchUrl = getFetchUrl;
 | 
				
			||||||
 | 
					function getServerUrl() {
 | 
				
			||||||
 | 
					    return new url_1.URL(process.env['GITHUB_URL'] || 'https://github.com');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.getServerUrl = getServerUrl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/***/ }),
 | 
					/***/ }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/***/ 87:
 | 
					/***/ 87:
 | 
				
			||||||
@@ -5109,9 +5149,9 @@ const os = __importStar(__webpack_require__(87));
 | 
				
			|||||||
const path = __importStar(__webpack_require__(622));
 | 
					const path = __importStar(__webpack_require__(622));
 | 
				
			||||||
const regexpHelper = __importStar(__webpack_require__(528));
 | 
					const regexpHelper = __importStar(__webpack_require__(528));
 | 
				
			||||||
const stateHelper = __importStar(__webpack_require__(153));
 | 
					const stateHelper = __importStar(__webpack_require__(153));
 | 
				
			||||||
 | 
					const urlHelper = __importStar(__webpack_require__(81));
 | 
				
			||||||
const v4_1 = __importDefault(__webpack_require__(826));
 | 
					const v4_1 = __importDefault(__webpack_require__(826));
 | 
				
			||||||
const IS_WINDOWS = process.platform === 'win32';
 | 
					const IS_WINDOWS = process.platform === 'win32';
 | 
				
			||||||
const HOSTNAME = 'github.com';
 | 
					 | 
				
			||||||
const SSH_COMMAND_KEY = 'core.sshCommand';
 | 
					const SSH_COMMAND_KEY = 'core.sshCommand';
 | 
				
			||||||
function createAuthHelper(git, settings) {
 | 
					function createAuthHelper(git, settings) {
 | 
				
			||||||
    return new GitAuthHelper(git, settings);
 | 
					    return new GitAuthHelper(git, settings);
 | 
				
			||||||
@@ -5119,19 +5159,22 @@ function createAuthHelper(git, settings) {
 | 
				
			|||||||
exports.createAuthHelper = createAuthHelper;
 | 
					exports.createAuthHelper = createAuthHelper;
 | 
				
			||||||
class GitAuthHelper {
 | 
					class GitAuthHelper {
 | 
				
			||||||
    constructor(gitCommandManager, gitSourceSettings) {
 | 
					    constructor(gitCommandManager, gitSourceSettings) {
 | 
				
			||||||
        this.tokenConfigKey = `http.https://${HOSTNAME}/.extraheader`;
 | 
					        this.sshCommand = '';
 | 
				
			||||||
        this.insteadOfKey = `url.https://${HOSTNAME}/.insteadOf`;
 | 
					 | 
				
			||||||
        this.insteadOfValue = `git@${HOSTNAME}:`;
 | 
					 | 
				
			||||||
        this.sshKeyPath = '';
 | 
					        this.sshKeyPath = '';
 | 
				
			||||||
        this.sshKnownHostsPath = '';
 | 
					        this.sshKnownHostsPath = '';
 | 
				
			||||||
        this.temporaryHomePath = '';
 | 
					        this.temporaryHomePath = '';
 | 
				
			||||||
        this.git = gitCommandManager;
 | 
					        this.git = gitCommandManager;
 | 
				
			||||||
        this.settings = gitSourceSettings || {};
 | 
					        this.settings = gitSourceSettings || {};
 | 
				
			||||||
        // Token auth header
 | 
					        // Token auth header
 | 
				
			||||||
 | 
					        const serverUrl = urlHelper.getServerUrl();
 | 
				
			||||||
 | 
					        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);
 | 
				
			||||||
        this.tokenPlaceholderConfigValue = `AUTHORIZATION: basic ***`;
 | 
					        this.tokenPlaceholderConfigValue = `AUTHORIZATION: basic ***`;
 | 
				
			||||||
        this.tokenConfigValue = `AUTHORIZATION: basic ${basicCredential}`;
 | 
					        this.tokenConfigValue = `AUTHORIZATION: basic ${basicCredential}`;
 | 
				
			||||||
 | 
					        // Instead of SSH URL
 | 
				
			||||||
 | 
					        this.insteadOfKey = `url.${serverUrl.origin}/.insteadOf`; // "origin" is SCHEME://HOSTNAME[:PORT]
 | 
				
			||||||
 | 
					        this.insteadOfValue = `git@${serverUrl.hostname}:`;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    configureAuth() {
 | 
					    configureAuth() {
 | 
				
			||||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
					        return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
@@ -5205,8 +5248,12 @@ class GitAuthHelper {
 | 
				
			|||||||
                    core.debug(`Replacing token placeholder in '${configPath}'`);
 | 
					                    core.debug(`Replacing token placeholder in '${configPath}'`);
 | 
				
			||||||
                    this.replaceTokenPlaceholder(configPath);
 | 
					                    this.replaceTokenPlaceholder(configPath);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                if (this.settings.sshKey) {
 | 
				
			||||||
 | 
					                    // Configure core.sshCommand
 | 
				
			||||||
 | 
					                    yield this.git.submoduleForeach(`git config --local '${SSH_COMMAND_KEY}' '${this.sshCommand}'`, this.settings.nestedSubmodules);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
                    // Configure HTTPS instead of SSH
 | 
					                    // Configure HTTPS instead of SSH
 | 
				
			||||||
                if (!this.settings.sshKey) {
 | 
					 | 
				
			||||||
                    yield this.git.submoduleForeach(`git config --local '${this.insteadOfKey}' '${this.insteadOfValue}'`, this.settings.nestedSubmodules);
 | 
					                    yield this.git.submoduleForeach(`git config --local '${this.insteadOfKey}' '${this.insteadOfValue}'`, this.settings.nestedSubmodules);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -5220,7 +5267,7 @@ class GitAuthHelper {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    removeGlobalAuth() {
 | 
					    removeGlobalAuth() {
 | 
				
			||||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
					        return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
            core.info(`Unsetting HOME override`);
 | 
					            core.debug(`Unsetting HOME override`);
 | 
				
			||||||
            this.git.removeEnvironmentVariable('HOME');
 | 
					            this.git.removeEnvironmentVariable('HOME');
 | 
				
			||||||
            yield io.rmRF(this.temporaryHomePath);
 | 
					            yield io.rmRF(this.temporaryHomePath);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
@@ -5268,16 +5315,16 @@ class GitAuthHelper {
 | 
				
			|||||||
            yield fs.promises.writeFile(this.sshKnownHostsPath, knownHosts);
 | 
					            yield fs.promises.writeFile(this.sshKnownHostsPath, knownHosts);
 | 
				
			||||||
            // Configure GIT_SSH_COMMAND
 | 
					            // Configure GIT_SSH_COMMAND
 | 
				
			||||||
            const sshPath = yield io.which('ssh', true);
 | 
					            const sshPath = yield io.which('ssh', true);
 | 
				
			||||||
            let sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename(this.sshKeyPath)}"`;
 | 
					            this.sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename(this.sshKeyPath)}"`;
 | 
				
			||||||
            if (this.settings.sshStrict) {
 | 
					            if (this.settings.sshStrict) {
 | 
				
			||||||
                sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no';
 | 
					                this.sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename(this.sshKnownHostsPath)}"`;
 | 
					            this.sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename(this.sshKnownHostsPath)}"`;
 | 
				
			||||||
            core.info(`Temporarily overriding GIT_SSH_COMMAND=${sshCommand}`);
 | 
					            core.info(`Temporarily overriding GIT_SSH_COMMAND=${this.sshCommand}`);
 | 
				
			||||||
            this.git.setEnvironmentVariable('GIT_SSH_COMMAND', sshCommand);
 | 
					            this.git.setEnvironmentVariable('GIT_SSH_COMMAND', this.sshCommand);
 | 
				
			||||||
            // Configure core.sshCommand
 | 
					            // Configure core.sshCommand
 | 
				
			||||||
            if (this.settings.persistCredentials) {
 | 
					            if (this.settings.persistCredentials) {
 | 
				
			||||||
                yield this.git.config(SSH_COMMAND_KEY, sshCommand);
 | 
					                yield this.git.config(SSH_COMMAND_KEY, this.sshCommand);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -5792,14 +5839,12 @@ const io = __importStar(__webpack_require__(1));
 | 
				
			|||||||
const path = __importStar(__webpack_require__(622));
 | 
					const path = __importStar(__webpack_require__(622));
 | 
				
			||||||
const refHelper = __importStar(__webpack_require__(227));
 | 
					const refHelper = __importStar(__webpack_require__(227));
 | 
				
			||||||
const stateHelper = __importStar(__webpack_require__(153));
 | 
					const stateHelper = __importStar(__webpack_require__(153));
 | 
				
			||||||
const hostname = 'github.com';
 | 
					const urlHelper = __importStar(__webpack_require__(81));
 | 
				
			||||||
function getSource(settings) {
 | 
					function getSource(settings) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        // Repository URL
 | 
					        // Repository URL
 | 
				
			||||||
        core.info(`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`);
 | 
					        core.info(`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`);
 | 
				
			||||||
        const repositoryUrl = settings.sshKey
 | 
					        const repositoryUrl = urlHelper.getFetchUrl(settings);
 | 
				
			||||||
            ? `git@${hostname}:${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}.git`
 | 
					 | 
				
			||||||
            : `https://${hostname}/${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}`;
 | 
					 | 
				
			||||||
        // Remove conflicting file path
 | 
					        // Remove conflicting file path
 | 
				
			||||||
        if (fsHelper.fileExistsSync(settings.repositoryPath)) {
 | 
					        if (fsHelper.fileExistsSync(settings.repositoryPath)) {
 | 
				
			||||||
            yield io.rmRF(settings.repositoryPath);
 | 
					            yield io.rmRF(settings.repositoryPath);
 | 
				
			||||||
@@ -5811,7 +5856,9 @@ function getSource(settings) {
 | 
				
			|||||||
            yield io.mkdirP(settings.repositoryPath);
 | 
					            yield io.mkdirP(settings.repositoryPath);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Git command manager
 | 
					        // Git command manager
 | 
				
			||||||
 | 
					        core.startGroup('Getting Git version info');
 | 
				
			||||||
        const git = yield getGitCommandManager(settings);
 | 
					        const git = yield getGitCommandManager(settings);
 | 
				
			||||||
 | 
					        core.endGroup();
 | 
				
			||||||
        // Prepare existing directory, otherwise recreate
 | 
					        // Prepare existing directory, otherwise recreate
 | 
				
			||||||
        if (isExisting) {
 | 
					        if (isExisting) {
 | 
				
			||||||
            yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean);
 | 
					            yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean);
 | 
				
			||||||
@@ -5820,6 +5867,12 @@ function getSource(settings) {
 | 
				
			|||||||
            // Downloading using REST API
 | 
					            // Downloading using REST API
 | 
				
			||||||
            core.info(`The repository will be downloaded using the GitHub 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`);
 | 
					            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);
 | 
					            yield githubApiHelper.downloadRepository(settings.authToken, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -5827,46 +5880,66 @@ function getSource(settings) {
 | 
				
			|||||||
        stateHelper.setRepositoryPath(settings.repositoryPath);
 | 
					        stateHelper.setRepositoryPath(settings.repositoryPath);
 | 
				
			||||||
        // Initialize the repository
 | 
					        // Initialize the repository
 | 
				
			||||||
        if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
 | 
					        if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
 | 
				
			||||||
 | 
					            core.startGroup('Initializing the repository');
 | 
				
			||||||
            yield git.init();
 | 
					            yield git.init();
 | 
				
			||||||
            yield git.remoteAdd('origin', repositoryUrl);
 | 
					            yield git.remoteAdd('origin', repositoryUrl);
 | 
				
			||||||
 | 
					            core.endGroup();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Disable automatic garbage collection
 | 
					        // Disable automatic garbage collection
 | 
				
			||||||
 | 
					        core.startGroup('Disabling automatic garbage collection');
 | 
				
			||||||
        if (!(yield git.tryDisableAutomaticGarbageCollection())) {
 | 
					        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.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);
 | 
					        const authHelper = gitAuthHelper.createAuthHelper(git, settings);
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            // Configure auth
 | 
					            // Configure auth
 | 
				
			||||||
 | 
					            core.startGroup('Setting up auth');
 | 
				
			||||||
            yield authHelper.configureAuth();
 | 
					            yield authHelper.configureAuth();
 | 
				
			||||||
 | 
					            core.endGroup();
 | 
				
			||||||
            // LFS install
 | 
					            // LFS install
 | 
				
			||||||
            if (settings.lfs) {
 | 
					            if (settings.lfs) {
 | 
				
			||||||
                yield git.lfsInstall();
 | 
					                yield git.lfsInstall();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // Fetch
 | 
					            // Fetch
 | 
				
			||||||
 | 
					            core.startGroup('Fetching the repository');
 | 
				
			||||||
            const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
 | 
					            const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
 | 
				
			||||||
            yield git.fetch(settings.fetchDepth, refSpec);
 | 
					            yield git.fetch(settings.fetchDepth, refSpec);
 | 
				
			||||||
 | 
					            core.endGroup();
 | 
				
			||||||
            // Checkout info
 | 
					            // Checkout info
 | 
				
			||||||
 | 
					            core.startGroup('Determining the checkout info');
 | 
				
			||||||
            const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
 | 
					            const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
 | 
				
			||||||
 | 
					            core.endGroup();
 | 
				
			||||||
            // LFS fetch
 | 
					            // LFS fetch
 | 
				
			||||||
            // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
 | 
					            // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
 | 
				
			||||||
            // Explicit lfs fetch will fetch lfs objects in parallel.
 | 
					            // Explicit lfs fetch will fetch lfs objects in parallel.
 | 
				
			||||||
            if (settings.lfs) {
 | 
					            if (settings.lfs) {
 | 
				
			||||||
 | 
					                core.startGroup('Fetching LFS objects');
 | 
				
			||||||
                yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
 | 
					                yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
 | 
				
			||||||
 | 
					                core.endGroup();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // Checkout
 | 
					            // Checkout
 | 
				
			||||||
 | 
					            core.startGroup('Checking out the ref');
 | 
				
			||||||
            yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
 | 
					            yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
 | 
				
			||||||
 | 
					            core.endGroup();
 | 
				
			||||||
            // Submodules
 | 
					            // Submodules
 | 
				
			||||||
            if (settings.submodules) {
 | 
					            if (settings.submodules) {
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    // Temporarily override global config
 | 
					                    // Temporarily override global config
 | 
				
			||||||
 | 
					                    core.startGroup('Setting up auth for fetching submodules');
 | 
				
			||||||
                    yield authHelper.configureGlobalAuth();
 | 
					                    yield authHelper.configureGlobalAuth();
 | 
				
			||||||
 | 
					                    core.endGroup();
 | 
				
			||||||
                    // Checkout submodules
 | 
					                    // Checkout submodules
 | 
				
			||||||
 | 
					                    core.startGroup('Fetching submodules');
 | 
				
			||||||
                    yield git.submoduleSync(settings.nestedSubmodules);
 | 
					                    yield git.submoduleSync(settings.nestedSubmodules);
 | 
				
			||||||
                    yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
 | 
					                    yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
 | 
				
			||||||
                    yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
 | 
					                    yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
 | 
				
			||||||
 | 
					                    core.endGroup();
 | 
				
			||||||
                    // Persist credentials
 | 
					                    // Persist credentials
 | 
				
			||||||
                    if (settings.persistCredentials) {
 | 
					                    if (settings.persistCredentials) {
 | 
				
			||||||
 | 
					                        core.startGroup('Persisting credentials for submodules');
 | 
				
			||||||
                        yield authHelper.configureSubmoduleAuth();
 | 
					                        yield authHelper.configureSubmoduleAuth();
 | 
				
			||||||
 | 
					                        core.endGroup();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                finally {
 | 
					                finally {
 | 
				
			||||||
@@ -5880,7 +5953,9 @@ function getSource(settings) {
 | 
				
			|||||||
        finally {
 | 
					        finally {
 | 
				
			||||||
            // Remove auth
 | 
					            // Remove auth
 | 
				
			||||||
            if (!settings.persistCredentials) {
 | 
					            if (!settings.persistCredentials) {
 | 
				
			||||||
 | 
					                core.startGroup('Removing auth');
 | 
				
			||||||
                yield authHelper.removeAuth();
 | 
					                yield authHelper.removeAuth();
 | 
				
			||||||
 | 
					                core.endGroup();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@@ -7180,6 +7255,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
 | 
				
			|||||||
    return result;
 | 
					    return result;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
Object.defineProperty(exports, "__esModule", { value: true });
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					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 fsHelper = __importStar(__webpack_require__(618));
 | 
					const fsHelper = __importStar(__webpack_require__(618));
 | 
				
			||||||
@@ -7187,6 +7263,9 @@ const io = __importStar(__webpack_require__(1));
 | 
				
			|||||||
const path = __importStar(__webpack_require__(622));
 | 
					const path = __importStar(__webpack_require__(622));
 | 
				
			||||||
function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
 | 
					function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
 | 
					        assert.ok(repositoryPath, 'Expected repositoryPath to be defined');
 | 
				
			||||||
 | 
					        assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined');
 | 
				
			||||||
 | 
					        // Indicates whether to delete the directory contents
 | 
				
			||||||
        let remove = false;
 | 
					        let remove = false;
 | 
				
			||||||
        // Check whether using git or REST API
 | 
					        // Check whether using git or REST API
 | 
				
			||||||
        if (!git) {
 | 
					        if (!git) {
 | 
				
			||||||
@@ -7212,6 +7291,7 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
 | 
					                core.startGroup('Removing previously created refs, to avoid conflicts');
 | 
				
			||||||
                // Checkout detached HEAD
 | 
					                // Checkout detached HEAD
 | 
				
			||||||
                if (!(yield git.isDetached())) {
 | 
					                if (!(yield git.isDetached())) {
 | 
				
			||||||
                    yield git.checkoutDetach();
 | 
					                    yield git.checkoutDetach();
 | 
				
			||||||
@@ -7226,8 +7306,10 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
 | 
				
			|||||||
                for (const branch of branches) {
 | 
					                for (const branch of branches) {
 | 
				
			||||||
                    yield git.branchDelete(true, branch);
 | 
					                    yield git.branchDelete(true, branch);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                core.endGroup();
 | 
				
			||||||
                // Clean
 | 
					                // Clean
 | 
				
			||||||
                if (clean) {
 | 
					                if (clean) {
 | 
				
			||||||
 | 
					                    core.startGroup('Cleaning the repository');
 | 
				
			||||||
                    if (!(yield git.tryClean())) {
 | 
					                    if (!(yield git.tryClean())) {
 | 
				
			||||||
                        core.debug(`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`);
 | 
					                        core.debug(`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`);
 | 
				
			||||||
                        remove = true;
 | 
					                        remove = true;
 | 
				
			||||||
@@ -7235,6 +7317,7 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
 | 
				
			|||||||
                    else if (!(yield git.tryReset())) {
 | 
					                    else if (!(yield git.tryReset())) {
 | 
				
			||||||
                        remove = true;
 | 
					                        remove = true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    core.endGroup();
 | 
				
			||||||
                    if (remove) {
 | 
					                    if (remove) {
 | 
				
			||||||
                        core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`);
 | 
					                        core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@@ -9148,6 +9231,7 @@ 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 urlHelper = __importStar(__webpack_require__(81));
 | 
				
			||||||
const v4_1 = __importDefault(__webpack_require__(826));
 | 
					const v4_1 = __importDefault(__webpack_require__(826));
 | 
				
			||||||
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) {
 | 
				
			||||||
@@ -9198,7 +9282,7 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath)
 | 
				
			|||||||
exports.downloadRepository = downloadRepository;
 | 
					exports.downloadRepository = downloadRepository;
 | 
				
			||||||
function downloadArchive(authToken, owner, repo, ref, commit) {
 | 
					function downloadArchive(authToken, owner, repo, ref, commit) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        const octokit = new github.GitHub(authToken);
 | 
					        const octokit = new github.GitHub(authToken, { baseUrl: urlHelper.getApiUrl() });
 | 
				
			||||||
        const params = {
 | 
					        const params = {
 | 
				
			||||||
            owner: owner,
 | 
					            owner: owner,
 | 
				
			||||||
            repo: repo,
 | 
					            repo: repo,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,12 +7,12 @@ import * as os from 'os'
 | 
				
			|||||||
import * as path from 'path'
 | 
					import * as path from 'path'
 | 
				
			||||||
import * as regexpHelper from './regexp-helper'
 | 
					import * as regexpHelper from './regexp-helper'
 | 
				
			||||||
import * as stateHelper from './state-helper'
 | 
					import * as stateHelper from './state-helper'
 | 
				
			||||||
 | 
					import * as urlHelper from './url-helper'
 | 
				
			||||||
import {default as uuid} from 'uuid/v4'
 | 
					import {default as uuid} from 'uuid/v4'
 | 
				
			||||||
import {IGitCommandManager} from './git-command-manager'
 | 
					import {IGitCommandManager} from './git-command-manager'
 | 
				
			||||||
import {IGitSourceSettings} from './git-source-settings'
 | 
					import {IGitSourceSettings} from './git-source-settings'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const IS_WINDOWS = process.platform === 'win32'
 | 
					const IS_WINDOWS = process.platform === 'win32'
 | 
				
			||||||
const HOSTNAME = 'github.com'
 | 
					 | 
				
			||||||
const SSH_COMMAND_KEY = 'core.sshCommand'
 | 
					const SSH_COMMAND_KEY = 'core.sshCommand'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IGitAuthHelper {
 | 
					export interface IGitAuthHelper {
 | 
				
			||||||
@@ -33,14 +33,15 @@ export function createAuthHelper(
 | 
				
			|||||||
class GitAuthHelper {
 | 
					class GitAuthHelper {
 | 
				
			||||||
  private readonly git: IGitCommandManager
 | 
					  private readonly git: IGitCommandManager
 | 
				
			||||||
  private readonly settings: IGitSourceSettings
 | 
					  private readonly settings: IGitSourceSettings
 | 
				
			||||||
  private readonly tokenConfigKey: string = `http.https://${HOSTNAME}/.extraheader`
 | 
					  private readonly tokenConfigKey: string
 | 
				
			||||||
 | 
					  private readonly tokenConfigValue: string
 | 
				
			||||||
  private readonly tokenPlaceholderConfigValue: string
 | 
					  private readonly tokenPlaceholderConfigValue: string
 | 
				
			||||||
  private readonly insteadOfKey: string = `url.https://${HOSTNAME}/.insteadOf`
 | 
					  private readonly insteadOfKey: string
 | 
				
			||||||
  private readonly insteadOfValue: string = `git@${HOSTNAME}:`
 | 
					  private readonly insteadOfValue: string
 | 
				
			||||||
 | 
					  private sshCommand = ''
 | 
				
			||||||
  private sshKeyPath = ''
 | 
					  private sshKeyPath = ''
 | 
				
			||||||
  private sshKnownHostsPath = ''
 | 
					  private sshKnownHostsPath = ''
 | 
				
			||||||
  private temporaryHomePath = ''
 | 
					  private temporaryHomePath = ''
 | 
				
			||||||
  private tokenConfigValue: string
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
    gitCommandManager: IGitCommandManager,
 | 
					    gitCommandManager: IGitCommandManager,
 | 
				
			||||||
@@ -50,6 +51,8 @@ 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()
 | 
				
			||||||
 | 
					    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}`,
 | 
				
			||||||
      'utf8'
 | 
					      'utf8'
 | 
				
			||||||
@@ -57,6 +60,10 @@ class GitAuthHelper {
 | 
				
			|||||||
    core.setSecret(basicCredential)
 | 
					    core.setSecret(basicCredential)
 | 
				
			||||||
    this.tokenPlaceholderConfigValue = `AUTHORIZATION: basic ***`
 | 
					    this.tokenPlaceholderConfigValue = `AUTHORIZATION: basic ***`
 | 
				
			||||||
    this.tokenConfigValue = `AUTHORIZATION: basic ${basicCredential}`
 | 
					    this.tokenConfigValue = `AUTHORIZATION: basic ${basicCredential}`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Instead of SSH URL
 | 
				
			||||||
 | 
					    this.insteadOfKey = `url.${serverUrl.origin}/.insteadOf` // "origin" is SCHEME://HOSTNAME[:PORT]
 | 
				
			||||||
 | 
					    this.insteadOfValue = `git@${serverUrl.hostname}:`
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async configureAuth(): Promise<void> {
 | 
					  async configureAuth(): Promise<void> {
 | 
				
			||||||
@@ -144,8 +151,14 @@ class GitAuthHelper {
 | 
				
			|||||||
        this.replaceTokenPlaceholder(configPath)
 | 
					        this.replaceTokenPlaceholder(configPath)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (this.settings.sshKey) {
 | 
				
			||||||
 | 
					        // Configure core.sshCommand
 | 
				
			||||||
 | 
					        await this.git.submoduleForeach(
 | 
				
			||||||
 | 
					          `git config --local '${SSH_COMMAND_KEY}' '${this.sshCommand}'`,
 | 
				
			||||||
 | 
					          this.settings.nestedSubmodules
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
        // Configure HTTPS instead of SSH
 | 
					        // Configure HTTPS instead of SSH
 | 
				
			||||||
      if (!this.settings.sshKey) {
 | 
					 | 
				
			||||||
        await this.git.submoduleForeach(
 | 
					        await this.git.submoduleForeach(
 | 
				
			||||||
          `git config --local '${this.insteadOfKey}' '${this.insteadOfValue}'`,
 | 
					          `git config --local '${this.insteadOfKey}' '${this.insteadOfValue}'`,
 | 
				
			||||||
          this.settings.nestedSubmodules
 | 
					          this.settings.nestedSubmodules
 | 
				
			||||||
@@ -160,7 +173,7 @@ class GitAuthHelper {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async removeGlobalAuth(): Promise<void> {
 | 
					  async removeGlobalAuth(): Promise<void> {
 | 
				
			||||||
    core.info(`Unsetting HOME override`)
 | 
					    core.debug(`Unsetting HOME override`)
 | 
				
			||||||
    this.git.removeEnvironmentVariable('HOME')
 | 
					    this.git.removeEnvironmentVariable('HOME')
 | 
				
			||||||
    await io.rmRF(this.temporaryHomePath)
 | 
					    await io.rmRF(this.temporaryHomePath)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -218,21 +231,21 @@ class GitAuthHelper {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Configure GIT_SSH_COMMAND
 | 
					    // Configure GIT_SSH_COMMAND
 | 
				
			||||||
    const sshPath = await io.which('ssh', true)
 | 
					    const sshPath = await io.which('ssh', true)
 | 
				
			||||||
    let sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename(
 | 
					    this.sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename(
 | 
				
			||||||
      this.sshKeyPath
 | 
					      this.sshKeyPath
 | 
				
			||||||
    )}"`
 | 
					    )}"`
 | 
				
			||||||
    if (this.settings.sshStrict) {
 | 
					    if (this.settings.sshStrict) {
 | 
				
			||||||
      sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no'
 | 
					      this.sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename(
 | 
					    this.sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename(
 | 
				
			||||||
      this.sshKnownHostsPath
 | 
					      this.sshKnownHostsPath
 | 
				
			||||||
    )}"`
 | 
					    )}"`
 | 
				
			||||||
    core.info(`Temporarily overriding GIT_SSH_COMMAND=${sshCommand}`)
 | 
					    core.info(`Temporarily overriding GIT_SSH_COMMAND=${this.sshCommand}`)
 | 
				
			||||||
    this.git.setEnvironmentVariable('GIT_SSH_COMMAND', sshCommand)
 | 
					    this.git.setEnvironmentVariable('GIT_SSH_COMMAND', this.sshCommand)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Configure core.sshCommand
 | 
					    // Configure core.sshCommand
 | 
				
			||||||
    if (this.settings.persistCredentials) {
 | 
					    if (this.settings.persistCredentials) {
 | 
				
			||||||
      await this.git.config(SSH_COMMAND_KEY, sshCommand)
 | 
					      await this.git.config(SSH_COMMAND_KEY, this.sshCommand)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,11 @@
 | 
				
			|||||||
 | 
					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 fsHelper from './fs-helper'
 | 
					import * as fsHelper from './fs-helper'
 | 
				
			||||||
import * as io from '@actions/io'
 | 
					import * as io from '@actions/io'
 | 
				
			||||||
import * as path from 'path'
 | 
					import * as path from 'path'
 | 
				
			||||||
import {IGitCommandManager} from './git-command-manager'
 | 
					import {IGitCommandManager} from './git-command-manager'
 | 
				
			||||||
 | 
					import {IGitSourceSettings} from './git-source-settings'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function prepareExistingDirectory(
 | 
					export async function prepareExistingDirectory(
 | 
				
			||||||
  git: IGitCommandManager | undefined,
 | 
					  git: IGitCommandManager | undefined,
 | 
				
			||||||
@@ -11,6 +13,10 @@ export async function prepareExistingDirectory(
 | 
				
			|||||||
  repositoryUrl: string,
 | 
					  repositoryUrl: string,
 | 
				
			||||||
  clean: boolean
 | 
					  clean: boolean
 | 
				
			||||||
): Promise<void> {
 | 
					): Promise<void> {
 | 
				
			||||||
 | 
					  assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
 | 
				
			||||||
 | 
					  assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Indicates whether to delete the directory contents
 | 
				
			||||||
  let remove = false
 | 
					  let remove = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Check whether using git or REST API
 | 
					  // Check whether using git or REST API
 | 
				
			||||||
@@ -38,6 +44,7 @@ export async function prepareExistingDirectory(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
 | 
					      core.startGroup('Removing previously created refs, to avoid conflicts')
 | 
				
			||||||
      // Checkout detached HEAD
 | 
					      // Checkout detached HEAD
 | 
				
			||||||
      if (!(await git.isDetached())) {
 | 
					      if (!(await git.isDetached())) {
 | 
				
			||||||
        await git.checkoutDetach()
 | 
					        await git.checkoutDetach()
 | 
				
			||||||
@@ -54,9 +61,11 @@ export async function prepareExistingDirectory(
 | 
				
			|||||||
      for (const branch of branches) {
 | 
					      for (const branch of branches) {
 | 
				
			||||||
        await git.branchDelete(true, branch)
 | 
					        await git.branchDelete(true, branch)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Clean
 | 
					      // Clean
 | 
				
			||||||
      if (clean) {
 | 
					      if (clean) {
 | 
				
			||||||
 | 
					        core.startGroup('Cleaning the repository')
 | 
				
			||||||
        if (!(await git.tryClean())) {
 | 
					        if (!(await git.tryClean())) {
 | 
				
			||||||
          core.debug(
 | 
					          core.debug(
 | 
				
			||||||
            `The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
 | 
					            `The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
 | 
				
			||||||
@@ -65,6 +74,7 @@ export async function prepareExistingDirectory(
 | 
				
			|||||||
        } else if (!(await git.tryReset())) {
 | 
					        } else if (!(await git.tryReset())) {
 | 
				
			||||||
          remove = true
 | 
					          remove = true
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (remove) {
 | 
					        if (remove) {
 | 
				
			||||||
          core.warning(
 | 
					          core.warning(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,23 +8,16 @@ import * as io from '@actions/io'
 | 
				
			|||||||
import * as path from 'path'
 | 
					import * as path from 'path'
 | 
				
			||||||
import * as refHelper from './ref-helper'
 | 
					import * as refHelper from './ref-helper'
 | 
				
			||||||
import * as stateHelper from './state-helper'
 | 
					import * as stateHelper from './state-helper'
 | 
				
			||||||
 | 
					import * as urlHelper from './url-helper'
 | 
				
			||||||
import {IGitCommandManager} from './git-command-manager'
 | 
					import {IGitCommandManager} from './git-command-manager'
 | 
				
			||||||
import {IGitSourceSettings} from './git-source-settings'
 | 
					import {IGitSourceSettings} from './git-source-settings'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const hostname = 'github.com'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
					export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
				
			||||||
  // Repository URL
 | 
					  // Repository URL
 | 
				
			||||||
  core.info(
 | 
					  core.info(
 | 
				
			||||||
    `Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`
 | 
					    `Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
  const repositoryUrl = settings.sshKey
 | 
					  const repositoryUrl = urlHelper.getFetchUrl(settings)
 | 
				
			||||||
    ? `git@${hostname}:${encodeURIComponent(
 | 
					 | 
				
			||||||
        settings.repositoryOwner
 | 
					 | 
				
			||||||
      )}/${encodeURIComponent(settings.repositoryName)}.git`
 | 
					 | 
				
			||||||
    : `https://${hostname}/${encodeURIComponent(
 | 
					 | 
				
			||||||
        settings.repositoryOwner
 | 
					 | 
				
			||||||
      )}/${encodeURIComponent(settings.repositoryName)}`
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Remove conflicting file path
 | 
					  // Remove conflicting file path
 | 
				
			||||||
  if (fsHelper.fileExistsSync(settings.repositoryPath)) {
 | 
					  if (fsHelper.fileExistsSync(settings.repositoryPath)) {
 | 
				
			||||||
@@ -39,7 +32,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Git command manager
 | 
					  // Git command manager
 | 
				
			||||||
 | 
					  core.startGroup('Getting Git version info')
 | 
				
			||||||
  const git = await getGitCommandManager(settings)
 | 
					  const git = await getGitCommandManager(settings)
 | 
				
			||||||
 | 
					  core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Prepare existing directory, otherwise recreate
 | 
					  // Prepare existing directory, otherwise recreate
 | 
				
			||||||
  if (isExisting) {
 | 
					  if (isExisting) {
 | 
				
			||||||
@@ -57,6 +52,16 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
				
			|||||||
    core.info(
 | 
					    core.info(
 | 
				
			||||||
      `To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`
 | 
					      `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.`
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await githubApiHelper.downloadRepository(
 | 
					    await githubApiHelper.downloadRepository(
 | 
				
			||||||
      settings.authToken,
 | 
					      settings.authToken,
 | 
				
			||||||
      settings.repositoryOwner,
 | 
					      settings.repositoryOwner,
 | 
				
			||||||
@@ -75,21 +80,27 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
				
			|||||||
  if (
 | 
					  if (
 | 
				
			||||||
    !fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
 | 
					    !fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
 | 
					    core.startGroup('Initializing the repository')
 | 
				
			||||||
    await git.init()
 | 
					    await git.init()
 | 
				
			||||||
    await git.remoteAdd('origin', repositoryUrl)
 | 
					    await git.remoteAdd('origin', repositoryUrl)
 | 
				
			||||||
 | 
					    core.endGroup()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Disable automatic garbage collection
 | 
					  // Disable automatic garbage collection
 | 
				
			||||||
 | 
					  core.startGroup('Disabling automatic garbage collection')
 | 
				
			||||||
  if (!(await git.tryDisableAutomaticGarbageCollection())) {
 | 
					  if (!(await git.tryDisableAutomaticGarbageCollection())) {
 | 
				
			||||||
    core.warning(
 | 
					    core.warning(
 | 
				
			||||||
      `Unable to turn off git automatic garbage collection. The git fetch operation may trigger garbage collection and cause a delay.`
 | 
					      `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)
 | 
					  const authHelper = gitAuthHelper.createAuthHelper(git, settings)
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    // Configure auth
 | 
					    // Configure auth
 | 
				
			||||||
 | 
					    core.startGroup('Setting up auth')
 | 
				
			||||||
    await authHelper.configureAuth()
 | 
					    await authHelper.configureAuth()
 | 
				
			||||||
 | 
					    core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // LFS install
 | 
					    // LFS install
 | 
				
			||||||
    if (settings.lfs) {
 | 
					    if (settings.lfs) {
 | 
				
			||||||
@@ -97,33 +108,44 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Fetch
 | 
					    // Fetch
 | 
				
			||||||
 | 
					    core.startGroup('Fetching the repository')
 | 
				
			||||||
    const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
 | 
					    const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
 | 
				
			||||||
    await git.fetch(settings.fetchDepth, refSpec)
 | 
					    await git.fetch(settings.fetchDepth, refSpec)
 | 
				
			||||||
 | 
					    core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Checkout info
 | 
					    // Checkout info
 | 
				
			||||||
 | 
					    core.startGroup('Determining the checkout info')
 | 
				
			||||||
    const checkoutInfo = await refHelper.getCheckoutInfo(
 | 
					    const checkoutInfo = await refHelper.getCheckoutInfo(
 | 
				
			||||||
      git,
 | 
					      git,
 | 
				
			||||||
      settings.ref,
 | 
					      settings.ref,
 | 
				
			||||||
      settings.commit
 | 
					      settings.commit
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					    core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // LFS fetch
 | 
					    // LFS fetch
 | 
				
			||||||
    // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
 | 
					    // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
 | 
				
			||||||
    // Explicit lfs fetch will fetch lfs objects in parallel.
 | 
					    // Explicit lfs fetch will fetch lfs objects in parallel.
 | 
				
			||||||
    if (settings.lfs) {
 | 
					    if (settings.lfs) {
 | 
				
			||||||
 | 
					      core.startGroup('Fetching LFS objects')
 | 
				
			||||||
      await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref)
 | 
					      await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref)
 | 
				
			||||||
 | 
					      core.endGroup()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Checkout
 | 
					    // Checkout
 | 
				
			||||||
 | 
					    core.startGroup('Checking out the ref')
 | 
				
			||||||
    await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
 | 
					    await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
 | 
				
			||||||
 | 
					    core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Submodules
 | 
					    // Submodules
 | 
				
			||||||
    if (settings.submodules) {
 | 
					    if (settings.submodules) {
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
        // Temporarily override global config
 | 
					        // Temporarily override global config
 | 
				
			||||||
 | 
					        core.startGroup('Setting up auth for fetching submodules')
 | 
				
			||||||
        await authHelper.configureGlobalAuth()
 | 
					        await authHelper.configureGlobalAuth()
 | 
				
			||||||
 | 
					        core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Checkout submodules
 | 
					        // Checkout submodules
 | 
				
			||||||
 | 
					        core.startGroup('Fetching submodules')
 | 
				
			||||||
        await git.submoduleSync(settings.nestedSubmodules)
 | 
					        await git.submoduleSync(settings.nestedSubmodules)
 | 
				
			||||||
        await git.submoduleUpdate(
 | 
					        await git.submoduleUpdate(
 | 
				
			||||||
          settings.fetchDepth,
 | 
					          settings.fetchDepth,
 | 
				
			||||||
@@ -133,10 +155,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
				
			|||||||
          'git config --local gc.auto 0',
 | 
					          'git config --local gc.auto 0',
 | 
				
			||||||
          settings.nestedSubmodules
 | 
					          settings.nestedSubmodules
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        core.endGroup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Persist credentials
 | 
					        // Persist credentials
 | 
				
			||||||
        if (settings.persistCredentials) {
 | 
					        if (settings.persistCredentials) {
 | 
				
			||||||
 | 
					          core.startGroup('Persisting credentials for submodules')
 | 
				
			||||||
          await authHelper.configureSubmoduleAuth()
 | 
					          await authHelper.configureSubmoduleAuth()
 | 
				
			||||||
 | 
					          core.endGroup()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      } finally {
 | 
					      } finally {
 | 
				
			||||||
        // Remove temporary global config override
 | 
					        // Remove temporary global config override
 | 
				
			||||||
@@ -149,7 +174,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
 | 
				
			|||||||
  } finally {
 | 
					  } finally {
 | 
				
			||||||
    // Remove auth
 | 
					    // Remove auth
 | 
				
			||||||
    if (!settings.persistCredentials) {
 | 
					    if (!settings.persistCredentials) {
 | 
				
			||||||
 | 
					      core.startGroup('Removing auth')
 | 
				
			||||||
      await authHelper.removeAuth()
 | 
					      await authHelper.removeAuth()
 | 
				
			||||||
 | 
					      core.endGroup()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,17 +1,76 @@
 | 
				
			|||||||
export interface IGitSourceSettings {
 | 
					export interface IGitSourceSettings {
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The location on disk where the repository will be placed
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  repositoryPath: string
 | 
					  repositoryPath: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The repository owner
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  repositoryOwner: string
 | 
					  repositoryOwner: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The repository name
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  repositoryName: string
 | 
					  repositoryName: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The ref to fetch
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  ref: string
 | 
					  ref: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The commit to checkout
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  commit: string
 | 
					  commit: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Indicates whether to clean the repository
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  clean: boolean
 | 
					  clean: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The depth when fetching
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  fetchDepth: number
 | 
					  fetchDepth: number
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Indicates whether to fetch LFS objects
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  lfs: boolean
 | 
					  lfs: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Indicates whether to checkout submodules
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  submodules: boolean
 | 
					  submodules: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Indicates whether to recursively checkout submodules
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  nestedSubmodules: boolean
 | 
					  nestedSubmodules: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The auth token to use when fetching the repository
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  authToken: string
 | 
					  authToken: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The SSH key to configure
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  sshKey: string
 | 
					  sshKey: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Additional SSH known hosts
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  sshKnownHosts: string
 | 
					  sshKnownHosts: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Indicates whether the server must be a known host
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  sshStrict: boolean
 | 
					  sshStrict: boolean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
  persistCredentials: boolean
 | 
					  persistCredentials: boolean
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ 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 * as urlHelper from './url-helper'
 | 
				
			||||||
import {default as uuid} from 'uuid/v4'
 | 
					import {default as uuid} from 'uuid/v4'
 | 
				
			||||||
import {ReposGetArchiveLinkParams} from '@octokit/rest'
 | 
					import {ReposGetArchiveLinkParams} from '@octokit/rest'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -74,7 +75,7 @@ async function downloadArchive(
 | 
				
			|||||||
  ref: string,
 | 
					  ref: string,
 | 
				
			||||||
  commit: string
 | 
					  commit: string
 | 
				
			||||||
): Promise<Buffer> {
 | 
					): Promise<Buffer> {
 | 
				
			||||||
  const octokit = new github.GitHub(authToken)
 | 
					  const octokit = new github.GitHub(authToken, {baseUrl: urlHelper.getApiUrl()})
 | 
				
			||||||
  const params: ReposGetArchiveLinkParams = {
 | 
					  const params: ReposGetArchiveLinkParams = {
 | 
				
			||||||
    owner: owner,
 | 
					    owner: owner,
 | 
				
			||||||
    repo: repo,
 | 
					    repo: repo,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										28
									
								
								src/url-helper.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/url-helper.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					import * as assert from 'assert'
 | 
				
			||||||
 | 
					import {IGitSourceSettings} from './git-source-settings'
 | 
				
			||||||
 | 
					import {URL} from 'url'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getApiUrl(): string {
 | 
				
			||||||
 | 
					  return process.env['GITHUB_API_URL'] || 'https://api.github.com'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getFetchUrl(settings: IGitSourceSettings): string {
 | 
				
			||||||
 | 
					  assert.ok(
 | 
				
			||||||
 | 
					    settings.repositoryOwner,
 | 
				
			||||||
 | 
					    'settings.repositoryOwner must be defined'
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
 | 
				
			||||||
 | 
					  const serviceUrl = getServerUrl()
 | 
				
			||||||
 | 
					  const encodedOwner = encodeURIComponent(settings.repositoryOwner)
 | 
				
			||||||
 | 
					  const encodedName = encodeURIComponent(settings.repositoryName)
 | 
				
			||||||
 | 
					  if (settings.sshKey) {
 | 
				
			||||||
 | 
					    return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // "origin" is SCHEME://HOSTNAME[:PORT]
 | 
				
			||||||
 | 
					  return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getServerUrl(): URL {
 | 
				
			||||||
 | 
					  return new URL(process.env['GITHUB_URL'] || 'https://github.com')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user