Skip to content

Commit

Permalink
Merge pull request #343 from github/improvements
Browse files Browse the repository at this point in the history
General Cleanup + SHA outputs for merge deploy mode
  • Loading branch information
GrantBirki authored Dec 13, 2024
2 parents fe8542c + 23d5f20 commit 304e4d2
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 119 deletions.
17 changes: 16 additions & 1 deletion __tests__/functions/identical-commit-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core'
import {identicalCommitCheck} from '../../src/functions/identical-commit-check'
import {COLORS} from '../../src/functions/colors'

const saveStateMock = jest.spyOn(core, 'saveState')
const setOutputMock = jest.spyOn(core, 'setOutput')
const infoMock = jest.spyOn(core, 'info')

Expand All @@ -13,6 +14,7 @@ beforeEach(() => {
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
jest.spyOn(core, 'info').mockImplementation(() => {})
jest.spyOn(core, 'debug').mockImplementation(() => {})
jest.spyOn(core, 'saveState').mockImplementation(() => {})

context = {
repo: {
Expand All @@ -37,7 +39,7 @@ beforeEach(() => {
getBranch: jest.fn().mockReturnValue({
data: {
commit: {
sha: 'deadbeef',
sha: 'abcdef',
commit: {
tree: {
sha: 'deadbeef'
Expand Down Expand Up @@ -89,6 +91,8 @@ test('checks if the default branch sha and deployment sha are identical, and the
)
expect(setOutputMock).toHaveBeenCalledWith('continue', 'false')
expect(setOutputMock).toHaveBeenCalledWith('environment', 'production')
expect(setOutputMock).not.toHaveBeenCalledWith('sha', 'abcdef')
expect(saveStateMock).not.toHaveBeenCalledWith('sha', 'abcdef')
})

test('checks if the default branch sha and deployment sha are identical, and they are not', async () => {
Expand All @@ -105,9 +109,20 @@ test('checks if the default branch sha and deployment sha are identical, and the
expect(
await identicalCommitCheck(octokit, context, 'production')
).toStrictEqual(false)
expect(infoMock).toHaveBeenCalledWith(
`📍 latest commit sha on ${COLORS.highlight}main${COLORS.reset}: ${COLORS.info}abcdef${COLORS.reset}`
)
expect(infoMock).toHaveBeenCalledWith(
`🌲 latest default ${COLORS.info}branch${COLORS.reset} tree sha: ${COLORS.info}deadbeef${COLORS.reset}`
)
expect(infoMock).toHaveBeenCalledWith(
`🌲 latest ${COLORS.info}deployment${COLORS.reset} tree sha: ${COLORS.info}beefdead${COLORS.reset}`
)
expect(infoMock).toHaveBeenCalledWith(
`🚀 a ${COLORS.success}new deployment${COLORS.reset} will be created based on your configuration`
)
expect(setOutputMock).toHaveBeenCalledWith('continue', 'true')
expect(setOutputMock).toHaveBeenCalledWith('environment', 'production')
expect(setOutputMock).toHaveBeenCalledWith('sha', 'abcdef')
expect(saveStateMock).toHaveBeenCalledWith('sha', 'abcdef')
})
7 changes: 4 additions & 3 deletions __tests__/functions/trigger-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as core from '@actions/core'
import {COLORS} from '../../src/functions/colors'

const color = COLORS.highlight
const colorReset = COLORS.reset
const infoMock = jest.spyOn(core, 'info')
const debugMock = jest.spyOn(core, 'debug')

Expand All @@ -18,7 +19,7 @@ test('checks a message and finds a standard trigger', async () => {
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(true)
expect(infoMock).toHaveBeenCalledWith(
`✅ comment body starts with trigger: ${color}.deploy`
`✅ comment body starts with trigger: ${color}.deploy${colorReset}`
)
})

Expand All @@ -27,7 +28,7 @@ test('checks a message and does not find trigger', async () => {
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(debugMock).toHaveBeenCalledWith(
`comment body does not start with trigger: ${color}.deploy`
`comment body does not start with trigger: ${color}.deploy${colorReset}`
)
})

Expand All @@ -50,6 +51,6 @@ test('checks a message and does not find global trigger', async () => {
const trigger = '.deploy'
expect(await triggerCheck(body, trigger)).toBe(false)
expect(debugMock).toHaveBeenCalledWith(
`comment body does not start with trigger: ${color}.deploy`
`comment body does not start with trigger: ${color}.deploy${colorReset}`
)
})
163 changes: 105 additions & 58 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.

2 changes: 2 additions & 0 deletions docs/merge-commit-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
# Check out the repository
- uses: actions/checkout@v4
if: ${{ steps.deployment-check.outputs.continue == 'true' }} # only run if the Action returned 'true' for the 'continue' output
with:
ref: ${{ steps.deployment-check.outputs.sha }} # checkout the EXACT sha of the default branch for deployment (latest commit on the default branch)

# Do your deployment here! (However you want to do it)
# This could be deployment logic via SSH, Terraform, AWS, Heroku, etc.
Expand Down
12 changes: 6 additions & 6 deletions src/functions/action-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ export async function actionStatus(
reaction = thumbsDown
}

// add a reaction to the issue_comment to indicate success or failure
await octokit.rest.reactions.createForIssueComment({
// remove the initial reaction on the IssueOp comment that triggered this action
await octokit.rest.reactions.deleteForIssueComment({
...context.repo,
comment_id: context.payload.comment.id,
content: reaction,
reaction_id: reactionId,
headers: API_HEADERS
})

// remove the initial reaction on the IssueOp comment that triggered this action
await octokit.rest.reactions.deleteForIssueComment({
// add a reaction to the issue_comment to indicate success or failure
await octokit.rest.reactions.createForIssueComment({
...context.repo,
comment_id: context.payload.comment.id,
reaction_id: reactionId,
content: reaction,
headers: API_HEADERS
})
}
Loading

0 comments on commit 304e4d2

Please sign in to comment.