Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Cleanup + SHA outputs for merge deploy mode #343

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading