mirror of
				https://github.com/actions/checkout.git
				synced 2025-10-31 19:23:59 +08:00 
			
		
		
		
	Compare commits
	
		
			13 Commits
		
	
	
		
			v2.3.0
			...
			hross-zeit
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | c43fdbfb30 | ||
|   | 239235dd46 | ||
|   | 2955f2419d | ||
|   | 5aa50f005d | ||
|   | be6c44d969 | ||
|   | dac8cc78a1 | ||
|   | 2036a08e25 | ||
|   | 592cf69a22 | ||
|   | a4b69b4886 | ||
|   | 1433f62caa | ||
|   | 61b9e3751b | ||
|   | 28c7f3d2b5 | ||
|   | fb6f360df2 | 
							
								
								
									
										2
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							| @@ -4,7 +4,7 @@ on: | ||||
|   pull_request: | ||||
|   push: | ||||
|     branches: | ||||
|       - master | ||||
|       - main | ||||
|       - releases/* | ||||
|  | ||||
| jobs: | ||||
|   | ||||
| @@ -1,5 +1,10 @@ | ||||
| # Changelog | ||||
|  | ||||
| ## v2.3.1 | ||||
|  | ||||
| - [Fix default branch resolution for .wiki and when using SSH](https://github.com/actions/checkout/pull/284) | ||||
|  | ||||
|  | ||||
| ## v2.3.0 | ||||
|  | ||||
| - [Fallback to the default branch](https://github.com/actions/checkout/pull/278) | ||||
|   | ||||
							
								
								
									
										23
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								README.md
									
									
									
									
									
								
							| @@ -89,7 +89,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous | ||||
|     # Default: true | ||||
|     clean: '' | ||||
|  | ||||
|     # Number of commits to fetch. 0 indicates all history. | ||||
|     # Number of commits to fetch. 0 indicates all history for all branches and tags. | ||||
|     # Default: 1 | ||||
|     fetch-depth: '' | ||||
|  | ||||
| @@ -118,6 +118,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous | ||||
| - [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 on closed event](#Checkout-pull-request-on-closed-event) | ||||
| - [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token) | ||||
|  | ||||
| ## Fetch all history for all tags and branches | ||||
|  | ||||
| @@ -204,7 +205,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous | ||||
| ```yaml | ||||
| on: | ||||
|   pull_request: | ||||
|     branches: [master] | ||||
|     branches: [main] | ||||
|     types: [opened, synchronize, closed] | ||||
| jobs: | ||||
|   build: | ||||
| @@ -213,6 +214,24 @@ jobs: | ||||
|       - uses: actions/checkout@v2 | ||||
| ``` | ||||
|  | ||||
| ## Push a commit using the built-in token | ||||
|  | ||||
| ```yaml | ||||
| on: push | ||||
| jobs: | ||||
|   build: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - run: | | ||||
|           date > generated.txt | ||||
|           git config user.name github-actions | ||||
|           git config user.email github-actions@github.com | ||||
|           git add . | ||||
|           git commit -m "generated" | ||||
|           git push | ||||
| ``` | ||||
|  | ||||
| # License | ||||
|  | ||||
| The scripts and documentation in this project are released under the [MIT License](LICENSE) | ||||
|   | ||||
| @@ -714,6 +714,7 @@ async function setup(testName: string): Promise<void> { | ||||
|     ), | ||||
|     env: {}, | ||||
|     fetch: jest.fn(), | ||||
|     getDefaultBranch: jest.fn(), | ||||
|     getWorkingDirectory: jest.fn(() => workspace), | ||||
|     init: jest.fn(), | ||||
|     isDetached: jest.fn(), | ||||
| @@ -763,7 +764,7 @@ async function setup(testName: string): Promise<void> { | ||||
|     submodules: false, | ||||
|     nestedSubmodules: false, | ||||
|     persistCredentials: true, | ||||
|     ref: 'refs/heads/master', | ||||
|     ref: 'refs/heads/main', | ||||
|     repositoryName: 'my-repo', | ||||
|     repositoryOwner: 'my-org', | ||||
|     repositoryPath: '', | ||||
|   | ||||
| @@ -408,6 +408,7 @@ async function setup(testName: string): Promise<void> { | ||||
|     config: jest.fn(), | ||||
|     configExists: jest.fn(), | ||||
|     fetch: jest.fn(), | ||||
|     getDefaultBranch: jest.fn(), | ||||
|     getWorkingDirectory: jest.fn(() => repositoryPath), | ||||
|     init: jest.fn(), | ||||
|     isDetached: jest.fn(), | ||||
|   | ||||
| @@ -20,5 +20,5 @@ else | ||||
|  | ||||
|   # Verify auth token | ||||
|   cd basic | ||||
|   git fetch --no-tags --depth=1 origin +refs/heads/master:refs/remotes/origin/master | ||||
|   git fetch --no-tags --depth=1 origin +refs/heads/main:refs/remotes/origin/main | ||||
| fi | ||||
|   | ||||
| @@ -54,7 +54,7 @@ inputs: | ||||
|     description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching' | ||||
|     default: true | ||||
|   fetch-depth: | ||||
|     description: 'Number of commits to fetch. 0 indicates all history.' | ||||
|     description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.' | ||||
|     default: 1 | ||||
|   lfs: | ||||
|     description: 'Whether to download Git-LFS files' | ||||
|   | ||||
| @@ -24,7 +24,7 @@ We want to take this opportunity to make behavioral changes, from v1. This docum | ||||
|     description: > | ||||
|       The branch, tag or SHA to checkout. When checking out the repository that | ||||
|       triggered a workflow, this defaults to the reference or SHA for that | ||||
|       event.  Otherwise, defaults to `master`. | ||||
|       event.  Otherwise, uses the default branch. | ||||
|   token: | ||||
|     description: > | ||||
|       Personal access token (PAT) used to fetch the repository. The PAT is configured | ||||
| @@ -277,7 +277,7 @@ Note: | ||||
| ### Branching strategy and release tags | ||||
|  | ||||
| - Create a servicing branch for V1: `releases/v1` | ||||
| - Merge the changes into `master` | ||||
| - Merge the changes into the default branch | ||||
| - Release using a new tag `preview` | ||||
| - When stable, release using a new tag `v2` | ||||
|  | ||||
|   | ||||
							
								
								
									
										30668
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										30668
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1328
									
								
								dist/licenses.txt
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1328
									
								
								dist/licenses.txt
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -971,10 +971,10 @@ | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     "@zeit/ncc": { | ||||
|       "version": "0.20.5", | ||||
|       "resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.20.5.tgz", | ||||
|       "integrity": "sha512-XU6uzwvv95DqxciQx+aOLhbyBx/13ky+RK1y88Age9Du3BlA4mMPCy13BGjayOrrumOzlq1XV3SD/BWiZENXlw==", | ||||
|     "@vercel/ncc": { | ||||
|       "version": "0.23.0", | ||||
|       "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.23.0.tgz", | ||||
|       "integrity": "sha512-Fcr1qlG9t54X4X9qbo/+jr1+t5Qc6H3TgIRBXmKkF/WDs6YFulAN6ilq2Ehx38RbgIOFxaZnjlAQ50GyexnMpQ==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "abab": { | ||||
|   | ||||
| @@ -38,7 +38,7 @@ | ||||
|     "@types/node": "^12.7.12", | ||||
|     "@types/uuid": "^3.4.6", | ||||
|     "@typescript-eslint/parser": "^2.8.0", | ||||
|     "@zeit/ncc": "^0.20.5", | ||||
|     "@vercel/ncc": "^0.23.0", | ||||
|     "eslint": "^5.16.0", | ||||
|     "eslint-plugin-github": "^2.0.0", | ||||
|     "eslint-plugin-jest": "^22.21.0", | ||||
|   | ||||
| @@ -25,6 +25,7 @@ export interface IGitCommandManager { | ||||
|   ): Promise<void> | ||||
|   configExists(configKey: string, globalConfig?: boolean): Promise<boolean> | ||||
|   fetch(refSpec: string[], fetchDepth?: number): Promise<void> | ||||
|   getDefaultBranch(repositoryUrl: string): Promise<string> | ||||
|   getWorkingDirectory(): string | ||||
|   init(): Promise<void> | ||||
|   isDetached(): Promise<boolean> | ||||
| @@ -195,6 +196,34 @@ class GitCommandManager { | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   async getDefaultBranch(repositoryUrl: string): Promise<string> { | ||||
|     let output: GitOutput | undefined | ||||
|     await retryHelper.execute(async () => { | ||||
|       output = await this.execGit([ | ||||
|         'ls-remote', | ||||
|         '--quiet', | ||||
|         '--exit-code', | ||||
|         '--symref', | ||||
|         repositoryUrl, | ||||
|         'HEAD' | ||||
|       ]) | ||||
|     }) | ||||
|  | ||||
|     if (output) { | ||||
|       // Satisfy compiler, will always be set | ||||
|       for (let line of output.stdout.trim().split('\n')) { | ||||
|         line = line.trim() | ||||
|         if (line.startsWith('ref:') || line.endsWith('HEAD')) { | ||||
|           return line | ||||
|             .substr('ref:'.length, line.length - 'ref:'.length - 'HEAD'.length) | ||||
|             .trim() | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     throw new Error('Unexpected output when retrieving default branch') | ||||
|   } | ||||
|  | ||||
|   getWorkingDirectory(): string { | ||||
|     return this.workingDirectory | ||||
|   } | ||||
| @@ -241,7 +270,7 @@ class GitCommandManager { | ||||
|   /** | ||||
|    * Resolves a ref to a SHA. For a branch or lightweight tag, the commit SHA is returned. | ||||
|    * For an annotated tag, the tag SHA is returned. | ||||
|    * @param {string} ref  For example: 'refs/heads/master' or '/refs/tags/v1' | ||||
|    * @param {string} ref  For example: 'refs/heads/main' or '/refs/tags/v1' | ||||
|    * @returns {Promise<string>} | ||||
|    */ | ||||
|   async revParse(ref: string): Promise<string> { | ||||
|   | ||||
| @@ -19,17 +19,6 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | ||||
|   ) | ||||
|   const repositoryUrl = urlHelper.getFetchUrl(settings) | ||||
|  | ||||
|   // Determine the default branch | ||||
|   if (!settings.ref && !settings.commit) { | ||||
|     core.startGroup('Determining the default branch') | ||||
|     settings.ref = await githubApiHelper.getDefaultBranch( | ||||
|       settings.authToken, | ||||
|       settings.repositoryOwner, | ||||
|       settings.repositoryName | ||||
|     ) | ||||
|     core.endGroup() | ||||
|   } | ||||
|  | ||||
|   // Remove conflicting file path | ||||
|   if (fsHelper.fileExistsSync(settings.repositoryPath)) { | ||||
|     await io.rmRF(settings.repositoryPath) | ||||
| @@ -114,6 +103,21 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | ||||
|     await authHelper.configureAuth() | ||||
|     core.endGroup() | ||||
|  | ||||
|     // Determine the default branch | ||||
|     if (!settings.ref && !settings.commit) { | ||||
|       core.startGroup('Determining the default branch') | ||||
|       if (settings.sshKey) { | ||||
|         settings.ref = await git.getDefaultBranch(repositoryUrl) | ||||
|       } else { | ||||
|         settings.ref = await githubApiHelper.getDefaultBranch( | ||||
|           settings.authToken, | ||||
|           settings.repositoryOwner, | ||||
|           settings.repositoryName | ||||
|         ) | ||||
|       } | ||||
|       core.endGroup() | ||||
|     } | ||||
|  | ||||
|     // LFS install | ||||
|     if (settings.lfs) { | ||||
|       await git.lfsInstall() | ||||
|   | ||||
| @@ -19,6 +19,12 @@ export async function downloadRepository( | ||||
|   commit: string, | ||||
|   repositoryPath: string | ||||
| ): Promise<void> { | ||||
|   // Determine the default branch | ||||
|   if (!ref && !commit) { | ||||
|     core.info('Determining the default branch') | ||||
|     ref = await getDefaultBranch(authToken, owner, repo) | ||||
|   } | ||||
|  | ||||
|   // Download the archive | ||||
|   let archiveData = await retryHelper.execute(async () => { | ||||
|     core.info('Downloading the archive') | ||||
| @@ -78,17 +84,25 @@ export async function getDefaultBranch( | ||||
|   return await retryHelper.execute(async () => { | ||||
|     core.info('Retrieving the default branch name') | ||||
|     const octokit = new github.GitHub(authToken) | ||||
|     const response = await octokit.repos.get({owner, repo}) | ||||
|     if (response.status != 200) { | ||||
|       throw new Error( | ||||
|         `Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}` | ||||
|       ) | ||||
|     let result: string | ||||
|     try { | ||||
|       // Get the default branch from the repo info | ||||
|       const response = await octokit.repos.get({owner, repo}) | ||||
|       result = response.data.default_branch | ||||
|       assert.ok(result, 'default_branch cannot be empty') | ||||
|     } catch (err) { | ||||
|       // Handle .wiki repo | ||||
|       if (err['status'] === 404 && repo.toUpperCase().endsWith('.WIKI')) { | ||||
|         result = 'master' | ||||
|       } | ||||
|       // Otherwise error | ||||
|       else { | ||||
|         throw err | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     // Print the default branch | ||||
|     let result = response.data.default_branch | ||||
|     core.info(`Default branch '${result}'`) | ||||
|     assert.ok(result, 'default_branch cannot be empty') | ||||
|  | ||||
|     // Prefix with 'refs/heads' | ||||
|     if (!result.startsWith('refs/')) { | ||||
|   | ||||
| @@ -63,7 +63,7 @@ export function getInputs(): IGitSourceSettings { | ||||
|       result.commit = github.context.sha | ||||
|  | ||||
|       // Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event), | ||||
|       // the ref is unqualifed like "master" instead of "refs/heads/master". | ||||
|       // the ref is unqualifed like "main" instead of "refs/heads/main". | ||||
|       if (result.commit && result.ref && !result.ref.startsWith('refs/')) { | ||||
|         result.ref = `refs/heads/${result.ref}` | ||||
|       } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user