Skip to content

Commit f496297

Browse files
jerezefranky47
andauthored
feat: Add sameCommitPolicy option (#213)
Co-authored-by: François Best <github@francoisbest.com>
1 parent 160d348 commit f496297

File tree

7 files changed

+79
-24
lines changed

7 files changed

+79
-24
lines changed

.github/workflows/pr-preview.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ jobs:
2828
2929
// Only create comment if it doesn't exist
3030
if (!approvalComment) {
31+
const body = `<!-- approval-request-comment -->
32+
## ⚠️ &nbsp;Manual approval required
33+
34+
A repository owner must approve the Docker preview deployment for this PR.
35+
36+
**PR Author:** @${{ github.event.pull_request.user.login }}
37+
**Head SHA:** \`${{ github.event.pull_request.head.sha }}\`
38+
39+
[Review and approve in Actions →](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
40+
3141
await github.rest.issues.createComment({
3242
owner: context.repo.owner,
3343
repo: context.repo.repo,
3444
issue_number: context.issue.number,
35-
body: `<!-- approval-request-comment -->
36-
## ⚠️ &nbsp;Manual approval required
37-
38-
A repository owner must approve the Docker preview deployment for this PR.
39-
40-
**PR Author:** @${{ github.event.pull_request.user.login }}
41-
**Head SHA:** \`${{ github.event.pull_request.head.sha }}\`
42-
43-
[Review and approve in Actions →](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`
45+
body
4446
});
4547
}
4648

README.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ GitHub action to deploy your application to [Clever Cloud](https://clever-cloud.
1010
## Prerequisite
1111

1212
⚠️ When creating an application on Clever Cloud, you have to choose
13-
between deploying "*from a local repository*" (using Clever CLI, Git
14-
or SFTP) or "*from a Github repository*" (using a webhook setup
13+
between deploying "_from a local repository_" (using Clever CLI, Git
14+
or SFTP) or "_from a Github repository_" (using a webhook setup
1515
automatically by Clever Cloud). Only the first type of applications
1616
can be deployed using this Github action.
1717

1818
In your project's `.clever.json`, if the `deploy_url` value starts
1919
with `https://github.com/`, your application is meant to be deployed
20-
"*from a Github repository*" only.
20+
"_from a Github repository_" only.
2121
If you try deploying it with this Github action, you will get the
2222
following message in your logs: `[ERROR] HTTP Error: 401 Authorization
2323
Required`.
2424

2525
Currently (early 2023), the only workaround is to create a new
26-
application on Clever Cloud, that deploys "*from a local repository*",
26+
application on Clever Cloud, that deploys "_from a local repository_",
2727
then remove the Clever Cloud webhook that has been created on your
2828
Github repository.
2929

@@ -102,8 +102,9 @@ $ cat ~/.config/clever-cloud/clever-tools.json
102102
```
103103

104104
4. In your repository settings, [add the following secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets):
105-
- `CLEVER_TOKEN`: the `token` value in the credentials
106-
- `CLEVER_SECRET`: the `secret` value in the credentials
105+
106+
- `CLEVER_TOKEN`: the `token` value in the credentials
107+
- `CLEVER_SECRET`: the `secret` value in the credentials
107108

108109
## Extra Environment Variables
109110

@@ -121,7 +122,7 @@ key=value).
121122
EGG=spam
122123
# ^-- ..and the indentation here
123124
env:
124-
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
125+
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
125126
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
126127
```
127128

@@ -158,7 +159,7 @@ regardless of the deployment status:
158159
with:
159160
timeout: 1800 # wait at maximum 30 minutes before moving on
160161
env:
161-
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
162+
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
162163
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
163164
```
164165

@@ -178,6 +179,26 @@ Clever Cloud uses a Git remote to perform deploys. By default, if the commit you
178179
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
179180
```
180181

182+
## Same Commit Policy
183+
184+
> Support: introduced in v2.1.0
185+
186+
When the local and remote commits are identical, you can control what happens using the `sameCommitPolicy` option. Possible values are:
187+
188+
- `error` (default): Fail the deployment
189+
- `ignore`: Skip the deployment silently
190+
- `restart`: Restart the application without redeploying
191+
- `rebuild`: Rebuild and redeploy the application
192+
193+
```yml
194+
- uses: 47ng/actions-clever-cloud@v2.0.0
195+
with:
196+
sameCommitPolicy: restart
197+
env:
198+
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
199+
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
200+
```
201+
181202
## Logs
182203

183204
> Support: introduced in v1.3.1
@@ -225,6 +246,7 @@ _Note: this behaviour will be disabled if the `quiet` option is used._
225246
This action follows [SemVer](https://semver.org/).
226247

227248
To specify the version of the action to use:
249+
228250
- `uses: 47ng/actions-clever-cloud@v2.0.0`: latest stable version
229251
- `uses: 47ng/actions-clever-cloud@3e5402496b8d6492401ebb3134acfeccc25c3fce`: pinned to a specific Git SHA-1 (check out the [releases](https://github.com/47ng/actions-clever-cloud/releases))
230252
- `uses: docker://ghcr.io/47ng/actions-clever-cloud:latest`: latest code from master (not recommended, as it may break: hic sunt dracones.)
@@ -258,10 +280,11 @@ Using this action at work ? [Sponsor me](https://github.com/sponsors/franky47) t
258280

259281
## Deploying a Specific Directory
260282

283+
> Support: introduced in v2.1.0
284+
261285
> ⚠️ Important note about the difference between `working-directory` and `deployPath`:
262286
>
263287
> - `working-directory` (GitHub Actions option) : Only changes the directory where the action runs. All files remain available, only the execution context changes.
264-
>
265288
> - `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.
266289

267290
### Example
@@ -270,15 +293,16 @@ Using this action at work ? [Sponsor me](https://github.com/sponsors/franky47) t
270293
# This will NOT deploy only the build folder:
271294
- uses: 47ng/actions-clever-cloud@v2.0.0
272295
with:
273-
working-directory: ./build # ❌ Only changes where the action runs
296+
working-directory: ./build # ❌ Only changes where the action runs
274297
275298
# This will deploy only the build folder:
276299
- uses: 47ng/actions-clever-cloud@v2.0.0
277300
with:
278-
deployPath: ./build # ✅ Only sends these files to Clever Cloud
301+
deployPath: ./build # ✅ Only sends these files to Clever Cloud
279302
```
280303

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

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ inputs:
4848
description: |
4949
Don't print deployment output to the console. Use this in case your deployment
5050
may reveal secrets or PII.
51+
sameCommitPolicy:
52+
required: false
53+
description: |
54+
What to do when local and remote commit are identical.
55+
Possible values: error, ignore, restart, rebuild.
56+
If not set, the Clever Cloud CLI default (error) will be used.
5157
runs:
5258
using: docker
53-
image: docker://ghcr.io/47ng/actions-clever-cloud:2.0.1
59+
image: docker://ghcr.io/47ng/actions-clever-cloud:2.1.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@47ng/actions-clever-cloud",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"private": true,
55
"description": "GitHub Action to deploy to Clever Cloud",
66
"license": "MIT",

src/action.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export async function run({
3333
deployPath,
3434
logFile,
3535
quiet = false,
36-
extraEnv = {}
36+
extraEnv = {},
37+
sameCommitPolicy
3738
}: Arguments): Promise<void> {
3839
try {
3940
await checkForShallowCopy()
@@ -90,6 +91,10 @@ export async function run({
9091
args.push('--force')
9192
}
9293

94+
if (sameCommitPolicy) {
95+
args.push('--same-commit-policy', sameCommitPolicy)
96+
}
97+
9398
if (timeout) {
9499
let timeoutID: NodeJS.Timeout | undefined
95100
let timedOut = false

src/arguments.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,18 @@ test('deployPath is set from input', () => {
151151
const args = processArguments()
152152
expect(args.deployPath).toBe('./packages/backend')
153153
})
154+
155+
test('sameCommitPolicy is unset by default', () => {
156+
process.env.CLEVER_TOKEN = 'token'
157+
process.env.CLEVER_SECRET = 'secret'
158+
const args = processArguments()
159+
expect(args.sameCommitPolicy).toBeUndefined()
160+
})
161+
162+
test('sameCommitPolicy is set from input', () => {
163+
process.env.CLEVER_TOKEN = 'token'
164+
process.env.CLEVER_SECRET = 'secret'
165+
process.env.INPUT_SAMECOMMITPOLICY = 'restart'
166+
const args = processArguments()
167+
expect(args.sameCommitPolicy).toBe('restart')
168+
})

src/arguments.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type Arguments = {
2020
deployPath?: string
2121
logFile?: string
2222
quiet?: boolean
23+
sameCommitPolicy?: string
2324
}
2425

2526
function throwMissingEnvVar(name: string): never {
@@ -74,6 +75,7 @@ export function processArguments(): Arguments {
7475
const logFile = core.getInput('logFile') || undefined
7576
const quiet = core.getBooleanInput('quiet', { required: false })
7677
const deployPath = core.getInput('deployPath') || undefined
78+
const sameCommitPolicy = core.getInput('sameCommitPolicy') || undefined
7779

7880
return {
7981
token,
@@ -86,6 +88,7 @@ export function processArguments(): Arguments {
8688
cleverCLI: path.resolve(__dirname, '../node_modules/.bin/clever'),
8789
extraEnv: listExtraEnv(),
8890
logFile,
89-
quiet
91+
quiet,
92+
sameCommitPolicy
9093
}
9194
}

0 commit comments

Comments
 (0)