mirror of
https://github.com/actions/checkout.git
synced 2026-06-23 04:21:23 +08:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d668097b24 | |||
| 4edfe9f331 | |||
| 25a956c84d | |||
| 5a4ac9002d | |||
| c952173edf | |||
| a81bbbf829 | |||
| 21dc310f19 | |||
| be6c44d969 | |||
| dac8cc78a1 | |||
| 2036a08e25 | |||
| 592cf69a22 | |||
| a4b69b4886 | |||
| 1433f62caa | |||
| 61b9e3751b | |||
| 28c7f3d2b5 | |||
| fb6f360df2 | |||
| b4483adec3 | |||
| 00a3be8934 | |||
| 453ee27fca | |||
| 65865e15a1 | |||
| aabbfeb2ce | |||
| e52d022eb5 | |||
| 2ff2fbdea4 | |||
| df86c829eb | |||
| 97b30c411c |
@@ -27,6 +27,7 @@
|
|||||||
"@typescript-eslint/no-empty-interface": "error",
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
"@typescript-eslint/no-explicit-any": "error",
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
"@typescript-eslint/no-extraneous-class": "error",
|
"@typescript-eslint/no-extraneous-class": "error",
|
||||||
|
"@typescript-eslint/no-floating-promises": "error",
|
||||||
"@typescript-eslint/no-for-in-array": "error",
|
"@typescript-eslint/no-for-in-array": "error",
|
||||||
"@typescript-eslint/no-inferrable-types": "error",
|
"@typescript-eslint/no-inferrable-types": "error",
|
||||||
"@typescript-eslint/no-misused-new": "error",
|
"@typescript-eslint/no-misused-new": "error",
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
.licenses/** -diff linguist-generated=true
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
name: Licensed
|
||||||
|
|
||||||
|
on:
|
||||||
|
push: {branches: main}
|
||||||
|
pull_request: {branches: main}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Check licenses
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: npm ci
|
||||||
|
- name: Install licensed
|
||||||
|
run: |
|
||||||
|
cd $RUNNER_TEMP
|
||||||
|
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
|
||||||
|
sudo tar -xzf licensed.tar.gz
|
||||||
|
sudo mv licensed /usr/local/bin/licensed
|
||||||
|
- run: licensed status
|
||||||
@@ -4,7 +4,7 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- main
|
||||||
- releases/*
|
- releases/*
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
sources:
|
||||||
|
npm: true
|
||||||
|
|
||||||
|
allowed:
|
||||||
|
- apache-2.0
|
||||||
|
- bsd-2-clause
|
||||||
|
- bsd-3-clause
|
||||||
|
- isc
|
||||||
|
- mit
|
||||||
|
- cc0-1.0
|
||||||
|
- unlicense
|
||||||
|
|
||||||
|
reviewed:
|
||||||
|
npm:
|
||||||
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
@@ -1,6 +1,20 @@
|
|||||||
# Changelog
|
# 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)
|
||||||
|
|
||||||
|
## v2.2.0
|
||||||
|
|
||||||
|
- [Fetch all history for all tags and branches when fetch-depth=0](https://github.com/actions/checkout/pull/258)
|
||||||
|
|
||||||
## v2.1.1
|
## v2.1.1
|
||||||
|
|
||||||
- Changes to support GHES ([here](https://github.com/actions/checkout/pull/236) and [here](https://github.com/actions/checkout/pull/248))
|
- Changes to support GHES ([here](https://github.com/actions/checkout/pull/236) and [here](https://github.com/actions/checkout/pull/248))
|
||||||
|
|
||||||
## v2.1.0
|
## v2.1.0
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
* @actions/actions-runtime
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.
|
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` to fetch more history. 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://help.github.com/en/articles/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.
|
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.
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
|||||||
|
|
||||||
# The branch, tag or SHA to checkout. When checking out the repository that
|
# 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.
|
# triggered a workflow, this defaults to the reference or SHA for that event.
|
||||||
# Otherwise, defaults to `master`.
|
# Otherwise, uses the default branch.
|
||||||
ref: ''
|
ref: ''
|
||||||
|
|
||||||
# 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
|
||||||
@@ -89,7 +89,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
|||||||
# Default: true
|
# Default: true
|
||||||
clean: ''
|
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
|
# Default: 1
|
||||||
fetch-depth: ''
|
fetch-depth: ''
|
||||||
|
|
||||||
@@ -110,6 +110,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
|||||||
|
|
||||||
# Scenarios
|
# Scenarios
|
||||||
|
|
||||||
|
- [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 a different branch](#Checkout-a-different-branch)
|
||||||
- [Checkout HEAD^](#Checkout-HEAD)
|
- [Checkout HEAD^](#Checkout-HEAD)
|
||||||
- [Checkout multiple repos (side by side)](#Checkout-multiple-repos-side-by-side)
|
- [Checkout multiple repos (side by side)](#Checkout-multiple-repos-side-by-side)
|
||||||
@@ -117,9 +118,15 @@ 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)
|
||||||
- [Fetch all tags](#Fetch-all-tags)
|
- [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token)
|
||||||
- [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
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
```
|
||||||
|
|
||||||
## Checkout a different branch
|
## Checkout a different branch
|
||||||
|
|
||||||
@@ -198,7 +205,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
|
|||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [master]
|
branches: [main]
|
||||||
types: [opened, synchronize, closed]
|
types: [opened, synchronize, closed]
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -207,27 +214,22 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
```
|
```
|
||||||
|
|
||||||
## Fetch all tags
|
## Push a commit using the built-in token
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v2
|
on: push
|
||||||
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
jobs:
|
||||||
```
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
## Fetch all branches
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
```yaml
|
- run: |
|
||||||
- uses: actions/checkout@v2
|
date > generated.txt
|
||||||
- run: |
|
git config user.name github-actions
|
||||||
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
|
git config user.email github-actions@github.com
|
||||||
```
|
git add .
|
||||||
|
git commit -m "generated"
|
||||||
## Fetch all history for all tags and branches
|
git push
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- run: |
|
|
||||||
git fetch --prune --unshallow
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|||||||
@@ -714,6 +714,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
),
|
),
|
||||||
env: {},
|
env: {},
|
||||||
fetch: jest.fn(),
|
fetch: jest.fn(),
|
||||||
|
getDefaultBranch: jest.fn(),
|
||||||
getWorkingDirectory: jest.fn(() => workspace),
|
getWorkingDirectory: jest.fn(() => workspace),
|
||||||
init: jest.fn(),
|
init: jest.fn(),
|
||||||
isDetached: jest.fn(),
|
isDetached: jest.fn(),
|
||||||
@@ -722,9 +723,11 @@ async function setup(testName: string): Promise<void> {
|
|||||||
log1: jest.fn(),
|
log1: jest.fn(),
|
||||||
remoteAdd: jest.fn(),
|
remoteAdd: jest.fn(),
|
||||||
removeEnvironmentVariable: jest.fn((name: string) => delete git.env[name]),
|
removeEnvironmentVariable: jest.fn((name: string) => delete git.env[name]),
|
||||||
|
revParse: jest.fn(),
|
||||||
setEnvironmentVariable: jest.fn((name: string, value: string) => {
|
setEnvironmentVariable: jest.fn((name: string, value: string) => {
|
||||||
git.env[name] = value
|
git.env[name] = value
|
||||||
}),
|
}),
|
||||||
|
shaExists: jest.fn(),
|
||||||
submoduleForeach: jest.fn(async () => {
|
submoduleForeach: jest.fn(async () => {
|
||||||
return ''
|
return ''
|
||||||
}),
|
}),
|
||||||
@@ -761,7 +764,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
submodules: false,
|
submodules: false,
|
||||||
nestedSubmodules: false,
|
nestedSubmodules: false,
|
||||||
persistCredentials: true,
|
persistCredentials: true,
|
||||||
ref: 'refs/heads/master',
|
ref: 'refs/heads/main',
|
||||||
repositoryName: 'my-repo',
|
repositoryName: 'my-repo',
|
||||||
repositoryOwner: 'my-org',
|
repositoryOwner: 'my-org',
|
||||||
repositoryPath: '',
|
repositoryPath: '',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper')
|
|||||||
let repositoryPath: string
|
let repositoryPath: string
|
||||||
let repositoryUrl: string
|
let repositoryUrl: string
|
||||||
let clean: boolean
|
let clean: boolean
|
||||||
|
let ref: string
|
||||||
let git: IGitCommandManager
|
let git: IGitCommandManager
|
||||||
|
|
||||||
describe('git-directory-helper tests', () => {
|
describe('git-directory-helper tests', () => {
|
||||||
@@ -41,7 +42,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -63,7 +65,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -88,7 +91,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -109,7 +113,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -137,7 +142,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -163,7 +169,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
differentRepositoryUrl,
|
differentRepositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -187,7 +194,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -212,7 +220,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -236,7 +245,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
undefined,
|
undefined,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -260,7 +270,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -290,7 +301,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -305,29 +317,66 @@ describe('git-directory-helper tests', () => {
|
|||||||
expect(git.tryReset).not.toHaveBeenCalled()
|
expect(git.tryReset).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
const removesRemoteBranches = 'removes local branches'
|
const removesAncestorRemoteBranch = 'removes ancestor remote branch'
|
||||||
it(removesRemoteBranches, async () => {
|
it(removesAncestorRemoteBranch, async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
await setup(removesRemoteBranches)
|
await setup(removesAncestorRemoteBranch)
|
||||||
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
|
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
|
||||||
const mockBranchList = git.branchList as jest.Mock<any, any>
|
const mockBranchList = git.branchList as jest.Mock<any, any>
|
||||||
mockBranchList.mockImplementation(async (remote: boolean) => {
|
mockBranchList.mockImplementation(async (remote: boolean) => {
|
||||||
return remote ? ['remote-branch-1', 'remote-branch-2'] : []
|
return remote ? ['origin/remote-branch-1', 'origin/remote-branch-2'] : []
|
||||||
})
|
})
|
||||||
|
ref = 'remote-branch-1/conflict'
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
clean
|
clean,
|
||||||
|
ref
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
const files = await fs.promises.readdir(repositoryPath)
|
const files = await fs.promises.readdir(repositoryPath)
|
||||||
expect(files.sort()).toEqual(['.git', 'my-file'])
|
expect(files.sort()).toEqual(['.git', 'my-file'])
|
||||||
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-1')
|
expect(git.branchDelete).toHaveBeenCalledTimes(1)
|
||||||
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-2')
|
expect(git.branchDelete).toHaveBeenCalledWith(
|
||||||
|
true,
|
||||||
|
'origin/remote-branch-1'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const removesDescendantRemoteBranches = 'removes descendant remote branch'
|
||||||
|
it(removesDescendantRemoteBranches, async () => {
|
||||||
|
// Arrange
|
||||||
|
await setup(removesDescendantRemoteBranches)
|
||||||
|
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
|
||||||
|
const mockBranchList = git.branchList as jest.Mock<any, any>
|
||||||
|
mockBranchList.mockImplementation(async (remote: boolean) => {
|
||||||
|
return remote
|
||||||
|
? ['origin/remote-branch-1/conflict', 'origin/remote-branch-2']
|
||||||
|
: []
|
||||||
|
})
|
||||||
|
ref = 'remote-branch-1'
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
|
git,
|
||||||
|
repositoryPath,
|
||||||
|
repositoryUrl,
|
||||||
|
clean,
|
||||||
|
ref
|
||||||
|
)
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
const files = await fs.promises.readdir(repositoryPath)
|
||||||
|
expect(files.sort()).toEqual(['.git', 'my-file'])
|
||||||
|
expect(git.branchDelete).toHaveBeenCalledTimes(1)
|
||||||
|
expect(git.branchDelete).toHaveBeenCalledWith(
|
||||||
|
true,
|
||||||
|
'origin/remote-branch-1/conflict'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -344,6 +393,9 @@ async function setup(testName: string): Promise<void> {
|
|||||||
// Clean
|
// Clean
|
||||||
clean = true
|
clean = true
|
||||||
|
|
||||||
|
// Ref
|
||||||
|
ref = ''
|
||||||
|
|
||||||
// Git command manager
|
// Git command manager
|
||||||
git = {
|
git = {
|
||||||
branchDelete: jest.fn(),
|
branchDelete: jest.fn(),
|
||||||
@@ -356,6 +408,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
config: jest.fn(),
|
config: jest.fn(),
|
||||||
configExists: jest.fn(),
|
configExists: jest.fn(),
|
||||||
fetch: jest.fn(),
|
fetch: jest.fn(),
|
||||||
|
getDefaultBranch: jest.fn(),
|
||||||
getWorkingDirectory: jest.fn(() => repositoryPath),
|
getWorkingDirectory: jest.fn(() => repositoryPath),
|
||||||
init: jest.fn(),
|
init: jest.fn(),
|
||||||
isDetached: jest.fn(),
|
isDetached: jest.fn(),
|
||||||
@@ -364,7 +417,9 @@ async function setup(testName: string): Promise<void> {
|
|||||||
log1: jest.fn(),
|
log1: jest.fn(),
|
||||||
remoteAdd: jest.fn(),
|
remoteAdd: jest.fn(),
|
||||||
removeEnvironmentVariable: jest.fn(),
|
removeEnvironmentVariable: jest.fn(),
|
||||||
|
revParse: jest.fn(),
|
||||||
setEnvironmentVariable: jest.fn(),
|
setEnvironmentVariable: jest.fn(),
|
||||||
|
shaExists: jest.fn(),
|
||||||
submoduleForeach: jest.fn(),
|
submoduleForeach: jest.fn(),
|
||||||
submoduleSync: jest.fn(),
|
submoduleSync: jest.fn(),
|
||||||
submoduleUpdate: jest.fn(),
|
submoduleUpdate: jest.fn(),
|
||||||
|
|||||||
@@ -110,13 +110,6 @@ describe('input-helper tests', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets correct default ref/sha for other repo', () => {
|
|
||||||
inputs.repository = 'some-owner/some-other-repo'
|
|
||||||
const settings: IGitSourceSettings = inputHelper.getInputs()
|
|
||||||
expect(settings.ref).toBe('refs/heads/master')
|
|
||||||
expect(settings.commit).toBeFalsy()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('sets ref to empty when explicit sha', () => {
|
it('sets ref to empty when explicit sha', () => {
|
||||||
inputs.ref = '1111111111222222222233333333334444444444'
|
inputs.ref = '1111111111222222222233333333334444444444'
|
||||||
const settings: IGitSourceSettings = inputHelper.getInputs()
|
const settings: IGitSourceSettings = inputHelper.getInputs()
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
mkdir override-git-version
|
mkdir override-git-version
|
||||||
cd override-git-version
|
cd override-git-version
|
||||||
echo @echo override git version 1.2.3 > git.cmd
|
echo @echo override git version 1.2.3 > git.cmd
|
||||||
echo ::add-path::%CD%
|
echo "%CD%" >> $GITHUB_PATH
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ cd override-git-version
|
|||||||
echo "#!/bin/sh" > git
|
echo "#!/bin/sh" > git
|
||||||
echo "echo override git version 1.2.3" >> git
|
echo "echo override git version 1.2.3" >> git
|
||||||
chmod +x git
|
chmod +x git
|
||||||
echo "::add-path::$(pwd)"
|
echo "$(pwd)" >> $GITHUB_PATH
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
@@ -20,5 +20,5 @@ else
|
|||||||
|
|
||||||
# Verify auth token
|
# Verify auth token
|
||||||
cd basic
|
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
|
fi
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ if [[ "$(git status --porcelain)" != "" ]]; then
|
|||||||
echo ----------------------------------------
|
echo ----------------------------------------
|
||||||
echo Troubleshooting
|
echo Troubleshooting
|
||||||
echo ----------------------------------------
|
echo ----------------------------------------
|
||||||
echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && npm ci && npm run all"
|
echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && npm ci && npm run format && npm run build"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@ inputs:
|
|||||||
description: >
|
description: >
|
||||||
The branch, tag or SHA to checkout. When checking out the repository that
|
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
|
triggered a workflow, this defaults to the reference or SHA for that
|
||||||
event. Otherwise, defaults to `master`.
|
event. Otherwise, uses the default branch.
|
||||||
token:
|
token:
|
||||||
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
|
||||||
@@ -54,7 +54,7 @@ inputs:
|
|||||||
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
||||||
default: true
|
default: true
|
||||||
fetch-depth:
|
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
|
default: 1
|
||||||
lfs:
|
lfs:
|
||||||
description: 'Whether to download Git-LFS files'
|
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: >
|
description: >
|
||||||
The branch, tag or SHA to checkout. When checking out the repository that
|
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
|
triggered a workflow, this defaults to the reference or SHA for that
|
||||||
event. Otherwise, defaults to `master`.
|
event. Otherwise, uses the default branch.
|
||||||
token:
|
token:
|
||||||
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
|
||||||
@@ -70,7 +70,7 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
|
|||||||
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
||||||
default: true
|
default: true
|
||||||
fetch-depth:
|
fetch-depth:
|
||||||
description: 'Number of commits to fetch. 0 indicates all history.'
|
description: 'Number of commits to fetch. 0 indicates all history for all tags and branches.'
|
||||||
default: 1
|
default: 1
|
||||||
lfs:
|
lfs:
|
||||||
description: 'Whether to download Git-LFS files'
|
description: 'Whether to download Git-LFS files'
|
||||||
@@ -277,7 +277,7 @@ Note:
|
|||||||
### Branching strategy and release tags
|
### Branching strategy and release tags
|
||||||
|
|
||||||
- Create a servicing branch for V1: `releases/v1`
|
- 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`
|
- Release using a new tag `preview`
|
||||||
- When stable, release using a new tag `v2`
|
- When stable, release using a new tag `v2`
|
||||||
|
|
||||||
|
|||||||
Vendored
+304
-33
@@ -3286,6 +3286,7 @@ function run() {
|
|||||||
try {
|
try {
|
||||||
// Register problem matcher
|
// Register problem matcher
|
||||||
coreCommand.issueCommand('add-matcher', {}, path.join(__dirname, 'problem-matcher.json'));
|
coreCommand.issueCommand('add-matcher', {}, path.join(__dirname, 'problem-matcher.json'));
|
||||||
|
console.log(JSON.stringify(process.env, null, ' '));
|
||||||
// Get sources
|
// Get sources
|
||||||
yield gitSourceProvider.getSource(sourceSettings);
|
yield gitSourceProvider.getSource(sourceSettings);
|
||||||
}
|
}
|
||||||
@@ -3359,7 +3360,7 @@ module.exports = {"name":"@octokit/rest","version":"16.43.1","publishConfig":{"a
|
|||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 227:
|
/***/ 227:
|
||||||
/***/ (function(__unusedmodule, exports) {
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@@ -3372,7 +3373,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const url_1 = __webpack_require__(835);
|
||||||
|
const core = __importStar(__webpack_require__(470));
|
||||||
|
const github = __importStar(__webpack_require__(469));
|
||||||
|
exports.tagsRefSpec = '+refs/tags/*:refs/tags/*';
|
||||||
function getCheckoutInfo(git, ref, commit) {
|
function getCheckoutInfo(git, ref, commit) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (!git) {
|
if (!git) {
|
||||||
@@ -3419,6 +3431,15 @@ function getCheckoutInfo(git, ref, commit) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getCheckoutInfo = getCheckoutInfo;
|
exports.getCheckoutInfo = getCheckoutInfo;
|
||||||
|
function getRefSpecForAllHistory(ref, commit) {
|
||||||
|
const result = ['+refs/heads/*:refs/remotes/origin/*', exports.tagsRefSpec];
|
||||||
|
if (ref && ref.toUpperCase().startsWith('REFS/PULL/')) {
|
||||||
|
const branch = ref.substring('refs/pull/'.length);
|
||||||
|
result.push(`+${commit || ref}:refs/remotes/pull/${branch}`);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
exports.getRefSpecForAllHistory = getRefSpecForAllHistory;
|
||||||
function getRefSpec(ref, commit) {
|
function getRefSpec(ref, commit) {
|
||||||
if (!ref && !commit) {
|
if (!ref && !commit) {
|
||||||
throw new Error('Args ref and commit cannot both be empty');
|
throw new Error('Args ref and commit cannot both be empty');
|
||||||
@@ -3468,6 +3489,129 @@ function getRefSpec(ref, commit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getRefSpec = getRefSpec;
|
exports.getRefSpec = getRefSpec;
|
||||||
|
/**
|
||||||
|
* Tests whether the initial fetch created the ref at the expected commit
|
||||||
|
*/
|
||||||
|
function testRef(git, ref, commit) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!git) {
|
||||||
|
throw new Error('Arg git cannot be empty');
|
||||||
|
}
|
||||||
|
if (!ref && !commit) {
|
||||||
|
throw new Error('Args ref and commit cannot both be empty');
|
||||||
|
}
|
||||||
|
// No SHA? Nothing to test
|
||||||
|
if (!commit) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// SHA only?
|
||||||
|
else if (!ref) {
|
||||||
|
return yield git.shaExists(commit);
|
||||||
|
}
|
||||||
|
const upperRef = ref.toUpperCase();
|
||||||
|
// refs/heads/
|
||||||
|
if (upperRef.startsWith('REFS/HEADS/')) {
|
||||||
|
const branch = ref.substring('refs/heads/'.length);
|
||||||
|
return ((yield git.branchExists(true, `origin/${branch}`)) &&
|
||||||
|
commit === (yield git.revParse(`refs/remotes/origin/${branch}`)));
|
||||||
|
}
|
||||||
|
// refs/pull/
|
||||||
|
else if (upperRef.startsWith('REFS/PULL/')) {
|
||||||
|
// Assume matches because fetched using the commit
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// refs/tags/
|
||||||
|
else if (upperRef.startsWith('REFS/TAGS/')) {
|
||||||
|
const tagName = ref.substring('refs/tags/'.length);
|
||||||
|
return ((yield git.tagExists(tagName)) && commit === (yield git.revParse(ref)));
|
||||||
|
}
|
||||||
|
// Unexpected
|
||||||
|
else {
|
||||||
|
core.debug(`Unexpected ref format '${ref}' when testing ref info`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.testRef = testRef;
|
||||||
|
function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref, commit) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
// GHES?
|
||||||
|
if (isGhes()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Auth token?
|
||||||
|
if (!token) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Public PR synchronize, for workflow repo?
|
||||||
|
if (fromPayload('repository.private') !== false ||
|
||||||
|
github.context.eventName !== 'pull_request' ||
|
||||||
|
fromPayload('action') !== 'synchronize' ||
|
||||||
|
repositoryOwner !== github.context.repo.owner ||
|
||||||
|
repositoryName !== github.context.repo.repo ||
|
||||||
|
ref !== github.context.ref ||
|
||||||
|
!ref.startsWith('refs/pull/') ||
|
||||||
|
commit !== github.context.sha) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Head SHA
|
||||||
|
const expectedHeadSha = fromPayload('after');
|
||||||
|
if (!expectedHeadSha) {
|
||||||
|
core.debug('Unable to determine head sha');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Base SHA
|
||||||
|
const expectedBaseSha = fromPayload('pull_request.base.sha');
|
||||||
|
if (!expectedBaseSha) {
|
||||||
|
core.debug('Unable to determine base sha');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Expected message?
|
||||||
|
const expectedMessage = `Merge ${expectedHeadSha} into ${expectedBaseSha}`;
|
||||||
|
if (commitInfo.indexOf(expectedMessage) >= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Extract details from message
|
||||||
|
const match = commitInfo.match(/Merge ([0-9a-f]{40}) into ([0-9a-f]{40})/);
|
||||||
|
if (!match) {
|
||||||
|
core.debug('Unexpected message format');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Post telemetry
|
||||||
|
const actualHeadSha = match[1];
|
||||||
|
if (actualHeadSha !== expectedHeadSha) {
|
||||||
|
core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`);
|
||||||
|
const octokit = new github.GitHub(token, {
|
||||||
|
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload('number')};run_id=${process.env['GITHUB_RUN_ID']};expected_head_sha=${expectedHeadSha};actual_head_sha=${actualHeadSha})`
|
||||||
|
});
|
||||||
|
yield octokit.repos.get({ owner: repositoryOwner, repo: repositoryName });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
core.debug(`Error when validating commit info: ${err.stack}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.checkCommitInfo = checkCommitInfo;
|
||||||
|
function fromPayload(path) {
|
||||||
|
return select(github.context.payload, path);
|
||||||
|
}
|
||||||
|
function select(obj, path) {
|
||||||
|
if (!obj) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const i = path.indexOf('.');
|
||||||
|
if (i < 0) {
|
||||||
|
return obj[path];
|
||||||
|
}
|
||||||
|
const key = path.substr(0, i);
|
||||||
|
return select(obj[key], path.substr(i + 1));
|
||||||
|
}
|
||||||
|
function isGhes() {
|
||||||
|
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||||
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -5355,7 +5499,7 @@ class GitAuthHelper {
|
|||||||
const configPaths = output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || [];
|
const configPaths = output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || [];
|
||||||
for (const configPath of configPaths) {
|
for (const configPath of configPaths) {
|
||||||
core.debug(`Replacing token placeholder in '${configPath}'`);
|
core.debug(`Replacing token placeholder in '${configPath}'`);
|
||||||
this.replaceTokenPlaceholder(configPath);
|
yield this.replaceTokenPlaceholder(configPath);
|
||||||
}
|
}
|
||||||
if (this.settings.sshKey) {
|
if (this.settings.sshKey) {
|
||||||
// Configure core.sshCommand
|
// Configure core.sshCommand
|
||||||
@@ -5545,6 +5689,7 @@ const exec = __importStar(__webpack_require__(986));
|
|||||||
const fshelper = __importStar(__webpack_require__(618));
|
const fshelper = __importStar(__webpack_require__(618));
|
||||||
const io = __importStar(__webpack_require__(1));
|
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 regexpHelper = __importStar(__webpack_require__(528));
|
const regexpHelper = __importStar(__webpack_require__(528));
|
||||||
const retryHelper = __importStar(__webpack_require__(587));
|
const retryHelper = __importStar(__webpack_require__(587));
|
||||||
const git_version_1 = __webpack_require__(559);
|
const git_version_1 = __webpack_require__(559);
|
||||||
@@ -5660,18 +5805,14 @@ class GitCommandManager {
|
|||||||
return output.exitCode === 0;
|
return output.exitCode === 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fetch(fetchDepth, refSpec) {
|
fetch(refSpec, fetchDepth) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const args = [
|
const args = ['-c', 'protocol.version=2', 'fetch'];
|
||||||
'-c',
|
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
|
||||||
'protocol.version=2',
|
args.push('--no-tags');
|
||||||
'fetch',
|
}
|
||||||
'--no-tags',
|
args.push('--prune', '--progress', '--no-recurse-submodules');
|
||||||
'--prune',
|
if (fetchDepth && fetchDepth > 0) {
|
||||||
'--progress',
|
|
||||||
'--no-recurse-submodules'
|
|
||||||
];
|
|
||||||
if (fetchDepth > 0) {
|
|
||||||
args.push(`--depth=${fetchDepth}`);
|
args.push(`--depth=${fetchDepth}`);
|
||||||
}
|
}
|
||||||
else if (fshelper.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))) {
|
else if (fshelper.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))) {
|
||||||
@@ -5687,6 +5828,33 @@ class GitCommandManager {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
getDefaultBranch(repositoryUrl) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let output;
|
||||||
|
yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
output = yield 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() {
|
getWorkingDirectory() {
|
||||||
return this.workingDirectory;
|
return this.workingDirectory;
|
||||||
}
|
}
|
||||||
@@ -5716,9 +5884,12 @@ class GitCommandManager {
|
|||||||
yield this.execGit(['lfs', 'install', '--local']);
|
yield this.execGit(['lfs', 'install', '--local']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
log1() {
|
log1(format) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
yield this.execGit(['log', '-1']);
|
var args = format ? ['log', '-1', format] : ['log', '-1'];
|
||||||
|
var silent = format ? false : true;
|
||||||
|
const output = yield this.execGit(args, false, silent);
|
||||||
|
return output.stdout;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
remoteAdd(remoteName, remoteUrl) {
|
remoteAdd(remoteName, remoteUrl) {
|
||||||
@@ -5729,9 +5900,28 @@ class GitCommandManager {
|
|||||||
removeEnvironmentVariable(name) {
|
removeEnvironmentVariable(name) {
|
||||||
delete this.gitEnv[name];
|
delete this.gitEnv[name];
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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/main' or '/refs/tags/v1'
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
revParse(ref) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const output = yield this.execGit(['rev-parse', ref]);
|
||||||
|
return output.stdout.trim();
|
||||||
|
});
|
||||||
|
}
|
||||||
setEnvironmentVariable(name, value) {
|
setEnvironmentVariable(name, value) {
|
||||||
this.gitEnv[name] = value;
|
this.gitEnv[name] = value;
|
||||||
}
|
}
|
||||||
|
shaExists(sha) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const args = ['rev-parse', '--verify', '--quiet', `${sha}^{object}`];
|
||||||
|
const output = yield this.execGit(args, true);
|
||||||
|
return output.exitCode === 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
submoduleForeach(command, recursive) {
|
submoduleForeach(command, recursive) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const args = ['submodule', 'foreach'];
|
const args = ['submodule', 'foreach'];
|
||||||
@@ -5820,7 +6010,7 @@ class GitCommandManager {
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
execGit(args, allowAllExitCodes = false) {
|
execGit(args, allowAllExitCodes = false, silent = false) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
fshelper.directoryExistsSync(this.workingDirectory, true);
|
fshelper.directoryExistsSync(this.workingDirectory, true);
|
||||||
const result = new GitOutput();
|
const result = new GitOutput();
|
||||||
@@ -5835,6 +6025,7 @@ class GitCommandManager {
|
|||||||
const options = {
|
const options = {
|
||||||
cwd: this.workingDirectory,
|
cwd: this.workingDirectory,
|
||||||
env,
|
env,
|
||||||
|
silent,
|
||||||
ignoreReturnCode: allowAllExitCodes,
|
ignoreReturnCode: allowAllExitCodes,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data) => {
|
stdout: (data) => {
|
||||||
@@ -5970,7 +6161,7 @@ function getSource(settings) {
|
|||||||
core.endGroup();
|
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, settings.ref);
|
||||||
}
|
}
|
||||||
if (!git) {
|
if (!git) {
|
||||||
// Downloading using REST API
|
// Downloading using REST API
|
||||||
@@ -6006,14 +6197,38 @@ function getSource(settings) {
|
|||||||
core.startGroup('Setting up auth');
|
core.startGroup('Setting up auth');
|
||||||
yield authHelper.configureAuth();
|
yield authHelper.configureAuth();
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
|
// Determine the default branch
|
||||||
|
if (!settings.ref && !settings.commit) {
|
||||||
|
core.startGroup('Determining the default branch');
|
||||||
|
if (settings.sshKey) {
|
||||||
|
settings.ref = yield git.getDefaultBranch(repositoryUrl);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
settings.ref = yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName);
|
||||||
|
}
|
||||||
|
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');
|
core.startGroup('Fetching the repository');
|
||||||
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
|
if (settings.fetchDepth <= 0) {
|
||||||
yield git.fetch(settings.fetchDepth, refSpec);
|
// Fetch all branches and tags
|
||||||
|
let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit);
|
||||||
|
yield git.fetch(refSpec);
|
||||||
|
// When all history is fetched, the ref we're interested in may have moved to a different
|
||||||
|
// commit (push or force push). If so, fetch again with a targeted refspec.
|
||||||
|
if (!(yield refHelper.testRef(git, settings.ref, settings.commit))) {
|
||||||
|
refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
|
||||||
|
yield git.fetch(refSpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
|
||||||
|
yield git.fetch(refSpec, settings.fetchDepth);
|
||||||
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// Checkout info
|
// Checkout info
|
||||||
core.startGroup('Determining the checkout info');
|
core.startGroup('Determining the checkout info');
|
||||||
@@ -6056,8 +6271,12 @@ function getSource(settings) {
|
|||||||
yield authHelper.removeGlobalAuth();
|
yield authHelper.removeGlobalAuth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Dump some info about the checked out commit
|
// Get commit information
|
||||||
yield git.log1();
|
const commitInfo = yield git.log1();
|
||||||
|
// Log commit sha
|
||||||
|
yield git.log1("--format='%H'");
|
||||||
|
// Check for incorrect pull request merge commit
|
||||||
|
yield refHelper.checkCommitInfo(settings.authToken, commitInfo, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Remove auth
|
// Remove auth
|
||||||
@@ -7362,7 +7581,7 @@ const fs = __importStar(__webpack_require__(747));
|
|||||||
const fsHelper = __importStar(__webpack_require__(618));
|
const fsHelper = __importStar(__webpack_require__(618));
|
||||||
const io = __importStar(__webpack_require__(1));
|
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, ref) {
|
||||||
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(repositoryPath, 'Expected repositoryPath to be defined');
|
||||||
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined');
|
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined');
|
||||||
@@ -7402,10 +7621,24 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
|
|||||||
for (const branch of branches) {
|
for (const branch of branches) {
|
||||||
yield git.branchDelete(false, branch);
|
yield git.branchDelete(false, branch);
|
||||||
}
|
}
|
||||||
// Remove all refs/remotes/origin/* to avoid conflicts
|
// Remove any conflicting refs/remotes/origin/*
|
||||||
branches = yield git.branchList(true);
|
// Example 1: Consider ref is refs/heads/foo and previously fetched refs/remotes/origin/foo/bar
|
||||||
for (const branch of branches) {
|
// Example 2: Consider ref is refs/heads/foo/bar and previously fetched refs/remotes/origin/foo
|
||||||
yield git.branchDelete(true, branch);
|
if (ref) {
|
||||||
|
ref = ref.startsWith('refs/') ? ref : `refs/heads/${ref}`;
|
||||||
|
if (ref.startsWith('refs/heads/')) {
|
||||||
|
const upperName1 = ref.toUpperCase().substr('REFS/HEADS/'.length);
|
||||||
|
const upperName1Slash = `${upperName1}/`;
|
||||||
|
branches = yield git.branchList(true);
|
||||||
|
for (const branch of branches) {
|
||||||
|
const upperName2 = branch.substr('origin/'.length).toUpperCase();
|
||||||
|
const upperName2Slash = `${upperName2}/`;
|
||||||
|
if (upperName1.startsWith(upperName2Slash) ||
|
||||||
|
upperName2.startsWith(upperName1Slash)) {
|
||||||
|
yield git.branchDelete(true, branch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// Clean
|
// Clean
|
||||||
@@ -9336,6 +9569,11 @@ 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) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Determine the default branch
|
||||||
|
if (!ref && !commit) {
|
||||||
|
core.info('Determining the default branch');
|
||||||
|
ref = yield getDefaultBranch(authToken, owner, repo);
|
||||||
|
}
|
||||||
// Download the archive
|
// Download the archive
|
||||||
let archiveData = yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
let archiveData = yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info('Downloading the archive');
|
core.info('Downloading the archive');
|
||||||
@@ -9357,7 +9595,7 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath)
|
|||||||
else {
|
else {
|
||||||
yield toolCache.extractTar(archivePath, extractPath);
|
yield toolCache.extractTar(archivePath, extractPath);
|
||||||
}
|
}
|
||||||
io.rmRF(archivePath);
|
yield io.rmRF(archivePath);
|
||||||
// Determine the path of the repository content. The archive contains
|
// Determine the path of the repository content. The archive contains
|
||||||
// a top-level folder and the repository content is inside.
|
// a top-level folder and the repository content is inside.
|
||||||
const archiveFileNames = yield fs.promises.readdir(extractPath);
|
const archiveFileNames = yield fs.promises.readdir(extractPath);
|
||||||
@@ -9376,10 +9614,46 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath)
|
|||||||
yield io.mv(sourcePath, targetPath);
|
yield io.mv(sourcePath, targetPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
io.rmRF(extractPath);
|
yield io.rmRF(extractPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.downloadRepository = downloadRepository;
|
exports.downloadRepository = downloadRepository;
|
||||||
|
/**
|
||||||
|
* Looks up the default branch name
|
||||||
|
*/
|
||||||
|
function getDefaultBranch(authToken, owner, repo) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info('Retrieving the default branch name');
|
||||||
|
const octokit = new github.GitHub(authToken);
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
// Get the default branch from the repo info
|
||||||
|
const response = yield 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
|
||||||
|
core.info(`Default branch '${result}'`);
|
||||||
|
// Prefix with 'refs/heads'
|
||||||
|
if (!result.startsWith('refs/')) {
|
||||||
|
result = `refs/heads/${result}`;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.getDefaultBranch = getDefaultBranch;
|
||||||
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);
|
||||||
@@ -14277,14 +14551,11 @@ function getInputs() {
|
|||||||
result.ref = github.context.ref;
|
result.ref = github.context.ref;
|
||||||
result.commit = github.context.sha;
|
result.commit = github.context.sha;
|
||||||
// Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
|
// 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/')) {
|
if (result.commit && result.ref && !result.ref.startsWith('refs/')) {
|
||||||
result.ref = `refs/heads/${result.ref}`;
|
result.ref = `refs/heads/${result.ref}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!result.ref && !result.commit) {
|
|
||||||
result.ref = 'refs/heads/master';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// SHA?
|
// SHA?
|
||||||
else if (result.ref.match(/^[0-9a-fA-F]{40}$/)) {
|
else if (result.ref.match(/^[0-9a-fA-F]{40}$/)) {
|
||||||
@@ -14319,7 +14590,7 @@ function getInputs() {
|
|||||||
core.debug(`submodules = ${result.submodules}`);
|
core.debug(`submodules = ${result.submodules}`);
|
||||||
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
|
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
|
||||||
// Auth token
|
// Auth token
|
||||||
result.authToken = core.getInput('token');
|
result.authToken = core.getInput('token', { required: true });
|
||||||
// SSH
|
// SSH
|
||||||
result.sshKey = core.getInput('ssh-key');
|
result.sshKey = core.getInput('ssh-key');
|
||||||
result.sshKnownHosts = core.getInput('ssh-known-hosts');
|
result.sshKnownHosts = core.getInput('ssh-known-hosts');
|
||||||
|
|||||||
+2
-2
@@ -5,8 +5,8 @@
|
|||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && ncc build && node lib/misc/generate-docs.js",
|
"build": "tsc && ncc build && node lib/misc/generate-docs.js",
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write '**/*.ts'",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check '**/*.ts'",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ class GitAuthHelper {
|
|||||||
output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || []
|
output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || []
|
||||||
for (const configPath of configPaths) {
|
for (const configPath of configPaths) {
|
||||||
core.debug(`Replacing token placeholder in '${configPath}'`)
|
core.debug(`Replacing token placeholder in '${configPath}'`)
|
||||||
this.replaceTokenPlaceholder(configPath)
|
await this.replaceTokenPlaceholder(configPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.settings.sshKey) {
|
if (this.settings.sshKey) {
|
||||||
|
|||||||
+67
-16
@@ -3,6 +3,7 @@ import * as exec from '@actions/exec'
|
|||||||
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 * as refHelper from './ref-helper'
|
||||||
import * as regexpHelper from './regexp-helper'
|
import * as regexpHelper from './regexp-helper'
|
||||||
import * as retryHelper from './retry-helper'
|
import * as retryHelper from './retry-helper'
|
||||||
import {GitVersion} from './git-version'
|
import {GitVersion} from './git-version'
|
||||||
@@ -23,16 +24,19 @@ export interface IGitCommandManager {
|
|||||||
globalConfig?: boolean
|
globalConfig?: boolean
|
||||||
): Promise<void>
|
): Promise<void>
|
||||||
configExists(configKey: string, globalConfig?: boolean): Promise<boolean>
|
configExists(configKey: string, globalConfig?: boolean): Promise<boolean>
|
||||||
fetch(fetchDepth: number, refSpec: string[]): Promise<void>
|
fetch(refSpec: string[], fetchDepth?: number): Promise<void>
|
||||||
|
getDefaultBranch(repositoryUrl: string): Promise<string>
|
||||||
getWorkingDirectory(): string
|
getWorkingDirectory(): string
|
||||||
init(): Promise<void>
|
init(): Promise<void>
|
||||||
isDetached(): Promise<boolean>
|
isDetached(): Promise<boolean>
|
||||||
lfsFetch(ref: string): Promise<void>
|
lfsFetch(ref: string): Promise<void>
|
||||||
lfsInstall(): Promise<void>
|
lfsInstall(): Promise<void>
|
||||||
log1(): Promise<void>
|
log1(format?: string): Promise<string>
|
||||||
remoteAdd(remoteName: string, remoteUrl: string): Promise<void>
|
remoteAdd(remoteName: string, remoteUrl: string): Promise<void>
|
||||||
removeEnvironmentVariable(name: string): void
|
removeEnvironmentVariable(name: string): void
|
||||||
|
revParse(ref: string): Promise<string>
|
||||||
setEnvironmentVariable(name: string, value: string): void
|
setEnvironmentVariable(name: string, value: string): void
|
||||||
|
shaExists(sha: string): Promise<boolean>
|
||||||
submoduleForeach(command: string, recursive: boolean): Promise<string>
|
submoduleForeach(command: string, recursive: boolean): Promise<string>
|
||||||
submoduleSync(recursive: boolean): Promise<void>
|
submoduleSync(recursive: boolean): Promise<void>
|
||||||
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
|
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
|
||||||
@@ -164,17 +168,14 @@ class GitCommandManager {
|
|||||||
return output.exitCode === 0
|
return output.exitCode === 0
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetch(fetchDepth: number, refSpec: string[]): Promise<void> {
|
async fetch(refSpec: string[], fetchDepth?: number): Promise<void> {
|
||||||
const args = [
|
const args = ['-c', 'protocol.version=2', 'fetch']
|
||||||
'-c',
|
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
|
||||||
'protocol.version=2',
|
args.push('--no-tags')
|
||||||
'fetch',
|
}
|
||||||
'--no-tags',
|
|
||||||
'--prune',
|
args.push('--prune', '--progress', '--no-recurse-submodules')
|
||||||
'--progress',
|
if (fetchDepth && fetchDepth > 0) {
|
||||||
'--no-recurse-submodules'
|
|
||||||
]
|
|
||||||
if (fetchDepth > 0) {
|
|
||||||
args.push(`--depth=${fetchDepth}`)
|
args.push(`--depth=${fetchDepth}`)
|
||||||
} else if (
|
} else if (
|
||||||
fshelper.fileExistsSync(
|
fshelper.fileExistsSync(
|
||||||
@@ -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 {
|
getWorkingDirectory(): string {
|
||||||
return this.workingDirectory
|
return this.workingDirectory
|
||||||
}
|
}
|
||||||
@@ -225,8 +254,11 @@ class GitCommandManager {
|
|||||||
await this.execGit(['lfs', 'install', '--local'])
|
await this.execGit(['lfs', 'install', '--local'])
|
||||||
}
|
}
|
||||||
|
|
||||||
async log1(): Promise<void> {
|
async log1(format?: string): Promise<string> {
|
||||||
await this.execGit(['log', '-1'])
|
var args = format ? ['log', '-1', format] : ['log', '-1']
|
||||||
|
var silent = format ? false : true
|
||||||
|
const output = await this.execGit(args, false, silent)
|
||||||
|
return output.stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
async remoteAdd(remoteName: string, remoteUrl: string): Promise<void> {
|
async remoteAdd(remoteName: string, remoteUrl: string): Promise<void> {
|
||||||
@@ -237,10 +269,27 @@ class GitCommandManager {
|
|||||||
delete this.gitEnv[name]
|
delete this.gitEnv[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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/main' or '/refs/tags/v1'
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
async revParse(ref: string): Promise<string> {
|
||||||
|
const output = await this.execGit(['rev-parse', ref])
|
||||||
|
return output.stdout.trim()
|
||||||
|
}
|
||||||
|
|
||||||
setEnvironmentVariable(name: string, value: string): void {
|
setEnvironmentVariable(name: string, value: string): void {
|
||||||
this.gitEnv[name] = value
|
this.gitEnv[name] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async shaExists(sha: string): Promise<boolean> {
|
||||||
|
const args = ['rev-parse', '--verify', '--quiet', `${sha}^{object}`]
|
||||||
|
const output = await this.execGit(args, true)
|
||||||
|
return output.exitCode === 0
|
||||||
|
}
|
||||||
|
|
||||||
async submoduleForeach(command: string, recursive: boolean): Promise<string> {
|
async submoduleForeach(command: string, recursive: boolean): Promise<string> {
|
||||||
const args = ['submodule', 'foreach']
|
const args = ['submodule', 'foreach']
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
@@ -343,7 +392,8 @@ class GitCommandManager {
|
|||||||
|
|
||||||
private async execGit(
|
private async execGit(
|
||||||
args: string[],
|
args: string[],
|
||||||
allowAllExitCodes = false
|
allowAllExitCodes = false,
|
||||||
|
silent = false
|
||||||
): Promise<GitOutput> {
|
): Promise<GitOutput> {
|
||||||
fshelper.directoryExistsSync(this.workingDirectory, true)
|
fshelper.directoryExistsSync(this.workingDirectory, true)
|
||||||
|
|
||||||
@@ -362,6 +412,7 @@ class GitCommandManager {
|
|||||||
const options = {
|
const options = {
|
||||||
cwd: this.workingDirectory,
|
cwd: this.workingDirectory,
|
||||||
env,
|
env,
|
||||||
|
silent,
|
||||||
ignoreReturnCode: allowAllExitCodes,
|
ignoreReturnCode: allowAllExitCodes,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ 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,
|
||||||
repositoryPath: string,
|
repositoryPath: string,
|
||||||
repositoryUrl: string,
|
repositoryUrl: string,
|
||||||
clean: boolean
|
clean: boolean,
|
||||||
|
ref: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
|
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
|
||||||
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined')
|
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined')
|
||||||
@@ -56,10 +56,26 @@ export async function prepareExistingDirectory(
|
|||||||
await git.branchDelete(false, branch)
|
await git.branchDelete(false, branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all refs/remotes/origin/* to avoid conflicts
|
// Remove any conflicting refs/remotes/origin/*
|
||||||
branches = await git.branchList(true)
|
// Example 1: Consider ref is refs/heads/foo and previously fetched refs/remotes/origin/foo/bar
|
||||||
for (const branch of branches) {
|
// Example 2: Consider ref is refs/heads/foo/bar and previously fetched refs/remotes/origin/foo
|
||||||
await git.branchDelete(true, branch)
|
if (ref) {
|
||||||
|
ref = ref.startsWith('refs/') ? ref : `refs/heads/${ref}`
|
||||||
|
if (ref.startsWith('refs/heads/')) {
|
||||||
|
const upperName1 = ref.toUpperCase().substr('REFS/HEADS/'.length)
|
||||||
|
const upperName1Slash = `${upperName1}/`
|
||||||
|
branches = await git.branchList(true)
|
||||||
|
for (const branch of branches) {
|
||||||
|
const upperName2 = branch.substr('origin/'.length).toUpperCase()
|
||||||
|
const upperName2Slash = `${upperName2}/`
|
||||||
|
if (
|
||||||
|
upperName1.startsWith(upperName2Slash) ||
|
||||||
|
upperName2.startsWith(upperName1Slash)
|
||||||
|
) {
|
||||||
|
await git.branchDelete(true, branch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||||||
git,
|
git,
|
||||||
settings.repositoryPath,
|
settings.repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
settings.clean
|
settings.clean,
|
||||||
|
settings.ref
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +103,21 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||||||
await authHelper.configureAuth()
|
await authHelper.configureAuth()
|
||||||
core.endGroup()
|
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
|
// LFS install
|
||||||
if (settings.lfs) {
|
if (settings.lfs) {
|
||||||
await git.lfsInstall()
|
await git.lfsInstall()
|
||||||
@@ -109,8 +125,24 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||||||
|
|
||||||
// Fetch
|
// Fetch
|
||||||
core.startGroup('Fetching the repository')
|
core.startGroup('Fetching the repository')
|
||||||
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
|
if (settings.fetchDepth <= 0) {
|
||||||
await git.fetch(settings.fetchDepth, refSpec)
|
// Fetch all branches and tags
|
||||||
|
let refSpec = refHelper.getRefSpecForAllHistory(
|
||||||
|
settings.ref,
|
||||||
|
settings.commit
|
||||||
|
)
|
||||||
|
await git.fetch(refSpec)
|
||||||
|
|
||||||
|
// When all history is fetched, the ref we're interested in may have moved to a different
|
||||||
|
// commit (push or force push). If so, fetch again with a targeted refspec.
|
||||||
|
if (!(await refHelper.testRef(git, settings.ref, settings.commit))) {
|
||||||
|
refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
|
||||||
|
await git.fetch(refSpec)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
|
||||||
|
await git.fetch(refSpec, settings.fetchDepth)
|
||||||
|
}
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
// Checkout info
|
// Checkout info
|
||||||
@@ -169,8 +201,21 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump some info about the checked out commit
|
// Get commit information
|
||||||
await git.log1()
|
const commitInfo = await git.log1()
|
||||||
|
|
||||||
|
// Log commit sha
|
||||||
|
await git.log1("--format='%H'")
|
||||||
|
|
||||||
|
// Check for incorrect pull request merge commit
|
||||||
|
await refHelper.checkCommitInfo(
|
||||||
|
settings.authToken,
|
||||||
|
commitInfo,
|
||||||
|
settings.repositoryOwner,
|
||||||
|
settings.repositoryName,
|
||||||
|
settings.ref,
|
||||||
|
settings.commit
|
||||||
|
)
|
||||||
} finally {
|
} finally {
|
||||||
// Remove auth
|
// Remove auth
|
||||||
if (!settings.persistCredentials) {
|
if (!settings.persistCredentials) {
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ export async function downloadRepository(
|
|||||||
commit: string,
|
commit: string,
|
||||||
repositoryPath: string
|
repositoryPath: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
// Determine the default branch
|
||||||
|
if (!ref && !commit) {
|
||||||
|
core.info('Determining the default branch')
|
||||||
|
ref = await getDefaultBranch(authToken, owner, repo)
|
||||||
|
}
|
||||||
|
|
||||||
// Download the archive
|
// Download the archive
|
||||||
let archiveData = await retryHelper.execute(async () => {
|
let archiveData = await retryHelper.execute(async () => {
|
||||||
core.info('Downloading the archive')
|
core.info('Downloading the archive')
|
||||||
@@ -41,7 +47,7 @@ export async function downloadRepository(
|
|||||||
} else {
|
} else {
|
||||||
await toolCache.extractTar(archivePath, extractPath)
|
await toolCache.extractTar(archivePath, extractPath)
|
||||||
}
|
}
|
||||||
io.rmRF(archivePath)
|
await io.rmRF(archivePath)
|
||||||
|
|
||||||
// Determine the path of the repository content. The archive contains
|
// Determine the path of the repository content. The archive contains
|
||||||
// a top-level folder and the repository content is inside.
|
// a top-level folder and the repository content is inside.
|
||||||
@@ -64,7 +70,47 @@ export async function downloadRepository(
|
|||||||
await io.mv(sourcePath, targetPath)
|
await io.mv(sourcePath, targetPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
io.rmRF(extractPath)
|
await io.rmRF(extractPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks up the default branch name
|
||||||
|
*/
|
||||||
|
export async function getDefaultBranch(
|
||||||
|
authToken: string,
|
||||||
|
owner: string,
|
||||||
|
repo: string
|
||||||
|
): Promise<string> {
|
||||||
|
return await retryHelper.execute(async () => {
|
||||||
|
core.info('Retrieving the default branch name')
|
||||||
|
const octokit = new github.GitHub(authToken)
|
||||||
|
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
|
||||||
|
core.info(`Default branch '${result}'`)
|
||||||
|
|
||||||
|
// Prefix with 'refs/heads'
|
||||||
|
if (!result.startsWith('refs/')) {
|
||||||
|
result = `refs/heads/${result}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadArchive(
|
async function downloadArchive(
|
||||||
|
|||||||
+2
-6
@@ -63,15 +63,11 @@ export function getInputs(): IGitSourceSettings {
|
|||||||
result.commit = github.context.sha
|
result.commit = github.context.sha
|
||||||
|
|
||||||
// Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
|
// 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/')) {
|
if (result.commit && result.ref && !result.ref.startsWith('refs/')) {
|
||||||
result.ref = `refs/heads/${result.ref}`
|
result.ref = `refs/heads/${result.ref}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.ref && !result.commit) {
|
|
||||||
result.ref = 'refs/heads/master'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// SHA?
|
// SHA?
|
||||||
else if (result.ref.match(/^[0-9a-fA-F]{40}$/)) {
|
else if (result.ref.match(/^[0-9a-fA-F]{40}$/)) {
|
||||||
@@ -110,7 +106,7 @@ export function getInputs(): IGitSourceSettings {
|
|||||||
core.debug(`recursive submodules = ${result.nestedSubmodules}`)
|
core.debug(`recursive submodules = ${result.nestedSubmodules}`)
|
||||||
|
|
||||||
// Auth token
|
// Auth token
|
||||||
result.authToken = core.getInput('token')
|
result.authToken = core.getInput('token', {required: true})
|
||||||
|
|
||||||
// SSH
|
// SSH
|
||||||
result.sshKey = core.getInput('ssh-key')
|
result.sshKey = core.getInput('ssh-key')
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ async function run(): Promise<void> {
|
|||||||
path.join(__dirname, 'problem-matcher.json')
|
path.join(__dirname, 'problem-matcher.json')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.log(JSON.stringify(process.env, null, ' '))
|
||||||
|
|
||||||
// Get sources
|
// Get sources
|
||||||
await gitSourceProvider.getSource(sourceSettings)
|
await gitSourceProvider.getSource(sourceSettings)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
|
import {URL} from 'url'
|
||||||
import {IGitCommandManager} from './git-command-manager'
|
import {IGitCommandManager} from './git-command-manager'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
import * as github from '@actions/github'
|
||||||
|
|
||||||
|
export const tagsRefSpec = '+refs/tags/*:refs/tags/*'
|
||||||
|
|
||||||
export interface ICheckoutInfo {
|
export interface ICheckoutInfo {
|
||||||
ref: string
|
ref: string
|
||||||
@@ -57,6 +62,16 @@ export async function getCheckoutInfo(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRefSpecForAllHistory(ref: string, commit: string): string[] {
|
||||||
|
const result = ['+refs/heads/*:refs/remotes/origin/*', tagsRefSpec]
|
||||||
|
if (ref && ref.toUpperCase().startsWith('REFS/PULL/')) {
|
||||||
|
const branch = ref.substring('refs/pull/'.length)
|
||||||
|
result.push(`+${commit || ref}:refs/remotes/pull/${branch}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
export function getRefSpec(ref: string, commit: string): string[] {
|
export function getRefSpec(ref: string, commit: string): string[] {
|
||||||
if (!ref && !commit) {
|
if (!ref && !commit) {
|
||||||
throw new Error('Args ref and commit cannot both be empty')
|
throw new Error('Args ref and commit cannot both be empty')
|
||||||
@@ -107,3 +122,162 @@ export function getRefSpec(ref: string, commit: string): string[] {
|
|||||||
return [`+${ref}:${ref}`]
|
return [`+${ref}:${ref}`]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the initial fetch created the ref at the expected commit
|
||||||
|
*/
|
||||||
|
export async function testRef(
|
||||||
|
git: IGitCommandManager,
|
||||||
|
ref: string,
|
||||||
|
commit: string
|
||||||
|
): Promise<boolean> {
|
||||||
|
if (!git) {
|
||||||
|
throw new Error('Arg git cannot be empty')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ref && !commit) {
|
||||||
|
throw new Error('Args ref and commit cannot both be empty')
|
||||||
|
}
|
||||||
|
|
||||||
|
// No SHA? Nothing to test
|
||||||
|
if (!commit) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// SHA only?
|
||||||
|
else if (!ref) {
|
||||||
|
return await git.shaExists(commit)
|
||||||
|
}
|
||||||
|
|
||||||
|
const upperRef = ref.toUpperCase()
|
||||||
|
|
||||||
|
// refs/heads/
|
||||||
|
if (upperRef.startsWith('REFS/HEADS/')) {
|
||||||
|
const branch = ref.substring('refs/heads/'.length)
|
||||||
|
return (
|
||||||
|
(await git.branchExists(true, `origin/${branch}`)) &&
|
||||||
|
commit === (await git.revParse(`refs/remotes/origin/${branch}`))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// refs/pull/
|
||||||
|
else if (upperRef.startsWith('REFS/PULL/')) {
|
||||||
|
// Assume matches because fetched using the commit
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// refs/tags/
|
||||||
|
else if (upperRef.startsWith('REFS/TAGS/')) {
|
||||||
|
const tagName = ref.substring('refs/tags/'.length)
|
||||||
|
return (
|
||||||
|
(await git.tagExists(tagName)) && commit === (await git.revParse(ref))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// Unexpected
|
||||||
|
else {
|
||||||
|
core.debug(`Unexpected ref format '${ref}' when testing ref info`)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkCommitInfo(
|
||||||
|
token: string,
|
||||||
|
commitInfo: string,
|
||||||
|
repositoryOwner: string,
|
||||||
|
repositoryName: string,
|
||||||
|
ref: string,
|
||||||
|
commit: string
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
// GHES?
|
||||||
|
if (isGhes()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auth token?
|
||||||
|
if (!token) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public PR synchronize, for workflow repo?
|
||||||
|
if (
|
||||||
|
fromPayload('repository.private') !== false ||
|
||||||
|
github.context.eventName !== 'pull_request' ||
|
||||||
|
fromPayload('action') !== 'synchronize' ||
|
||||||
|
repositoryOwner !== github.context.repo.owner ||
|
||||||
|
repositoryName !== github.context.repo.repo ||
|
||||||
|
ref !== github.context.ref ||
|
||||||
|
!ref.startsWith('refs/pull/') ||
|
||||||
|
commit !== github.context.sha
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Head SHA
|
||||||
|
const expectedHeadSha = fromPayload('after')
|
||||||
|
if (!expectedHeadSha) {
|
||||||
|
core.debug('Unable to determine head sha')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Base SHA
|
||||||
|
const expectedBaseSha = fromPayload('pull_request.base.sha')
|
||||||
|
if (!expectedBaseSha) {
|
||||||
|
core.debug('Unable to determine base sha')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expected message?
|
||||||
|
const expectedMessage = `Merge ${expectedHeadSha} into ${expectedBaseSha}`
|
||||||
|
if (commitInfo.indexOf(expectedMessage) >= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract details from message
|
||||||
|
const match = commitInfo.match(/Merge ([0-9a-f]{40}) into ([0-9a-f]{40})/)
|
||||||
|
if (!match) {
|
||||||
|
core.debug('Unexpected message format')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Post telemetry
|
||||||
|
const actualHeadSha = match[1]
|
||||||
|
if (actualHeadSha !== expectedHeadSha) {
|
||||||
|
core.debug(
|
||||||
|
`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`
|
||||||
|
)
|
||||||
|
const octokit = new github.GitHub(token, {
|
||||||
|
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
|
||||||
|
'number'
|
||||||
|
)};run_id=${
|
||||||
|
process.env['GITHUB_RUN_ID']
|
||||||
|
};expected_head_sha=${expectedHeadSha};actual_head_sha=${actualHeadSha})`
|
||||||
|
})
|
||||||
|
await octokit.repos.get({owner: repositoryOwner, repo: repositoryName})
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
core.debug(`Error when validating commit info: ${err.stack}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromPayload(path: string): any {
|
||||||
|
return select(github.context.payload, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
function select(obj: any, path: string): any {
|
||||||
|
if (!obj) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const i = path.indexOf('.')
|
||||||
|
if (i < 0) {
|
||||||
|
return obj[path]
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = path.substr(0, i)
|
||||||
|
return select(obj[key], path.substr(i + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
function isGhes(): boolean {
|
||||||
|
const ghUrl = new URL(
|
||||||
|
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
|
)
|
||||||
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user