Skip to content

Commit

Permalink
rebase to actions/checkout master and add tests (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankli0324 committed Oct 20, 2023
1 parent 06c6114 commit bca4172
Show file tree
Hide file tree
Showing 24 changed files with 10,099 additions and 25,153 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set Node.js 16.x
- name: Set Node.js 20.x
uses: actions/setup-node@v1
with:
node-version: 16.x
node-version: 20.x

- name: Install dependencies
run: npm ci
Expand Down
39 changes: 38 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 16.x
node-version: 20.x
- uses: actions/checkout@v3
- run: npm ci
- run: npm run build
Expand Down Expand Up @@ -72,6 +72,43 @@ jobs:
shell: bash
run: __test__/verify-side-by-side.sh

# Filter
- name: Fetch filter
uses: ./
with:
filter: 'blob:none'
path: fetch-filter

- name: Verify fetch filter
run: __test__/verify-fetch-filter.sh

# Sparse checkout
- name: Sparse checkout
uses: ./
with:
sparse-checkout: |
__test__
.github
dist
path: sparse-checkout

- name: Verify sparse checkout
run: __test__/verify-sparse-checkout.sh

# Sparse checkout (non-cone mode)
- name: Sparse checkout (non-cone mode)
uses: ./
with:
sparse-checkout: |
/__test__/
/.github/
/dist/
sparse-checkout-cone-mode: false
path: sparse-checkout-non-cone-mode

- name: Verify sparse checkout (non-cone mode)
run: __test__/verify-sparse-checkout-non-cone-mode.sh

# LFS
- name: Checkout LFS
uses: ./
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/update-main-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
type: choice
description: The major version to update
options:
- v4
- v3
- v2

Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## v4.1.0
- [Add support for partial checkout filters](https://github.com/actions/checkout/pull/1396)

## v4.0.0
- [Support fetching without the --progress option](https://github.com/actions/checkout/pull/1067)
- [Update to node20](https://github.com/actions/checkout/pull/1436)

## v3.6.0
- [Fix: Mark test scripts with Bash'isms to be run via Bash](https://github.com/actions/checkout/pull/1377)
- [Add option to fetch tags even if fetch-depth > 0](https://github.com/actions/checkout/pull/579)

## v3.5.3
- [Fix: Checkout fail in self-hosted runners when faulty submodule are checked-in](https://github.com/actions/checkout/pull/1196)
- [Fix typos found by codespell](https://github.com/actions/checkout/pull/1287)
- [Add support for sparse checkouts](https://github.com/actions/checkout/pull/1369)

## v3.5.2
- [Fix api endpoint for GHES](https://github.com/actions/checkout/pull/1289)

Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @actions/actions-runtime
* @actions/actions-launch
87 changes: 70 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
[![Build and Test](https://github.com/actions/checkout/actions/workflows/test.yml/badge.svg)](https://github.com/actions/checkout/actions/workflows/test.yml)

# Checkout V3
# Checkout V4

This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.

Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set `fetch-depth: 0` to fetch all history for all branches and tags. Refer [here](https://help.github.com/en/articles/events-that-trigger-workflows) to learn which commit `$GITHUB_SHA` points to for different events.
Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set `fetch-depth: 0` to fetch all history for all branches and tags. Refer [here](https://docs.github.com/actions/using-workflows/events-that-trigger-workflows) to learn which commit `$GITHUB_SHA` points to for different events.

The auth token is persisted in the local git config. This enables your scripts to run authenticated git commands. The token is removed during post-job cleanup. Set `persist-credentials: false` to opt-out.

When Git 2.18 or higher is not in your PATH, falls back to the REST API to download the files.

# What's new

- Updated to the node16 runtime by default
- This requires a minimum [Actions Runner](https://github.com/actions/runner/releases/tag/v2.285.0) version of v2.285.0 to run, which is by default available in GHES 3.4 or later.
- Updated default runtime to node20
- This requires a minimum Actions Runner version of [v2.308.0](https://github.com/actions/runner/releases/tag/v2.308.0).
- Added support for fetching without the `--progress` option

# Usage

<!-- start usage -->
```yaml
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# Repository name with owner. For example, actions/checkout
# Default: ${{ github.repository }}
Expand Down Expand Up @@ -74,10 +75,31 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
# Default: true
clean: ''

# Partially clone against a given filter. Overrides sparse-checkout if set.
# Default: null
filter: ''

# Do a sparse checkout on given patterns. Each pattern should be separated with
# new lines.
# Default: null
sparse-checkout: ''

# Specifies whether to use cone-mode when doing a sparse checkout.
# Default: true
sparse-checkout-cone-mode: ''

# Number of commits to fetch. 0 indicates all history for all branches and tags.
# Default: 1
fetch-depth: ''

# Whether to fetch tags, even if fetch-depth > 0.
# Default: false
fetch-tags: ''

# Whether to show progress status output when fetching.
# Default: true
show-progress: ''

# Whether to download Git-LFS files
# Default: false
lfs: ''
Expand Down Expand Up @@ -107,6 +129,9 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl

# Scenarios

- [Fetch only the root files](#Fetch-only-the-root-files)
- [Fetch only the root files and `.github` and `src` folder](#Fetch-only-the-root-files-and-github-and-src-folder)
- [Fetch only a single file](#Fetch-only-a-single-file)
- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches)
- [Checkout a different branch](#Checkout-a-different-branch)
- [Checkout HEAD^](#Checkout-HEAD)
Expand All @@ -117,26 +142,54 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
- [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 only the root files

```yaml
- uses: actions/checkout@v4
with:
sparse-checkout: .
```

## Fetch only the root files and `.github` and `src` folder

```yaml
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github
src
```

## Fetch only a single file

```yaml
- uses: actions/checkout@v4
with:
sparse-checkout: |
README.md
sparse-checkout-cone-mode: false
```

## Fetch all history for all tags and branches

```yaml
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
```

## Checkout a different branch

```yaml
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: my-branch
```

## Checkout HEAD^

```yaml
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 2
- run: git checkout HEAD^
Expand All @@ -146,12 +199,12 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl

```yaml
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: main

- name: Checkout tools repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: my-org/my-tools
path: my-tools
Expand All @@ -162,10 +215,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl

```yaml
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Checkout tools repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: my-org/my-tools
path: my-tools
Expand All @@ -176,12 +229,12 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl

```yaml
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: main

- name: Checkout private tools
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: my-org/my-private-tools
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT
Expand All @@ -194,7 +247,7 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
## Checkout pull request HEAD commit instead of merge commit

```yaml
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
```
Expand All @@ -210,7 +263,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
```

## Push a commit using the built-in token
Expand All @@ -221,7 +274,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: |
date > generated.txt
git config user.name github-actions
Expand Down
7 changes: 7 additions & 0 deletions __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ async function setup(testName: string): Promise<void> {
branchDelete: jest.fn(),
branchExists: jest.fn(),
branchList: jest.fn(),
sparseCheckout: jest.fn(),
sparseCheckoutNonConeMode: jest.fn(),
checkout: jest.fn(),
checkoutDetach: jest.fn(),
config: jest.fn(
Expand Down Expand Up @@ -800,7 +802,12 @@ async function setup(testName: string): Promise<void> {
authToken: 'some auth token',
clean: true,
commit: '',
filter: undefined,
sparseCheckout: [],
sparseCheckoutConeMode: true,
fetchDepth: 1,
fetchTags: false,
showProgress: true,
lfs: false,
submodules: false,
nestedSubmodules: false,
Expand Down

0 comments on commit bca4172

Please sign in to comment.