Skip to content

Commit ccd0f47

Browse files
authored
Merge pull request #2 from Lerer/clean-number-of-sandboxes
Clean number of sandboxes
2 parents 2b592da + d9bd71f commit ccd0f47

File tree

10 files changed

+321
-116
lines changed

10 files changed

+321
-116
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
on:
2-
push:
3-
paths-ignore:
4-
- "README.md"
5-
- "**.json"
6-
- "action.yml"
72
workflow_dispatch:
83

94
jobs:
@@ -14,14 +9,24 @@ jobs:
149
steps:
1510
- name: Checkout
1611
uses: actions/checkout@v2
17-
- name: Test Sandbox Cleaning
12+
- name: Test Sandbox Cleaning - no sandbox
1813
env:
1914
VERACODE_API_ID: '${{ secrets.VERACODE_API_ID }}'
2015
VERACODE_API_SECRET: '${{ secrets.VERACODE_API_SECRET }}'
2116
uses: ./
2217
with:
23-
activity: "promote-latest-scan"
24-
app-name: "Verademo-Brances"
25-
sandbox-name: "test-01"
26-
delete-on-promote: true
27-
# clean-amount: "2" # (Optional) Number - with default as 1
18+
activity: "clean"
19+
app-name: "test-delete-sandboxes"
20+
clean-amount: "2"
21+
clean-modified-before: "600"
22+
- name: Test Sandbox Cleaning - single sandbox
23+
env:
24+
VERACODE_API_ID: '${{ secrets.VERACODE_API_ID }}'
25+
VERACODE_API_SECRET: '${{ secrets.VERACODE_API_SECRET }}'
26+
uses: ./
27+
with:
28+
activity: "clean"
29+
app-name: "test-delete-sandboxes"
30+
clean-amount: "1"
31+
32+

README.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Veracode Sandboxes Helper
2+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Lerer_veracode-sandboxes-helper&metric=alert_status)](https://sonarcloud.io/dashboard?id=Lerer_veracode-sandboxes-helper)
3+
4+
25
An Action to handle Sandboxes mainly as a set of clean-up activities such as:
36
- Deleting a sandbox
7+
- Delete Multiple Sandboxes
48
- Promoting Sandbox scan to Policy Scan
59
- with or without deleting the sandbox
610

@@ -16,6 +20,7 @@ Value | Details
1620
--- | ---
1721
|`remove-sandbox`|Remove/Delete a sandbox|
1822
|`promote-latest-scan`|Promote the latest Sandbox scan to a Policy|
23+
|`clean`|Delete multiple dated sandboxes based on recent activity|
1924

2025
### `app-name`
2126
**Required** - The Veracode Application Profile name
@@ -24,17 +29,33 @@ Value | Details
2429
**Required** - The sandbox name
2530

2631
### `delete-on-promote`
27-
**Optional** - Only works with `promote-latest-scan` activity and give you the option to specify if you want the Sandbox to be deleted after the last scan is promoted to a Policy Scan
28-
32+
**Optional** - Only works with `activity: "promote-latest-scan"` activity and give you the option to specify if you want the Sandbox to be deleted after the last scan is promoted to a Policy Scan
2933

3034
| Value | Details|
3135
--- | ---
3236
| `"false"`| **Default** - Do not delete the Sandbox |
3337
| `"true"` | Delete the Sandbox after promoting the latest scan |
3438

39+
### `clean-amount`
40+
**Optional** - The number of dated sandboxes to delete. The query of sandboxes will target Sandboxes which their `modified` date is most dated.
41+
42+
Value | Details|
43+
--- | ---
44+
| `1`| **Default** - Delete a single Sandbox |
45+
| Any number from 1-25 | Number of sandboxes to delete |
46+
47+
### `clean-modified-before`
48+
**Optional** - The attribute will instruct the clean step to only look for sandboxes which their `modified` date is older than the amount of days given as the a value.
49+
:exclamation: __Only works in conjunction with the `clean` activity__
50+
51+
Value | Details|
52+
--- | ---
53+
| `0`| **Default** - Any sandbox |
54+
| Any other number - X | Can only delete sandboxes which last modified at least X days ago |
55+
3556
## Examples
3657

37-
### Delete Sandbox
58+
### Delete a Sandbox
3859
For deleting a sandbox you can simply add the following step to your workflow job.
3960

4061
```yaml
@@ -46,7 +67,7 @@ on:
4667
jobs:
4768
veracode-sandbox-task:
4869
runs-on: ubuntu-latest
49-
name: Clean 2 Sandboxes
70+
name: Clean branch Sandbox
5071

5172
steps:
5273

@@ -56,14 +77,49 @@ jobs:
5677
env:
5778
VERACODE_API_ID: '${{ secrets.VERACODE_API_ID }}'
5879
VERACODE_API_SECRET: '${{ secrets.VERACODE_API_SECRET }}'
59-
uses: lerer/veracode-sandboxes-helper@v1
80+
uses: lerer/veracode-sandboxes-helper@v1.0.1
6081
with:
6182
activity: "remove-sandbox"
6283
app-name: "<YOUR VERACODE APPLICATION NAME>"
63-
sandbox-name: "<SANDBOX_NAME>" # "${{ github.ref }}"
84+
# "${{ github.ref }}" - current branch on push triggers
85+
# or "${{ github.event.pull_request.head.ref }}" - post pull request
86+
sandbox-name: "<SANDBOX_NAME>"
87+
88+
```
89+
90+
### Delete Multiple Sandboxes
91+
Delete up to two most dated Sandboxes modified at least 14 days ago.
92+
93+
```yaml
94+
on:
95+
workflow_dispatch:
96+
97+
schedule:
98+
- cron: 30 14 * * *
99+
100+
jobs:
101+
veracode-sandbox-maintenance-task:
102+
runs-on: ubuntu-latest
103+
name: Pull Request Review Submitted
104+
105+
steps:
106+
107+
... # your other job steps
108+
109+
- name: Delete old unused Sandboxes
110+
env:
111+
VERACODE_API_ID: '${{ secrets.VERACODE_API_ID }}'
112+
VERACODE_API_SECRET: '${{ secrets.VERACODE_API_SECRET }}'
113+
uses: lerer/[email protected]
114+
with:
115+
activity: "clean"
116+
app-name: "<YOUR VERACODE APPLICATION NAME>"
117+
clean-amount: "2"
118+
clean-modified-before: "14"
64119

65120
```
66121

122+
67123
### Promote Sandbox
68124
For promoting a scan from Sandbox to a Policy you can use the following
69125

@@ -89,7 +145,7 @@ jobs:
89145
env:
90146
VERACODE_API_ID: '${{ secrets.VERACODE_API_ID }}'
91147
VERACODE_API_SECRET: '${{ secrets.VERACODE_API_SECRET }}'
92-
uses: lerer/veracode-sandboxes-helper@v1
148+
uses: lerer/veracode-sandboxes-helper@v1.0.1
93149
with:
94150
activity: "promote-latest-scan"
95151
app-name: "<YOUR VERACODE APPLICATION NAME>"

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ branding:
66
color: 'blue'
77
inputs:
88
activity:
9-
description: "The activity expected from the Action: clean, promote-latest-scan, promote-and-remove, remove-sandbox"
9+
description: "The activity expected from the Action: clean, promote-latest-scan, remove-sandbox"
1010
required: false
1111
app-name: # id of input
1212
description: 'Veracode Application name'
@@ -22,6 +22,10 @@ inputs:
2222
description: 'Deletes the sandbox after its promotion. Only works with the [promote] activity. Default is false'
2323
required: false
2424
default: 'false'
25+
clean-modified-before:
26+
description: 'The number of days which the sandbox had no activity'
27+
required: false
28+
default: "0"
2529
runs:
2630
using: 'node12'
2731
main: 'dist/index.js'

0 commit comments

Comments
 (0)