Skip to content

Commit

Permalink
feat: Add deployPath option for directory-specific deployments (#210)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryadh <[email protected]>
  • Loading branch information
ShineOfFire and ryadhkralfallah authored Jan 14, 2025
1 parent 722af6e commit 158d0b2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,32 @@ being published, or after a CI run.
[MIT](https://github.com/47ng/actions-clever-cloud/blob/master/LICENSE) - Made with ❤️ by [François Best](https://francoisbest.com)

Using this action at work ? [Sponsor me](https://github.com/sponsors/franky47) to help with support and maintenance.

## Deploying a Specific Directory

> ⚠️ Important note about the difference between `working-directory` and `deployPath`:
>
> - `working-directory` (GitHub Actions option) : Only changes the directory where the action runs. All files remain available, only the execution context changes.
>
> - `deployPath` (this action's option) : Specifies exactly which files will be sent to Clever Cloud. Allows deploying only a subset of files, like a `dist` or `build` folder.

### Example

```yml
# This will NOT deploy only the build folder:
- uses: 47ng/[email protected]
with:
working-directory: ./build # ❌ Only changes where the action runs
# This will deploy only the build folder:
- uses: 47ng/[email protected]
with:
deployPath: ./build # ✅ Only sends these files to Clever Cloud
```

This option is particularly useful for:
- Monorepos where you want to deploy a single package
- Projects where you only want to deploy built/compiled files
- Filtering which files are sent to Clever Cloud

Note: The path must be relative to the repository root and must exist.
15 changes: 15 additions & 0 deletions __tests__/processArguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,18 @@ test('quiet', () => {
const args = processArguments()
expect(args.quiet).toBe(true)
})

test('deployPath is unset by default', () => {
process.env.CLEVER_TOKEN = 'token'
process.env.CLEVER_SECRET = 'secret'
const args = processArguments()
expect(args.deployPath).toBeUndefined()
})

test('deployPath is set from input', () => {
process.env.CLEVER_TOKEN = 'token'
process.env.CLEVER_SECRET = 'secret'
process.env.INPUT_DEPLOYPATH = './packages/backend'
const args = processArguments()
expect(args.deployPath).toBe('./packages/backend')
})
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ inputs:
Values are separated by a newline character (\n), use a YAML literal block
scalar `|` to preserve newlines and separate multiple variables definitions.
(see https://github.com/47ng/actions-clever-cloud#extra-environment-variables)
deployPath:
required: false
description: |
Specific directory to deploy instead of the entire project.
Path must be relative to the repository root.
logFile:
required: false
description: |
Expand Down
15 changes: 15 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface Arguments {
timeout?: number
cleverCLI: string
extraEnv?: ExtraEnv
deployPath?: string
logFile?: string
quiet?: boolean
}
Expand Down Expand Up @@ -76,13 +77,16 @@ export function processArguments(): Arguments {
const timeout = parseInt(core.getInput('timeout')) || undefined
const logFile = core.getInput('logFile') || undefined
const quiet = core.getBooleanInput('quiet', { required: false })
const deployPath = core.getInput('deployPath') || undefined

return {
token,
secret,
alias,
force,
appID,
timeout,
deployPath,
cleverCLI: path.resolve(__dirname, '../node_modules/.bin/clever'),
extraEnv: listExtraEnv(),
logFile,
Expand Down Expand Up @@ -115,6 +119,7 @@ export default async function run({
force = false,
cleverCLI,
timeout,
deployPath,
logFile,
quiet = false,
extraEnv = {}
Expand All @@ -126,6 +131,16 @@ export default async function run({
outStream: await getOutputStream(quiet, logFile)
}

if (deployPath) {
try {
await fs.access(deployPath)
execOptions.cwd = deployPath
core.info(`Deploying from directory: ${deployPath}`)
} catch (error) {
throw new Error(`Deploy path does not exist: ${deployPath}`)
}
}

core.debug(`Clever CLI path: ${cleverCLI}`)

// Authenticate (this will only store the credentials at a known location)
Expand Down

0 comments on commit 158d0b2

Please sign in to comment.