mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-04-23 03:45:32 +00:00
.
This commit is contained in:
parent
1e6a918852
commit
89cbb18acd
4 changed files with 82 additions and 19 deletions
|
@ -3,10 +3,11 @@ import * as coreCommand from '@actions/core/lib/command'
|
|||
import * as fs from 'fs'
|
||||
import * as fsHelper from './fs-helper'
|
||||
import * as gitCommandManager from './git-command-manager'
|
||||
import * as githubApiHelper from './github-api-helper'
|
||||
import * as io from '@actions/io'
|
||||
import * as path from 'path'
|
||||
import * as refHelper from './ref-helper'
|
||||
import * as githubApiHelper from './github-api-helper'
|
||||
import * as stateHelper from './state-helper'
|
||||
import {IGitCommandManager} from './git-command-manager'
|
||||
|
||||
const authConfigKey = `http.https://github.com/.extraheader`
|
||||
|
@ -32,13 +33,6 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
|
|||
settings.repositoryOwner
|
||||
)}/${encodeURIComponent(settings.repositoryName)}`
|
||||
|
||||
// Set intra-task state for cleanup
|
||||
coreCommand.issueCommand(
|
||||
'save-state',
|
||||
{name: 'repositoryPath'},
|
||||
settings.repositoryPath
|
||||
)
|
||||
|
||||
// Remove conflicting file path
|
||||
if (fsHelper.fileExistsSync(settings.repositoryPath)) {
|
||||
await io.rmRF(settings.repositoryPath)
|
||||
|
@ -79,6 +73,9 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
|
|||
settings.repositoryPath
|
||||
)
|
||||
} else {
|
||||
// Save state for POST action
|
||||
stateHelper.setRepositoryPath(settings.repositoryPath)
|
||||
|
||||
// Initialize the repository
|
||||
if (
|
||||
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
|
||||
|
|
|
@ -3,8 +3,7 @@ import * as coreCommand from '@actions/core/lib/command'
|
|||
import * as gitSourceProvider from './git-source-provider'
|
||||
import * as inputHelper from './input-helper'
|
||||
import * as path from 'path'
|
||||
|
||||
const cleanupRepositoryPath = process.env['STATE_repositoryPath'] as string
|
||||
import * as stateHelper from './state-helper'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
|
@ -31,14 +30,14 @@ async function run(): Promise<void> {
|
|||
|
||||
async function cleanup(): Promise<void> {
|
||||
try {
|
||||
await gitSourceProvider.cleanup(cleanupRepositoryPath)
|
||||
await gitSourceProvider.cleanup(stateHelper.RepositoryPath)
|
||||
} catch (error) {
|
||||
core.warning(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
// Main
|
||||
if (!cleanupRepositoryPath) {
|
||||
if (!stateHelper.IsPost) {
|
||||
run()
|
||||
}
|
||||
// Post
|
||||
|
|
29
src/state-helper.ts
Normal file
29
src/state-helper.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as coreCommand from '@actions/core/lib/command'
|
||||
|
||||
/**
|
||||
* Indicates whether the POST action is running
|
||||
*/
|
||||
export const IsPost = !!process.env['STATE_isPost']
|
||||
|
||||
/**
|
||||
* The repository path for the POST action. The value is empty during the MAIN action.
|
||||
*/
|
||||
export const RepositoryPath = process.env['STATE_repositoryPath'] as string
|
||||
|
||||
/**
|
||||
* Save the repository path so the POST action can retrieve the value.
|
||||
*/
|
||||
export function setRepositoryPath(repositoryPath: string) {
|
||||
coreCommand.issueCommand(
|
||||
'save-state',
|
||||
{name: 'repositoryPath'},
|
||||
repositoryPath
|
||||
)
|
||||
}
|
||||
|
||||
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
|
||||
// This is necessary since we don't have a separate entry point.
|
||||
if (!IsPost) {
|
||||
coreCommand.issueCommand('save-state', {name: 'isPost'}, 'true')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue