Skip to content

Commit 6caef4f

Browse files
authored
Merge pull request #358 from github/payload-updates
Deployment Payload Updates
2 parents cd1dd78 + 046d20d commit 6caef4f

File tree

9 files changed

+154
-39
lines changed

9 files changed

+154
-39
lines changed

__tests__/functions/timestamp.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {timestamp} from '../../src/functions/timestamp'
2+
3+
beforeEach(() => {
4+
jest.clearAllMocks()
5+
})
6+
7+
describe('timestamp', () => {
8+
it('should return the current date in ISO 8601 format', () => {
9+
const mockDate = new Date('2025-01-01T00:00:00.000Z')
10+
jest.spyOn(global, 'Date').mockImplementation(() => mockDate)
11+
12+
const result = timestamp()
13+
14+
expect(result).toBe(mockDate.toISOString())
15+
16+
// Restore the original Date implementation
17+
global.Date.mockRestore()
18+
})
19+
})

__tests__/main.test.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as isDeprecated from '../src/functions/deprecated-checks'
1616
import * as nakedCommandCheck from '../src/functions/naked-command-check'
1717
import * as validDeploymentOrder from '../src/functions/valid-deployment-order'
1818
import * as commitSafetyChecks from '../src/functions/commit-safety-checks'
19+
import * as timestamp from '../src/functions/timestamp'
1920
import {COLORS} from '../src/functions/colors'
2021

2122
const setOutputMock = jest.spyOn(core, 'setOutput')
@@ -113,7 +114,7 @@ beforeEach(() => {
113114
rest: {
114115
issues: {
115116
createComment: jest.fn().mockReturnValueOnce({
116-
data: {}
117+
data: {id: 123456}
117118
})
118119
},
119120
repos: {
@@ -153,7 +154,10 @@ beforeEach(() => {
153154
return true
154155
})
155156
jest.spyOn(reactEmote, 'reactEmote').mockImplementation(() => {
156-
return {data: {id: '123'}}
157+
return {data: {id: 123}}
158+
})
159+
jest.spyOn(timestamp, 'timestamp').mockImplementation(() => {
160+
return '2025-01-01T00:00:00.000Z'
157161
})
158162
jest.spyOn(prechecks, 'prechecks').mockImplementation(() => {
159163
return {
@@ -175,7 +179,8 @@ beforeEach(() => {
175179
.mockImplementation(() => {
176180
return {
177181
status: true,
178-
message: 'success'
182+
message: 'success',
183+
isVerified: true
179184
}
180185
})
181186
jest
@@ -964,7 +969,7 @@ test('detects an out of date branch and exits', async () => {
964969
rest: {
965970
issues: {
966971
createComment: jest.fn().mockReturnValueOnce({
967-
data: {}
972+
data: {id: 123123}
968973
})
969974
},
970975
repos: {
@@ -1063,7 +1068,8 @@ test('fails commitSafetyChecks', async () => {
10631068
return {
10641069
status: false,
10651070
message:
1066-
'### ⚠️ Cannot proceed with deployment... a scary commit was found'
1071+
'### ⚠️ Cannot proceed with deployment... a scary commit was found',
1072+
isVerified: false
10671073
}
10681074
})
10691075
jest.spyOn(actionStatus, 'actionStatus').mockImplementation(() => {
@@ -1213,7 +1219,8 @@ test('stores params and parsed params into context', async () => {
12131219
params,
12141220
parsed_params,
12151221
sha: 'abc123',
1216-
type: 'branch-deploy'
1222+
type: 'branch-deploy',
1223+
github_run_id: 12345
12171224
})
12181225
})
12191226
expect(await run()).toBe('success')
@@ -1264,7 +1271,15 @@ test('stores params and parsed params into context with complex params', async (
12641271
params,
12651272
parsed_params,
12661273
sha: 'deadbeef',
1267-
type: 'branch-deploy'
1274+
type: 'branch-deploy',
1275+
github_run_id: 12345,
1276+
initial_comment_id: 123,
1277+
initial_reaction_id: 123,
1278+
deployment_started_comment_id: 123456,
1279+
timestamp: '2025-01-01T00:00:00.000Z',
1280+
commit_verified: true,
1281+
actor: 'monalisa',
1282+
stable_branch_used: false
12681283
})
12691284
})
12701285
expect(await run()).toBe('success')

dist/index.js

+46-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/deployment-payload.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,31 @@ Here is the data that the branch-deploy Action will add to the deployment payloa
66

77
```json
88
{
9-
"params": "<string>",
10-
"parsed_params": "<object>",
9+
"type": "branch-deploy",
1110
"sha": "<string>",
12-
"type": "branch-deploy"
11+
"params": "<string>",
12+
"parsed_params": {},
13+
"github_run_id": 123,
14+
"initial_comment_id": 123,
15+
"initial_reaction_id": 123,
16+
"deployment_started_comment_id": 123456,
17+
"deployment_started_comment_id": 123123,
18+
"timestamp": "2025-01-01T00:00:00.000Z",
19+
"commit_verified": true,
20+
"actor": "<string>",
21+
"stable_branch_used": false
1322
}
1423
```
1524

25+
- `type` - This is the type of deployment that is being created. This will always be `branch-deploy` for the branch-deploy Action.
26+
- `sha` - This is the commit SHA that is being deployed.
1627
- `params` - This is the raw string of parameters that were passed to the branch-deploy Action. You can read more about parameters [here](./parameters.md).
1728
- `parsed_params` - This is the parsed version of the `params` string. This is a JSON object that is created by parsing the `params` string. You can read more about parameters [here](./parameters.md).
18-
- `sha` - This is the commit SHA that is being deployed.
19-
- `type` - This is the type of deployment that is being created. This will always be `branch-deploy` for the branch-deploy Action.
29+
- `github_run_id` - This is the ID of the GitHub Action run that created the deployment. This can be useful if you need to access the logs of the deployment.
30+
- `initial_comment_id` - This is the ID of the initial (trigger) comment that kicked off the branch-deploy Action. Example: `.deploy` would be the comment that triggered the deployment and this would be the ID of that comment.
31+
- `initial_reaction_id` - This is the ID of the initial reaction that was left on the trigger comment by the branch-deploy Action. This is usually a pair of eyes (👀) to indicate that the branch-deploy Action has detected the trigger comment and it is running logic.
32+
- `deployment_started_comment_id` - This is the ID of the comment that the branch-deploy Action leaves below the trigger comment. It usually contains information about the deployment that is about to take place. Example: `Deployment Triggered 🚀... GrantBirki, started a branch deployment to production`
33+
- `timestamp` - This is the timestamp of when the deployment was created from the perspective of the branch-deploy Action.
34+
- `commit_verified` - This is a boolean that indicates whether the commit that is being deployed is verified.
35+
- `actor` - This is the username of the user that triggered the deployment.
36+
- `stable_branch_used` - This is a boolean that indicates whether the stable branch was used for the deployment. This will be `true` if the stable branch was used and `false` if the stable branch was not used.

src/functions/deployment.js

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export async function createDeploymentStatus(
3434
headers: API_HEADERS
3535
})
3636

37+
core.debug(`deploymentStatus.id: ${result.id}`)
38+
core.debug(`deploymentStatus.url: ${result.url}`)
39+
3740
return result
3841
}
3942

src/functions/timestamp.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Helper function to generate an ISO 8601 formatted timestamp string
2+
// :returns: An ISO 8601 formatted timestamp string (ex: 2025-01-01T00:00:00.000Z)
3+
export function timestamp() {
4+
const now = new Date()
5+
return now.toISOString()
6+
}

0 commit comments

Comments
 (0)