Skip to content

Commit

Permalink
Convert checkout to a regular action (actions#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsciple authored Dec 3, 2019
1 parent 50fbc62 commit e347bba
Show file tree
Hide file tree
Showing 33 changed files with 22,253 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
58 changes: 58 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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
}
}
80 changes: 72 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,83 @@
name: "test-local"
name: Build and Test

on:
pull_request:
push:
branches:
- master
- 'releases/*'
- releases/*

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:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macOS-latest]
runs-on: ${{ matrix.os }}
runs-on: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}

steps:
- uses: actions/checkout@master
- uses: ./
with:
ref: master
# Clone this repo
- name: Checkout
uses: actions/checkout@v1 # todo: switch to V2

# 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
node_modules/
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
26 changes: 18 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Changelog

## Unreleased Changes
- N/A
## v2 (preview)

## v1.2.0
- Reverted the breaking behavior change in v1.1.0 that broke custom authentication flows
- 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`

## 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
- Initial Release of the checkout action
## v1

Refer [here](https://github.com/actions/checkout/blob/v1/CHANGELOG.md) for the V1 changelog
72 changes: 41 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,70 @@
<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>

# Checkout
# Checkout V2 (preview)

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.
See [here](https://help.github.com/en/articles/events-that-trigger-workflows) to learn what `$GITHUB_SHA` is for different kinds of events.
By default, the repository that triggered the workflow is checked-out, for the ref/SHA that triggered the event.

# Usage
Refer [here](https://help.github.com/en/articles/events-that-trigger-workflows) to learn which commit `$GITHUB_SHA` points to for different events.

See [action.yml](action.yml)
Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous versions.

Basic:
# Usage

<!-- start usage -->
```yaml
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@preview
with:
node-version: 10.x
- run: npm install
- run: npm test
# Repository name
# Default: ${{ github.repository }}
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
- uses: actions/checkout@v1
- uses: actions/checkout@preview
with:
ref: some-branch
```
## Checkout different private repository
## Checkout a different, private repository
```yaml
- uses: actions/checkout@v1
- uses: actions/checkout@preview
with:
repository: myAccount/myRepository
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).

## 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

The scripts and documentation in this project are released under the [MIT License](LICENSE)
45 changes: 45 additions & 0 deletions __test__/git-version.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
Loading

0 comments on commit e347bba

Please sign in to comment.