mirror of
https://github.com/actions/checkout.git
synced 2026-08-07 02:18:58 +07:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4817b449b0 | |||
| 689bf84be4 | |||
| cc70598ce8 | |||
| 8461dbfed3 | |||
| e347bba93b |
@@ -0,0 +1,3 @@
|
|||||||
|
dist/
|
||||||
|
lib/
|
||||||
|
node_modules/
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["jest", "@typescript-eslint"],
|
||||||
|
"extends": ["plugin:github/es6"],
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 9,
|
||||||
|
"sourceType": "module",
|
||||||
|
"project": "./tsconfig.json"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"eslint-comments/no-use": "off",
|
||||||
|
"import/no-namespace": "off",
|
||||||
|
"no-unused-vars": "off",
|
||||||
|
"@typescript-eslint/no-unused-vars": "error",
|
||||||
|
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
||||||
|
"@typescript-eslint/no-require-imports": "error",
|
||||||
|
"@typescript-eslint/array-type": "error",
|
||||||
|
"@typescript-eslint/await-thenable": "error",
|
||||||
|
"@typescript-eslint/ban-ts-ignore": "error",
|
||||||
|
"camelcase": "off",
|
||||||
|
"@typescript-eslint/camelcase": "error",
|
||||||
|
"@typescript-eslint/class-name-casing": "error",
|
||||||
|
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||||
|
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||||
|
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
|
||||||
|
"@typescript-eslint/no-array-constructor": "error",
|
||||||
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
|
"@typescript-eslint/no-extraneous-class": "error",
|
||||||
|
"@typescript-eslint/no-for-in-array": "error",
|
||||||
|
"@typescript-eslint/no-inferrable-types": "error",
|
||||||
|
"@typescript-eslint/no-misused-new": "error",
|
||||||
|
"@typescript-eslint/no-namespace": "error",
|
||||||
|
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||||
|
"@typescript-eslint/no-object-literal-type-assertion": "error",
|
||||||
|
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||||
|
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||||
|
"@typescript-eslint/no-useless-constructor": "error",
|
||||||
|
"@typescript-eslint/no-var-requires": "error",
|
||||||
|
"@typescript-eslint/prefer-for-of": "warn",
|
||||||
|
"@typescript-eslint/prefer-function-type": "warn",
|
||||||
|
"@typescript-eslint/prefer-includes": "error",
|
||||||
|
"@typescript-eslint/prefer-interface": "error",
|
||||||
|
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||||
|
"@typescript-eslint/promise-function-async": "error",
|
||||||
|
"@typescript-eslint/require-array-sort-compare": "error",
|
||||||
|
"@typescript-eslint/restrict-plus-operands": "error",
|
||||||
|
"semi": "off",
|
||||||
|
"@typescript-eslint/semi": ["error", "never"],
|
||||||
|
"@typescript-eslint/type-annotation-spacing": "error",
|
||||||
|
"@typescript-eslint/unbound-method": "error"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"es6": true,
|
||||||
|
"jest/globals": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,83 @@
|
|||||||
name: "test-local"
|
name: Build and Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- 'releases/*'
|
- releases/*
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1 # todo: switch to v2
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run build
|
||||||
|
- run: npm run format-check
|
||||||
|
- run: npm run lint
|
||||||
|
- run: npm run pack
|
||||||
|
- run: npm run gendocs
|
||||||
|
- name: Verify no unstaged changes
|
||||||
|
run: __test__/verify-no-unstaged-changes.sh
|
||||||
|
|
||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [windows-latest, ubuntu-latest, macOS-latest]
|
runs-on: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.runs-on }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
# Clone this repo
|
||||||
- uses: ./
|
- name: Checkout
|
||||||
with:
|
uses: actions/checkout@v1 # todo: switch to V2
|
||||||
ref: master
|
|
||||||
|
# Basic checkout
|
||||||
|
- name: Basic checkout
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
ref: test-data/v2/basic
|
||||||
|
path: basic
|
||||||
|
- name: Verify basic
|
||||||
|
shell: bash
|
||||||
|
run: __test__/verify-basic.sh
|
||||||
|
|
||||||
|
# Clean
|
||||||
|
- name: Modify work tree
|
||||||
|
shell: bash
|
||||||
|
run: __test__/modify-work-tree.sh
|
||||||
|
- name: Clean checkout
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
ref: test-data/v2/basic
|
||||||
|
path: basic
|
||||||
|
- name: Verify clean
|
||||||
|
shell: bash
|
||||||
|
run: __test__/verify-clean.sh
|
||||||
|
|
||||||
|
# Side by side
|
||||||
|
- name: Side by side checkout 1
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
ref: test-data/v2/side-by-side-1
|
||||||
|
path: side-by-side-1
|
||||||
|
- name: Side by side checkout 2
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
ref: test-data/v2/side-by-side-2
|
||||||
|
path: side-by-side-2
|
||||||
|
- name: Verify side by side
|
||||||
|
shell: bash
|
||||||
|
run: __test__/verify-side-by-side.sh
|
||||||
|
|
||||||
|
# LFS
|
||||||
|
- name: LFS checkout
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
repository: actions/checkout # hardcoded, otherwise doesn't work from a fork
|
||||||
|
ref: test-data/v2/lfs
|
||||||
|
path: lfs
|
||||||
|
lfs: true
|
||||||
|
- name: Verify LFS
|
||||||
|
shell: bash
|
||||||
|
run: __test__/verify-lfs.sh
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
lib/
|
||||||
|
node_modules/
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
dist/
|
||||||
|
lib/
|
||||||
|
node_modules/
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": false,
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"parser": "typescript"
|
||||||
|
}
|
||||||
+18
-8
@@ -1,13 +1,23 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## Unreleased Changes
|
## v2 (beta)
|
||||||
- N/A
|
|
||||||
|
|
||||||
## v1.2.0
|
- Improved fetch performance
|
||||||
- Reverted the breaking behavior change in v1.1.0 that broke custom authentication flows
|
- The default behavior now fetches only the SHA being checked-out
|
||||||
|
- Script authenticated git commands
|
||||||
|
- Persists `with.token` in the local git config
|
||||||
|
- Enables your scripts to run authenticated git commands
|
||||||
|
- Post-job cleanup removes the token
|
||||||
|
- Coming soon: Opt out by setting `with.persist-credentials` to `false`
|
||||||
|
- Creates a local branch
|
||||||
|
- No longer detached HEAD when checking out a branch
|
||||||
|
- A local branch is created with the corresponding upstream branch set
|
||||||
|
- Improved layout
|
||||||
|
- `with.path` is always relative to `github.workspace`
|
||||||
|
- Aligns better with container actions, where `github.workspace` gets mapped in
|
||||||
|
- Removed input `submodules`
|
||||||
|
|
||||||
## v1.1.0 (Not reccomended for use, this functionality will be ported to the 2.0 update)
|
|
||||||
- Persist `with.token` or `${{ github.token }}` into checkout repository's git config as `http.https://github.com/.extraheader=AUTHORIZATION: basic ***` to better support scripting git
|
|
||||||
|
|
||||||
## v1.0.0
|
## v1
|
||||||
- Initial Release of the checkout action
|
|
||||||
|
Refer [here](https://github.com/actions/checkout/blob/v1/CHANGELOG.md) for the V1 changelog
|
||||||
|
|||||||
@@ -2,60 +2,86 @@
|
|||||||
<a href="https://github.com/actions/checkout"><img alt="GitHub Actions status" src="https://github.com/actions/checkout/workflows/test-local/badge.svg"></a>
|
<a href="https://github.com/actions/checkout"><img alt="GitHub Actions status" src="https://github.com/actions/checkout/workflows/test-local/badge.svg"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Checkout
|
# Checkout V2 beta
|
||||||
|
|
||||||
This action checks out your repository to `$GITHUB_WORKSPACE`, so that your workflow can access the contents of your repository.
|
This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.
|
||||||
|
|
||||||
By default, this is equivalent to running `git fetch` and `git checkout $GITHUB_SHA`, so that you'll always have your repo contents at the version that triggered the workflow.
|
By default, the repository that triggered the workflow is checked-out, for the ref/SHA that triggered the event.
|
||||||
See [here](https://help.github.com/en/articles/events-that-trigger-workflows) to learn what `$GITHUB_SHA` is for different kinds of events.
|
|
||||||
|
Refer [here](https://help.github.com/en/articles/events-that-trigger-workflows) to learn which commit `$GITHUB_SHA` points to for different events.
|
||||||
|
|
||||||
|
Changes in V2:
|
||||||
|
- Improved fetch performance
|
||||||
|
- The default behavior now fetches only the SHA being checked-out
|
||||||
|
- Script authenticated git commands
|
||||||
|
- Persists `with.token` in the local git config
|
||||||
|
- Enables your scripts to run authenticated git commands
|
||||||
|
- Post-job cleanup removes the token
|
||||||
|
- Coming soon: Opt out by setting `with.persist-credentials` to `false`
|
||||||
|
- Creates a local branch
|
||||||
|
- No longer detached HEAD when checking out a branch
|
||||||
|
- A local branch is created with the corresponding upstream branch set
|
||||||
|
- Improved layout
|
||||||
|
- `with.path` is always relative to `github.workspace`
|
||||||
|
- Aligns better with container actions, where `github.workspace` gets mapped in
|
||||||
|
- Removed input `submodules`
|
||||||
|
|
||||||
|
Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous versions.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
See [action.yml](action.yml)
|
<!-- start usage -->
|
||||||
|
|
||||||
Basic:
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
- uses: actions/checkout@v2-beta
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- uses: actions/setup-node@v1
|
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
# Repository name with owner. For example, actions/checkout
|
||||||
- run: npm install
|
# Default: ${{ github.repository }}
|
||||||
- run: npm test
|
repository: ''
|
||||||
|
|
||||||
|
# Ref to checkout (SHA, branch, tag). For the repository that triggered the
|
||||||
|
# workflow, defaults to the ref/SHA for the event. Otherwise defaults to master.
|
||||||
|
ref: ''
|
||||||
|
|
||||||
|
# Access token for clone repository
|
||||||
|
# Default: ${{ github.token }}
|
||||||
|
token: ''
|
||||||
|
|
||||||
|
# Relative path under $GITHUB_WORKSPACE to place the repository
|
||||||
|
path: ''
|
||||||
|
|
||||||
|
# Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching
|
||||||
|
# Default: true
|
||||||
|
clean: ''
|
||||||
|
|
||||||
|
# Number of commits to fetch. 0 indicates all history.
|
||||||
|
# Default: 1
|
||||||
|
fetch-depth: ''
|
||||||
|
|
||||||
|
# Whether to download Git-LFS files
|
||||||
|
# Default: false
|
||||||
|
lfs: ''
|
||||||
```
|
```
|
||||||
|
<!-- end usage -->
|
||||||
|
|
||||||
By default, the branch or tag ref that triggered the workflow will be checked out. If you wish to check out a different branch, a different repository or use different token to checkout, specify that using `with.ref`, `with.repository` and `with.token`.
|
## Checkout a different branch
|
||||||
|
|
||||||
## Checkout different branch from the workflow repository
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@preview
|
||||||
with:
|
with:
|
||||||
ref: some-branch
|
ref: some-branch
|
||||||
```
|
```
|
||||||
|
|
||||||
## Checkout different private repository
|
## Checkout a different, private repository
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@preview
|
||||||
with:
|
with:
|
||||||
repository: myAccount/myRepository
|
repository: myAccount/myRepository
|
||||||
ref: refs/heads/master
|
ref: refs/heads/master
|
||||||
token: ${{ secrets.GitHub_PAT }} # `GitHub_PAT` is a secret contains your PAT.
|
token: ${{ secrets.GitHub_PAT }} # `GitHub_PAT` is a secret that contains your PAT
|
||||||
```
|
```
|
||||||
> - `${{ github.token }}` is scoped to the current repository, so if you want to checkout another repository that is private you will need to provide your own [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
|
> - `${{ github.token }}` is scoped to the current repository, so if you want to checkout another repository that is private you will need to provide your own [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
|
||||||
|
|
||||||
## Checkout private submodules
|
|
||||||
```yaml
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
with:
|
|
||||||
submodules: true # 'recursive' 'true' or 'false'
|
|
||||||
token: ${{ secrets.GitHub_PAT }} # `GitHub_PAT` is a secret contains your PAT.
|
|
||||||
```
|
|
||||||
> - Private submodules must be configured via `https` not `ssh`.
|
|
||||||
> - `${{ github.token }}` only has permission to the workflow triggering repository. If the repository contains any submodules that come from private repositories, you will need to add your [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) as secret and use the secret in `with.token` to make the `checkout` action work.
|
|
||||||
|
|
||||||
For more details, see [Contexts and expression syntax for GitHub Actions](https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions) and [Creating and using encrypted secrets](https://help.github.com/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
|
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import {GitVersion} from '../lib/git-version'
|
||||||
|
|
||||||
|
describe('git-version tests', () => {
|
||||||
|
it('basics', async () => {
|
||||||
|
let version = new GitVersion('')
|
||||||
|
expect(version.isValid()).toBeFalsy()
|
||||||
|
|
||||||
|
version = new GitVersion('asdf')
|
||||||
|
expect(version.isValid()).toBeFalsy()
|
||||||
|
|
||||||
|
version = new GitVersion('1.2')
|
||||||
|
expect(version.isValid()).toBeTruthy()
|
||||||
|
expect(version.toString()).toBe('1.2')
|
||||||
|
|
||||||
|
version = new GitVersion('1.2.3')
|
||||||
|
expect(version.isValid()).toBeTruthy()
|
||||||
|
expect(version.toString()).toBe('1.2.3')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('check minimum', async () => {
|
||||||
|
let version = new GitVersion('4.5')
|
||||||
|
expect(version.checkMinimum(new GitVersion('3.6'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('3.6.7'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.4'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.5'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.5.0'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.6'))).toBeFalsy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.6.0'))).toBeFalsy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('5.1'))).toBeFalsy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('5.1.2'))).toBeFalsy()
|
||||||
|
|
||||||
|
version = new GitVersion('4.5.6')
|
||||||
|
expect(version.checkMinimum(new GitVersion('3.6'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('3.6.7'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.4'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.5'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.5.5'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.5.6'))).toBeTruthy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.5.7'))).toBeFalsy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.6'))).toBeFalsy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('4.6.0'))).toBeFalsy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('5.1'))).toBeFalsy()
|
||||||
|
expect(version.checkMinimum(new GitVersion('5.1.2'))).toBeFalsy()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import * as assert from 'assert'
|
||||||
|
import * as path from 'path'
|
||||||
|
import {ISourceSettings} from '../lib/git-source-provider'
|
||||||
|
|
||||||
|
const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
const gitHubWorkspace = path.resolve('/checkout-tests/workspace')
|
||||||
|
|
||||||
|
// Late bind
|
||||||
|
let inputHelper: any
|
||||||
|
|
||||||
|
// Mock @actions/core
|
||||||
|
let inputs = {} as any
|
||||||
|
const mockCore = jest.genMockFromModule('@actions/core') as any
|
||||||
|
mockCore.getInput = (name: string) => {
|
||||||
|
return inputs[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mock @actions/github
|
||||||
|
const mockGitHub = jest.genMockFromModule('@actions/github') as any
|
||||||
|
mockGitHub.context = {
|
||||||
|
repo: {
|
||||||
|
owner: 'some-owner',
|
||||||
|
repo: 'some-repo'
|
||||||
|
},
|
||||||
|
ref: 'refs/heads/some-ref',
|
||||||
|
sha: '1234567890123456789012345678901234567890'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mock ./fs-helper
|
||||||
|
const mockFSHelper = jest.genMockFromModule('../lib/fs-helper') as any
|
||||||
|
mockFSHelper.directoryExistsSync = (path: string) => path == gitHubWorkspace
|
||||||
|
|
||||||
|
describe('input-helper tests', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
// GitHub workspace
|
||||||
|
process.env['GITHUB_WORKSPACE'] = gitHubWorkspace
|
||||||
|
|
||||||
|
// Mocks
|
||||||
|
jest.setMock('@actions/core', mockCore)
|
||||||
|
jest.setMock('@actions/github', mockGitHub)
|
||||||
|
jest.setMock('../lib/fs-helper', mockFSHelper)
|
||||||
|
|
||||||
|
// Now import
|
||||||
|
inputHelper = require('../lib/input-helper')
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// Reset inputs
|
||||||
|
inputs = {}
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
// Reset GitHub workspace
|
||||||
|
delete process.env['GITHUB_WORKSPACE']
|
||||||
|
if (originalGitHubWorkspace) {
|
||||||
|
process.env['GITHUB_WORKSPACE'] = originalGitHubWorkspace
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset modules
|
||||||
|
jest.resetModules()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets defaults', () => {
|
||||||
|
const settings: ISourceSettings = inputHelper.getInputs()
|
||||||
|
expect(settings).toBeTruthy()
|
||||||
|
expect(settings.accessToken).toBeFalsy()
|
||||||
|
expect(settings.clean).toBe(true)
|
||||||
|
expect(settings.commit).toBeTruthy()
|
||||||
|
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
|
||||||
|
expect(settings.fetchDepth).toBe(1)
|
||||||
|
expect(settings.lfs).toBe(false)
|
||||||
|
expect(settings.ref).toBe('refs/heads/some-ref')
|
||||||
|
expect(settings.repositoryName).toBe('some-repo')
|
||||||
|
expect(settings.repositoryOwner).toBe('some-owner')
|
||||||
|
expect(settings.repositoryPath).toBe(gitHubWorkspace)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('requires qualified repo', () => {
|
||||||
|
inputs.repository = 'some-unqualified-repo'
|
||||||
|
assert.throws(() => {
|
||||||
|
inputHelper.getInputs()
|
||||||
|
}, /Invalid repository 'some-unqualified-repo'/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('roots path', () => {
|
||||||
|
inputs.path = 'some-directory/some-subdirectory'
|
||||||
|
const settings: ISourceSettings = inputHelper.getInputs()
|
||||||
|
expect(settings.repositoryPath).toBe(
|
||||||
|
path.join(gitHubWorkspace, 'some-directory', 'some-subdirectory')
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets correct default ref/sha for other repo', () => {
|
||||||
|
inputs.repository = 'some-owner/some-other-repo'
|
||||||
|
const settings: ISourceSettings = inputHelper.getInputs()
|
||||||
|
expect(settings.ref).toBe('refs/heads/master')
|
||||||
|
expect(settings.commit).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets ref to empty when explicit sha', () => {
|
||||||
|
inputs.ref = '1111111111222222222233333333334444444444'
|
||||||
|
const settings: ISourceSettings = inputHelper.getInputs()
|
||||||
|
expect(settings.ref).toBeFalsy()
|
||||||
|
expect(settings.commit).toBe('1111111111222222222233333333334444444444')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets sha to empty when explicit ref', () => {
|
||||||
|
inputs.ref = 'refs/heads/some-other-ref'
|
||||||
|
const settings: ISourceSettings = inputHelper.getInputs()
|
||||||
|
expect(settings.ref).toBe('refs/heads/some-other-ref')
|
||||||
|
expect(settings.commit).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('gives good error message for submodules input', () => {
|
||||||
|
inputs.submodules = 'true'
|
||||||
|
assert.throws(() => {
|
||||||
|
inputHelper.getInputs()
|
||||||
|
}, /The input 'submodules' is not supported/)
|
||||||
|
})
|
||||||
|
})
|
||||||
Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ ! -f "./basic/basic-file.txt" ]; then
|
||||||
|
echo "Expected basic file does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo hello >> ./basic/basic-file.txt
|
||||||
|
echo hello >> ./basic/new-file.txt
|
||||||
|
git -C ./basic status
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
import * as assert from 'assert'
|
||||||
|
import * as refHelper from '../lib/ref-helper'
|
||||||
|
import {IGitCommandManager} from '../lib/git-command-manager'
|
||||||
|
|
||||||
|
const commit = '1234567890123456789012345678901234567890'
|
||||||
|
let git: IGitCommandManager
|
||||||
|
|
||||||
|
describe('ref-helper tests', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
git = ({} as unknown) as IGitCommandManager
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo requires git', async () => {
|
||||||
|
const git = (null as unknown) as IGitCommandManager
|
||||||
|
try {
|
||||||
|
await refHelper.getCheckoutInfo(git, 'refs/heads/my/branch', commit)
|
||||||
|
throw new Error('Should not reach here')
|
||||||
|
} catch (err) {
|
||||||
|
expect(err.message).toBe('Arg git cannot be empty')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo requires ref or commit', async () => {
|
||||||
|
try {
|
||||||
|
await refHelper.getCheckoutInfo(git, '', '')
|
||||||
|
throw new Error('Should not reach here')
|
||||||
|
} catch (err) {
|
||||||
|
expect(err.message).toBe('Args ref and commit cannot both be empty')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo sha only', async () => {
|
||||||
|
const checkoutInfo = await refHelper.getCheckoutInfo(git, '', commit)
|
||||||
|
expect(checkoutInfo.ref).toBe(commit)
|
||||||
|
expect(checkoutInfo.startPoint).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo refs/heads/', async () => {
|
||||||
|
const checkoutInfo = await refHelper.getCheckoutInfo(
|
||||||
|
git,
|
||||||
|
'refs/heads/my/branch',
|
||||||
|
commit
|
||||||
|
)
|
||||||
|
expect(checkoutInfo.ref).toBe('my/branch')
|
||||||
|
expect(checkoutInfo.startPoint).toBe('refs/remotes/origin/my/branch')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo refs/pull/', async () => {
|
||||||
|
const checkoutInfo = await refHelper.getCheckoutInfo(
|
||||||
|
git,
|
||||||
|
'refs/pull/123/merge',
|
||||||
|
commit
|
||||||
|
)
|
||||||
|
expect(checkoutInfo.ref).toBe('refs/remotes/pull/123/merge')
|
||||||
|
expect(checkoutInfo.startPoint).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo refs/tags/', async () => {
|
||||||
|
const checkoutInfo = await refHelper.getCheckoutInfo(
|
||||||
|
git,
|
||||||
|
'refs/tags/my-tag',
|
||||||
|
commit
|
||||||
|
)
|
||||||
|
expect(checkoutInfo.ref).toBe('refs/tags/my-tag')
|
||||||
|
expect(checkoutInfo.startPoint).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo unqualified branch only', async () => {
|
||||||
|
git.branchExists = jest.fn(async (remote: boolean, pattern: string) => {
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
const checkoutInfo = await refHelper.getCheckoutInfo(git, 'my/branch', '')
|
||||||
|
|
||||||
|
expect(checkoutInfo.ref).toBe('my/branch')
|
||||||
|
expect(checkoutInfo.startPoint).toBe('refs/remotes/origin/my/branch')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo unqualified tag only', async () => {
|
||||||
|
git.branchExists = jest.fn(async (remote: boolean, pattern: string) => {
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
git.tagExists = jest.fn(async (pattern: string) => {
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
const checkoutInfo = await refHelper.getCheckoutInfo(git, 'my-tag', '')
|
||||||
|
|
||||||
|
expect(checkoutInfo.ref).toBe('refs/tags/my-tag')
|
||||||
|
expect(checkoutInfo.startPoint).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getCheckoutInfo unqualified ref only, not a branch or tag', async () => {
|
||||||
|
git.branchExists = jest.fn(async (remote: boolean, pattern: string) => {
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
git.tagExists = jest.fn(async (pattern: string) => {
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await refHelper.getCheckoutInfo(git, 'my-ref', '')
|
||||||
|
throw new Error('Should not reach here')
|
||||||
|
} catch (err) {
|
||||||
|
expect(err.message).toBe(
|
||||||
|
"A branch or tag with the name 'my-ref' could not be found"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec requires ref or commit', async () => {
|
||||||
|
assert.throws(
|
||||||
|
() => refHelper.getRefSpec('', ''),
|
||||||
|
/Args ref and commit cannot both be empty/
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec sha + refs/heads/', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('refs/heads/my/branch', commit)
|
||||||
|
expect(refSpec.length).toBe(1)
|
||||||
|
expect(refSpec[0]).toBe(`+${commit}:refs/remotes/origin/my/branch`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec sha + refs/pull/', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('refs/pull/123/merge', commit)
|
||||||
|
expect(refSpec.length).toBe(1)
|
||||||
|
expect(refSpec[0]).toBe(`+${commit}:refs/remotes/pull/123/merge`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec sha + refs/tags/', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('refs/tags/my-tag', commit)
|
||||||
|
expect(refSpec.length).toBe(1)
|
||||||
|
expect(refSpec[0]).toBe(`+${commit}:refs/tags/my-tag`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec sha only', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('', commit)
|
||||||
|
expect(refSpec.length).toBe(1)
|
||||||
|
expect(refSpec[0]).toBe(commit)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec unqualified ref only', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('my-ref', '')
|
||||||
|
expect(refSpec.length).toBe(2)
|
||||||
|
expect(refSpec[0]).toBe('+refs/heads/my-ref*:refs/remotes/origin/my-ref*')
|
||||||
|
expect(refSpec[1]).toBe('+refs/tags/my-ref*:refs/tags/my-ref*')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec refs/heads/ only', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('refs/heads/my/branch', '')
|
||||||
|
expect(refSpec.length).toBe(1)
|
||||||
|
expect(refSpec[0]).toBe(
|
||||||
|
'+refs/heads/my/branch:refs/remotes/origin/my/branch'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec refs/pull/ only', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('refs/pull/123/merge', '')
|
||||||
|
expect(refSpec.length).toBe(1)
|
||||||
|
expect(refSpec[0]).toBe('+refs/pull/123/merge:refs/remotes/pull/123/merge')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getRefSpec refs/tags/ only', async () => {
|
||||||
|
const refSpec = refHelper.getRefSpec('refs/tags/my-tag', '')
|
||||||
|
expect(refSpec.length).toBe(1)
|
||||||
|
expect(refSpec[0]).toBe('+refs/tags/my-tag:refs/tags/my-tag')
|
||||||
|
})
|
||||||
|
})
|
||||||
Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ ! -f "./basic/basic-file.txt" ]; then
|
||||||
|
echo "Expected basic file does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify auth token
|
||||||
|
cd basic
|
||||||
|
git fetch
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(git -C ./basic status --porcelain)" != "" ]]; then
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo git status
|
||||||
|
echo ----------------------------------------
|
||||||
|
git status
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo git diff
|
||||||
|
echo ----------------------------------------
|
||||||
|
git diff
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Executable
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ ! -f "./lfs/regular-file.txt" ]; then
|
||||||
|
echo "Expected regular file does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "./lfs/lfs-file.bin" ]; then
|
||||||
|
echo "Expected lfs file does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Executable
+17
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(git status --porcelain)" != "" ]]; then
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo git status
|
||||||
|
echo ----------------------------------------
|
||||||
|
git status
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo git diff
|
||||||
|
echo ----------------------------------------
|
||||||
|
git diff
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo Troubleshooting
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && npm ci && npm run all"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Executable
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ ! -f "./side-by-side-1/side-by-side-test-file-1.txt" ]; then
|
||||||
|
echo "Expected file 1 does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "./side-by-side-2/side-by-side-test-file-2.txt" ]; then
|
||||||
|
echo "Expected file 2 does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ ! -f "./submodules-not-checked-out/regular-file.txt" ]; then
|
||||||
|
echo "Expected regular file does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "./submodules-not-checked-out/submodule-level-1/submodule-file.txt" ]; then
|
||||||
|
echo "Unexpected submodule file exists"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
+20
-15
@@ -1,23 +1,28 @@
|
|||||||
name: 'Checkout'
|
name: 'Checkout'
|
||||||
description: 'Checkout a Git repository.'
|
description: 'Checkout a Git repository'
|
||||||
inputs:
|
inputs:
|
||||||
repository:
|
repository:
|
||||||
description: 'Repository name'
|
description: 'Repository name with owner. For example, actions/checkout'
|
||||||
|
default: ${{ github.repository }}
|
||||||
ref:
|
ref:
|
||||||
description: 'Ref to checkout (SHA, branch, tag)'
|
description: >
|
||||||
|
Ref to checkout (SHA, branch, tag). For the repository that triggered the
|
||||||
|
workflow, defaults to the ref/SHA for the event. Otherwise defaults to master.
|
||||||
token:
|
token:
|
||||||
description: 'Access token for clone repository'
|
description: 'Access token for clone repository'
|
||||||
clean:
|
default: ${{ github.token }}
|
||||||
description: 'If true, execute `execute git clean -ffdx && git reset --hard HEAD` before fetching'
|
|
||||||
default: true
|
|
||||||
submodules:
|
|
||||||
description: 'Whether to include submodules: false to exclude submodules, true to include only one level of submodules, or recursive to recursively clone submodules; defaults to false'
|
|
||||||
lfs:
|
|
||||||
description: 'Whether to download Git-LFS files; defaults to false'
|
|
||||||
fetch-depth:
|
|
||||||
description: 'The depth of commits to ask Git to fetch; defaults to no limit'
|
|
||||||
path:
|
path:
|
||||||
description: 'Optional path to check out source code'
|
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
|
||||||
|
clean:
|
||||||
|
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.'
|
||||||
|
default: 1
|
||||||
|
lfs:
|
||||||
|
description: 'Whether to download Git-LFS files'
|
||||||
|
default: false
|
||||||
runs:
|
runs:
|
||||||
# Plugins live on the runner and are only available to a certain set of first party actions.
|
using: node12
|
||||||
plugin: 'checkout'
|
main: dist/index.js
|
||||||
|
post: dist/index.js
|
||||||
Vendored
+13338
File diff suppressed because one or more lines are too long
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "checkout-git",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"regexp": "^(fatal|error): (.*)$",
|
||||||
|
"message": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module.exports = {
|
||||||
|
clearMocks: true,
|
||||||
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testMatch: ['**/*.test.ts'],
|
||||||
|
testRunner: 'jest-circus/runner',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': 'ts-jest'
|
||||||
|
},
|
||||||
|
verbose: true
|
||||||
|
}
|
||||||
Generated
+7025
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"name": "checkout",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"description": "checkout action",
|
||||||
|
"main": "lib/main.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"format": "prettier --write **/*.ts",
|
||||||
|
"format-check": "prettier --check **/*.ts",
|
||||||
|
"lint": "eslint src/**/*.ts",
|
||||||
|
"pack": "ncc build",
|
||||||
|
"gendocs": "node lib/misc/generate-docs.js",
|
||||||
|
"test": "jest",
|
||||||
|
"all": "npm run build && npm run format && npm run lint && npm run pack && npm run gendocs && npm test"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/actions/checkout.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"github",
|
||||||
|
"actions",
|
||||||
|
"checkout"
|
||||||
|
],
|
||||||
|
"author": "GitHub",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/actions/checkout/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/actions/checkout#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.1.3",
|
||||||
|
"@actions/exec": "^1.0.1",
|
||||||
|
"@actions/github": "^1.1.0",
|
||||||
|
"@actions/io": "^1.0.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jest": "^24.0.23",
|
||||||
|
"@types/node": "^12.7.12",
|
||||||
|
"@typescript-eslint/parser": "^2.8.0",
|
||||||
|
"@zeit/ncc": "^0.20.5",
|
||||||
|
"eslint": "^5.16.0",
|
||||||
|
"eslint-plugin-github": "^2.0.0",
|
||||||
|
"eslint-plugin-jest": "^22.21.0",
|
||||||
|
"jest": "^24.9.0",
|
||||||
|
"jest-circus": "^24.9.0",
|
||||||
|
"js-yaml": "^3.13.1",
|
||||||
|
"prettier": "^1.19.1",
|
||||||
|
"ts-jest": "^24.2.0",
|
||||||
|
"typescript": "^3.6.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import * as fs from 'fs'
|
||||||
|
|
||||||
|
export function directoryExistsSync(path: string, required?: boolean): boolean {
|
||||||
|
if (!path) {
|
||||||
|
throw new Error("Arg 'path' must not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
let stats: fs.Stats
|
||||||
|
try {
|
||||||
|
stats = fs.statSync(path)
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'ENOENT') {
|
||||||
|
if (!required) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Directory '${path}' does not exist`)
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
return true
|
||||||
|
} else if (!required) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Directory '${path}' does not exist`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function existsSync(path: string): boolean {
|
||||||
|
if (!path) {
|
||||||
|
throw new Error("Arg 'path' must not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.statSync(path)
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'ENOENT') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fileExistsSync(path: string): boolean {
|
||||||
|
if (!path) {
|
||||||
|
throw new Error("Arg 'path' must not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
let stats: fs.Stats
|
||||||
|
try {
|
||||||
|
stats = fs.statSync(path)
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'ENOENT') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stats.isDirectory()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -0,0 +1,399 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
|
import * as exec from '@actions/exec' | ||||||