mirror of
https://gitea.com/actions/checkout.git
synced 2024-11-10 02:35:56 +01:00
fallback to REST API to download repo
This commit is contained in:
parent
5881116d18
commit
ad6dd29a96
6 changed files with 666 additions and 729 deletions
81
.github/workflows/test.yml
vendored
81
.github/workflows/test.yml
vendored
|
@ -6,6 +6,7 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- releases/*
|
- releases/*
|
||||||
|
- users/ericsciple/*
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
@ -38,46 +39,46 @@ jobs:
|
||||||
with:
|
with:
|
||||||
ref: test-data/v2/basic
|
ref: test-data/v2/basic
|
||||||
path: basic
|
path: basic
|
||||||
- name: Verify basic
|
# - name: Verify basic
|
||||||
shell: bash
|
# shell: bash
|
||||||
run: __test__/verify-basic.sh
|
# run: __test__/verify-basic.sh
|
||||||
|
|
||||||
# Clean
|
# # Clean
|
||||||
- name: Modify work tree
|
# - name: Modify work tree
|
||||||
shell: bash
|
# shell: bash
|
||||||
run: __test__/modify-work-tree.sh
|
# run: __test__/modify-work-tree.sh
|
||||||
- name: Clean checkout
|
# - name: Clean checkout
|
||||||
uses: ./
|
# uses: ./
|
||||||
with:
|
# with:
|
||||||
ref: test-data/v2/basic
|
# ref: test-data/v2/basic
|
||||||
path: basic
|
# path: basic
|
||||||
- name: Verify clean
|
# - name: Verify clean
|
||||||
shell: bash
|
# shell: bash
|
||||||
run: __test__/verify-clean.sh
|
# run: __test__/verify-clean.sh
|
||||||
|
|
||||||
# Side by side
|
# # Side by side
|
||||||
- name: Side by side checkout 1
|
# - name: Side by side checkout 1
|
||||||
uses: ./
|
# uses: ./
|
||||||
with:
|
# with:
|
||||||
ref: test-data/v2/side-by-side-1
|
# ref: test-data/v2/side-by-side-1
|
||||||
path: side-by-side-1
|
# path: side-by-side-1
|
||||||
- name: Side by side checkout 2
|
# - name: Side by side checkout 2
|
||||||
uses: ./
|
# uses: ./
|
||||||
with:
|
# with:
|
||||||
ref: test-data/v2/side-by-side-2
|
# ref: test-data/v2/side-by-side-2
|
||||||
path: side-by-side-2
|
# path: side-by-side-2
|
||||||
- name: Verify side by side
|
# - name: Verify side by side
|
||||||
shell: bash
|
# shell: bash
|
||||||
run: __test__/verify-side-by-side.sh
|
# run: __test__/verify-side-by-side.sh
|
||||||
|
|
||||||
# LFS
|
# # LFS
|
||||||
- name: LFS checkout
|
# - name: LFS checkout
|
||||||
uses: ./
|
# uses: ./
|
||||||
with:
|
# with:
|
||||||
repository: actions/checkout # hardcoded, otherwise doesn't work from a fork
|
# repository: actions/checkout # hardcoded, otherwise doesn't work from a fork
|
||||||
ref: test-data/v2/lfs
|
# ref: test-data/v2/lfs
|
||||||
path: lfs
|
# path: lfs
|
||||||
lfs: true
|
# lfs: true
|
||||||
- name: Verify LFS
|
# - name: Verify LFS
|
||||||
shell: bash
|
# shell: bash
|
||||||
run: __test__/verify-lfs.sh
|
# run: __test__/verify-lfs.sh
|
||||||
|
|
781
dist/index.js
vendored
781
dist/index.js
vendored
File diff suppressed because one or more lines are too long
95
package-lock.json
generated
95
package-lock.json
generated
|
@ -15,11 +15,11 @@
|
||||||
"integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ=="
|
"integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ=="
|
||||||
},
|
},
|
||||||
"@actions/github": {
|
"@actions/github": {
|
||||||
"version": "1.1.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.0.0.tgz",
|
||||||
"integrity": "sha512-cHf6PyoNMdei13jEdGPhKprIMFmjVVW/dnM5/9QmQDJ1ZTaGVyezUSCUIC/ySNLRvDUpeFwPYMdThSEJldSbUw==",
|
"integrity": "sha512-sNpZ5dJyJyfJIO5lNYx8r/Gha4Tlm8R0MLO2cBkGdOnAAEn3t1M/MHVcoBhY/VPfjGVe5RNAUPz+6INrViiUPA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@octokit/graphql": "^2.0.1",
|
"@octokit/graphql": "^4.3.1",
|
||||||
"@octokit/rest": "^16.15.0"
|
"@octokit/rest": "^16.15.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -578,72 +578,56 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/endpoint": {
|
"@octokit/endpoint": {
|
||||||
"version": "5.4.0",
|
"version": "5.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.5.1.tgz",
|
||||||
"integrity": "sha512-DWTNgEKg5KXzvNjKTzcFTnkZiL7te6pQxxumvxPjyjDpcY5V3xzywnNu1WVqySY3Ct1flF/kAoyDdZos6acq3Q==",
|
"integrity": "sha512-nBFhRUb5YzVTCX/iAK1MgQ4uWo89Gu0TH00qQHoYRCsE12dWcG1OiLd7v2EIo2+tpUKPMOQ62QFy9hy9Vg2ULg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@octokit/types": "^2.0.0",
|
||||||
"is-plain-object": "^3.0.0",
|
"is-plain-object": "^3.0.0",
|
||||||
"universal-user-agent": "^4.0.0"
|
"universal-user-agent": "^4.0.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"universal-user-agent": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==",
|
|
||||||
"requires": {
|
|
||||||
"os-name": "^3.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/graphql": {
|
"@octokit/graphql": {
|
||||||
"version": "2.1.3",
|
"version": "4.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-2.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.3.1.tgz",
|
||||||
"integrity": "sha512-XoXJqL2ondwdnMIW3wtqJWEwcBfKk37jO/rYkoxNPEVeLBDGsGO1TCWggrAlq3keGt/O+C/7VepXnukUxwt5vA==",
|
"integrity": "sha512-hCdTjfvrK+ilU2keAdqNBWOk+gm1kai1ZcdjRfB30oA3/T6n53UVJb7w0L5cR3/rhU91xT3HSqCd+qbvH06yxA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@octokit/request": "^5.0.0",
|
"@octokit/request": "^5.3.0",
|
||||||
"universal-user-agent": "^2.0.3"
|
"@octokit/types": "^2.0.0",
|
||||||
|
"universal-user-agent": "^4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/request": {
|
"@octokit/request": {
|
||||||
"version": "5.1.0",
|
"version": "5.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.3.1.tgz",
|
||||||
"integrity": "sha512-I15T9PwjFs4tbWyhtFU2Kq7WDPidYMvRB7spmxoQRZfxSmiqullG+Nz+KbSmpkfnlvHwTr1e31R5WReFRKMXjg==",
|
"integrity": "sha512-5/X0AL1ZgoU32fAepTfEoggFinO3rxsMLtzhlUX+RctLrusn/CApJuGFCd0v7GMFhF+8UiCsTTfsu7Fh1HnEJg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@octokit/endpoint": "^5.1.0",
|
"@octokit/endpoint": "^5.5.0",
|
||||||
"@octokit/request-error": "^1.0.1",
|
"@octokit/request-error": "^1.0.1",
|
||||||
|
"@octokit/types": "^2.0.0",
|
||||||
"deprecation": "^2.0.0",
|
"deprecation": "^2.0.0",
|
||||||
"is-plain-object": "^3.0.0",
|
"is-plain-object": "^3.0.0",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"once": "^1.4.0",
|
"once": "^1.4.0",
|
||||||
"universal-user-agent": "^4.0.0"
|
"universal-user-agent": "^4.0.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"universal-user-agent": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==",
|
|
||||||
"requires": {
|
|
||||||
"os-name": "^3.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/request-error": {
|
"@octokit/request-error": {
|
||||||
"version": "1.0.4",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.2.0.tgz",
|
||||||
"integrity": "sha512-L4JaJDXn8SGT+5G0uX79rZLv0MNJmfGa4vb4vy1NnpjSnWDLJRy6m90udGwvMmavwsStgbv2QNkPzzTCMmL+ig==",
|
"integrity": "sha512-DNBhROBYjjV/I9n7A8kVkmQNkqFAMem90dSxqvPq57e2hBr7mNTX98y3R2zDpqMQHVRpBDjsvsfIGgBzy+4PAg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@octokit/types": "^2.0.0",
|
||||||
"deprecation": "^2.0.0",
|
"deprecation": "^2.0.0",
|
||||||
"once": "^1.4.0"
|
"once": "^1.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/rest": {
|
"@octokit/rest": {
|
||||||
"version": "16.33.0",
|
"version": "16.35.0",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.33.0.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.35.0.tgz",
|
||||||
"integrity": "sha512-t4jMR+odsfooQwmHiREoTQixVTX2DfdbSaO+lKrW9R5XBuk0DW+5T/JdfwtxAGUAHgvDDpWY/NVVDfEPTzxD6g==",
|
"integrity": "sha512-9ShFqYWo0CLoGYhA1FdtdykJuMzS/9H6vSbbQWDX4pWr4p9v+15MsH/wpd/3fIU+tSxylaNO48+PIHqOkBRx3w==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@octokit/request": "^5.0.0",
|
"@octokit/request": "^5.2.0",
|
||||||
"@octokit/request-error": "^1.0.2",
|
"@octokit/request-error": "^1.0.2",
|
||||||
"atob-lite": "^2.0.0",
|
"atob-lite": "^2.0.0",
|
||||||
"before-after-hook": "^2.0.0",
|
"before-after-hook": "^2.0.0",
|
||||||
|
@ -655,16 +639,14 @@
|
||||||
"octokit-pagination-methods": "^1.1.0",
|
"octokit-pagination-methods": "^1.1.0",
|
||||||
"once": "^1.4.0",
|
"once": "^1.4.0",
|
||||||
"universal-user-agent": "^4.0.0"
|
"universal-user-agent": "^4.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"@octokit/types": {
|
||||||
"universal-user-agent": {
|
"version": "2.0.2",
|
||||||
"version": "4.0.0",
|
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-2.0.2.tgz",
|
||||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz",
|
"integrity": "sha512-StASIL2lgT3TRjxv17z9pAqbnI7HGu9DrJlg3sEBFfCLaMEqp+O3IQPUF6EZtQ4xkAu2ml6kMBBCtGxjvmtmuQ==",
|
||||||
"integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"os-name": "^3.1.0"
|
"@types/node": ">= 8"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@types/babel__core": {
|
"@types/babel__core": {
|
||||||
|
@ -757,8 +739,7 @@
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "12.7.12",
|
"version": "12.7.12",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz",
|
||||||
"integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ==",
|
"integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/stack-utils": {
|
"@types/stack-utils": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
|
@ -6666,11 +6647,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"universal-user-agent": {
|
"universal-user-agent": {
|
||||||
"version": "2.1.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz",
|
||||||
"integrity": "sha512-8itiX7G05Tu3mGDTdNY2fB4KJ8MgZLS54RdG6PkkfwMAavrXu1mV/lls/GABx9O3Rw4PnTtasxrvbMQoBYY92Q==",
|
"integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"os-name": "^3.0.0"
|
"os-name": "^3.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"unset-value": {
|
"unset-value": {
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.1.3",
|
"@actions/core": "^1.1.3",
|
||||||
"@actions/exec": "^1.0.1",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^2.0.0",
|
||||||
"@actions/io": "^1.0.1"
|
"@actions/io": "^1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as gitCommandManager from './git-command-manager'
|
||||||
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 refHelper from './ref-helper'
|
||||||
|
import * as repositoryApiHelper from './repository-api-helper'
|
||||||
import {IGitCommandManager} from './git-command-manager'
|
import {IGitCommandManager} from './git-command-manager'
|
||||||
|
|
||||||
const authConfigKey = `http.https://github.com/.extraheader`
|
const authConfigKey = `http.https://github.com/.extraheader`
|
||||||
|
@ -23,6 +24,7 @@ export interface ISourceSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSource(settings: ISourceSettings): Promise<void> {
|
export async function getSource(settings: ISourceSettings): Promise<void> {
|
||||||
|
// Repository URL
|
||||||
core.info(
|
core.info(
|
||||||
`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`
|
`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`
|
||||||
)
|
)
|
||||||
|
@ -30,6 +32,13 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
|
||||||
settings.repositoryOwner
|
settings.repositoryOwner
|
||||||
)}/${encodeURIComponent(settings.repositoryName)}`
|
)}/${encodeURIComponent(settings.repositoryName)}`
|
||||||
|
|
||||||
|
// Set intra-task state for cleanup
|
||||||
|
coreCommand.issueCommand(
|
||||||
|
'save-state',
|
||||||
|
{name: 'repositoryPath'},
|
||||||
|
settings.repositoryPath
|
||||||
|
)
|
||||||
|
|
||||||
// Remove conflicting file path
|
// Remove conflicting file path
|
||||||
if (fsHelper.fileExistsSync(settings.repositoryPath)) {
|
if (fsHelper.fileExistsSync(settings.repositoryPath)) {
|
||||||
await io.rmRF(settings.repositoryPath)
|
await io.rmRF(settings.repositoryPath)
|
||||||
|
@ -44,29 +53,40 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
|
||||||
|
|
||||||
// Git command manager
|
// Git command manager
|
||||||
core.info(`Working directory is '${settings.repositoryPath}'`)
|
core.info(`Working directory is '${settings.repositoryPath}'`)
|
||||||
const git = await gitCommandManager.CreateCommandManager(
|
let git = (null as unknown) as IGitCommandManager
|
||||||
|
try {
|
||||||
|
git = await gitCommandManager.CreateCommandManager(
|
||||||
settings.repositoryPath,
|
settings.repositoryPath,
|
||||||
settings.lfs
|
settings.lfs
|
||||||
)
|
)
|
||||||
|
} catch (err) {
|
||||||
|
// Git is required for LFS
|
||||||
|
if (settings.lfs) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
|
||||||
// Try prepare existing directory, otherwise recreate
|
// Otherwise fallback to REST API
|
||||||
if (
|
}
|
||||||
isExisting &&
|
|
||||||
!(await tryPrepareExistingDirectory(
|
// Prepare existing directory, otherwise recreate
|
||||||
|
if (isExisting) {
|
||||||
|
await prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
settings.repositoryPath,
|
settings.repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
settings.clean
|
settings.clean
|
||||||
))
|
)
|
||||||
) {
|
|
||||||
// Delete the contents of the directory. Don't delete the directory itself
|
|
||||||
// since it may be the current working directory.
|
|
||||||
core.info(`Deleting the contents of '${settings.repositoryPath}'`)
|
|
||||||
for (const file of await fs.promises.readdir(settings.repositoryPath)) {
|
|
||||||
await io.rmRF(path.join(settings.repositoryPath, file))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!git || `${1}` == '1') {
|
||||||
|
await repositoryApiHelper.download(
|
||||||
|
settings.accessToken,
|
||||||
|
settings.repositoryOwner,
|
||||||
|
settings.repositoryName,
|
||||||
|
settings.ref,
|
||||||
|
settings.repositoryPath
|
||||||
|
)
|
||||||
|
} else {
|
||||||
// Initialize the repository
|
// Initialize the repository
|
||||||
if (
|
if (
|
||||||
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
|
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
|
||||||
|
@ -122,13 +142,7 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
|
||||||
|
|
||||||
// Dump some info about the checked out commit
|
// Dump some info about the checked out commit
|
||||||
await git.log1()
|
await git.log1()
|
||||||
|
}
|
||||||
// Set intra-task state for cleanup
|
|
||||||
coreCommand.issueCommand(
|
|
||||||
'save-state',
|
|
||||||
{name: 'repositoryPath'},
|
|
||||||
settings.repositoryPath
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cleanup(repositoryPath: string): Promise<void> {
|
export async function cleanup(repositoryPath: string): Promise<void> {
|
||||||
|
@ -146,20 +160,25 @@ export async function cleanup(repositoryPath: string): Promise<void> {
|
||||||
await removeGitConfig(git, authConfigKey)
|
await removeGitConfig(git, authConfigKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tryPrepareExistingDirectory(
|
async function prepareExistingDirectory(
|
||||||
git: IGitCommandManager,
|
git: IGitCommandManager,
|
||||||
repositoryPath: string,
|
repositoryPath: string,
|
||||||
repositoryUrl: string,
|
repositoryUrl: string,
|
||||||
clean: boolean
|
clean: boolean
|
||||||
): Promise<boolean> {
|
): Promise<void> {
|
||||||
|
let remove = false
|
||||||
|
|
||||||
|
// Check whether using git or REST API
|
||||||
|
if (!git) {
|
||||||
|
remove = true
|
||||||
|
}
|
||||||
// Fetch URL does not match
|
// Fetch URL does not match
|
||||||
if (
|
else if (
|
||||||
!fsHelper.directoryExistsSync(path.join(repositoryPath, '.git')) ||
|
!fsHelper.directoryExistsSync(path.join(repositoryPath, '.git')) ||
|
||||||
repositoryUrl !== (await git.tryGetFetchUrl())
|
repositoryUrl !== (await git.tryGetFetchUrl())
|
||||||
) {
|
) {
|
||||||
return false
|
remove = true
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// Delete any index.lock and shallow.lock left by a previously canceled run or crashed git process
|
// Delete any index.lock and shallow.lock left by a previously canceled run or crashed git process
|
||||||
const lockPaths = [
|
const lockPaths = [
|
||||||
path.join(repositoryPath, '.git', 'index.lock'),
|
path.join(repositoryPath, '.git', 'index.lock'),
|
||||||
|
@ -190,35 +209,40 @@ async function tryPrepareExistingDirectory(
|
||||||
for (const branch of branches) {
|
for (const branch of branches) {
|
||||||
await git.branchDelete(true, branch)
|
await git.branchDelete(true, branch)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
core.warning(
|
|
||||||
`Unable to prepare the existing repository. The repository will be recreated instead.`
|
|
||||||
)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
if (clean) {
|
if (clean) {
|
||||||
let succeeded = true
|
|
||||||
if (!(await git.tryClean())) {
|
if (!(await git.tryClean())) {
|
||||||
core.debug(
|
core.debug(
|
||||||
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
|
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
|
||||||
)
|
)
|
||||||
succeeded = false
|
remove = true
|
||||||
} else if (!(await git.tryReset())) {
|
} else if (!(await git.tryReset())) {
|
||||||
succeeded = false
|
remove = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!succeeded) {
|
if (remove) {
|
||||||
core.warning(
|
core.warning(
|
||||||
`Unable to clean or reset the repository. The repository will be recreated instead.`
|
`Unable to clean or reset the repository. The repository will be recreated instead.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return succeeded
|
} catch (error) {
|
||||||
|
core.warning(
|
||||||
|
`Unable to prepare the existing repository. The repository will be recreated instead.`
|
||||||
|
)
|
||||||
|
remove = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
if (remove) {
|
||||||
|
// Delete the contents of the directory. Don't delete the directory itself
|
||||||
|
// since it might be the current working directory.
|
||||||
|
core.info(`Deleting the contents of '${repositoryPath}'`)
|
||||||
|
for (const file of await fs.promises.readdir(repositoryPath)) {
|
||||||
|
await io.rmRF(path.join(repositoryPath, file))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeGitConfig(
|
async function removeGitConfig(
|
||||||
|
|
24
src/repository-api-helper.ts
Normal file
24
src/repository-api-helper.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import * as github from '@actions/github'
|
||||||
|
import {ReposGetArchiveLinkParams} from '@octokit/rest'
|
||||||
|
|
||||||
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
|
export async function download(
|
||||||
|
accessToken: string,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
ref: string,
|
||||||
|
repositoryPath: string
|
||||||
|
): Promise<void> {
|
||||||
|
const octokit = new github.GitHub(accessToken)
|
||||||
|
const params: ReposGetArchiveLinkParams = {
|
||||||
|
archive_format: IS_WINDOWS ? 'zipball' : 'tarball',
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
ref: ref
|
||||||
|
}
|
||||||
|
const response = await octokit.repos.getArchiveLink(params)
|
||||||
|
console.log(`status=${response.status}`)
|
||||||
|
console.log(`headers=${JSON.stringify(response.headers)}`)
|
||||||
|
console.log(`data=${JSON.stringify(response.data)}`)
|
||||||
|
}
|
Loading…
Reference in a new issue