Skip to content

Commit

Permalink
Merge pull request #358 from github/payload-updates
Browse files Browse the repository at this point in the history
Deployment Payload Updates
  • Loading branch information
GrantBirki authored Jan 21, 2025
2 parents cd1dd78 + 046d20d commit 6caef4f
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 39 deletions.
19 changes: 19 additions & 0 deletions __tests__/functions/timestamp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {timestamp} from '../../src/functions/timestamp'

beforeEach(() => {
jest.clearAllMocks()
})

describe('timestamp', () => {
it('should return the current date in ISO 8601 format', () => {
const mockDate = new Date('2025-01-01T00:00:00.000Z')
jest.spyOn(global, 'Date').mockImplementation(() => mockDate)

const result = timestamp()

expect(result).toBe(mockDate.toISOString())

// Restore the original Date implementation
global.Date.mockRestore()
})
})
29 changes: 22 additions & 7 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as isDeprecated from '../src/functions/deprecated-checks'
import * as nakedCommandCheck from '../src/functions/naked-command-check'
import * as validDeploymentOrder from '../src/functions/valid-deployment-order'
import * as commitSafetyChecks from '../src/functions/commit-safety-checks'
import * as timestamp from '../src/functions/timestamp'
import {COLORS} from '../src/functions/colors'

const setOutputMock = jest.spyOn(core, 'setOutput')
Expand Down Expand Up @@ -113,7 +114,7 @@ beforeEach(() => {
rest: {
issues: {
createComment: jest.fn().mockReturnValueOnce({
data: {}
data: {id: 123456}
})
},
repos: {
Expand Down Expand Up @@ -153,7 +154,10 @@ beforeEach(() => {
return true
})
jest.spyOn(reactEmote, 'reactEmote').mockImplementation(() => {
return {data: {id: '123'}}
return {data: {id: 123}}
})
jest.spyOn(timestamp, 'timestamp').mockImplementation(() => {
return '2025-01-01T00:00:00.000Z'
})
jest.spyOn(prechecks, 'prechecks').mockImplementation(() => {
return {
Expand All @@ -175,7 +179,8 @@ beforeEach(() => {
.mockImplementation(() => {
return {
status: true,
message: 'success'
message: 'success',
isVerified: true
}
})
jest
Expand Down Expand Up @@ -964,7 +969,7 @@ test('detects an out of date branch and exits', async () => {
rest: {
issues: {
createComment: jest.fn().mockReturnValueOnce({
data: {}
data: {id: 123123}
})
},
repos: {
Expand Down Expand Up @@ -1063,7 +1068,8 @@ test('fails commitSafetyChecks', async () => {
return {
status: false,
message:
'### ⚠️ Cannot proceed with deployment... a scary commit was found'
'### ⚠️ Cannot proceed with deployment... a scary commit was found',
isVerified: false
}
})
jest.spyOn(actionStatus, 'actionStatus').mockImplementation(() => {
Expand Down Expand Up @@ -1213,7 +1219,8 @@ test('stores params and parsed params into context', async () => {
params,
parsed_params,
sha: 'abc123',
type: 'branch-deploy'
type: 'branch-deploy',
github_run_id: 12345
})
})
expect(await run()).toBe('success')
Expand Down Expand Up @@ -1264,7 +1271,15 @@ test('stores params and parsed params into context with complex params', async (
params,
parsed_params,
sha: 'deadbeef',
type: 'branch-deploy'
type: 'branch-deploy',
github_run_id: 12345,
initial_comment_id: 123,
initial_reaction_id: 123,
deployment_started_comment_id: 123456,
timestamp: '2025-01-01T00:00:00.000Z',
commit_verified: true,
actor: 'monalisa',
stable_branch_used: false
})
})
expect(await run()).toBe('success')
Expand Down
59 changes: 46 additions & 13 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

27 changes: 22 additions & 5 deletions docs/deployment-payload.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@ Here is the data that the branch-deploy Action will add to the deployment payloa

```json
{
"params": "<string>",
"parsed_params": "<object>",
"type": "branch-deploy",
"sha": "<string>",
"type": "branch-deploy"
"params": "<string>",
"parsed_params": {},
"github_run_id": 123,
"initial_comment_id": 123,
"initial_reaction_id": 123,
"deployment_started_comment_id": 123456,
"deployment_started_comment_id": 123123,
"timestamp": "2025-01-01T00:00:00.000Z",
"commit_verified": true,
"actor": "<string>",
"stable_branch_used": false
}
```

- `type` - This is the type of deployment that is being created. This will always be `branch-deploy` for the branch-deploy Action.
- `sha` - This is the commit SHA that is being deployed.
- `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).
- `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).
- `sha` - This is the commit SHA that is being deployed.
- `type` - This is the type of deployment that is being created. This will always be `branch-deploy` for the branch-deploy Action.
- `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.
- `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.
- `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.
- `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`
- `timestamp` - This is the timestamp of when the deployment was created from the perspective of the branch-deploy Action.
- `commit_verified` - This is a boolean that indicates whether the commit that is being deployed is verified.
- `actor` - This is the username of the user that triggered the deployment.
- `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.
3 changes: 3 additions & 0 deletions src/functions/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export async function createDeploymentStatus(
headers: API_HEADERS
})

core.debug(`deploymentStatus.id: ${result.id}`)
core.debug(`deploymentStatus.url: ${result.url}`)

return result
}

Expand Down
6 changes: 6 additions & 0 deletions src/functions/timestamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Helper function to generate an ISO 8601 formatted timestamp string
// :returns: An ISO 8601 formatted timestamp string (ex: 2025-01-01T00:00:00.000Z)
export function timestamp() {
const now = new Date()
return now.toISOString()
}
Loading

0 comments on commit 6caef4f

Please sign in to comment.