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

[Prod] Properly track eventSubmitted, updates to Slack message around PR deploys #2343

Merged
merged 28 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
66149d7
Test PR extraction
kryswisnaskas Aug 27, 2024
4aec377
Test post-merge extraction
kryswisnaskas Aug 28, 2024
9fb0ff5
Remove whitespace
kryswisnaskas Aug 28, 2024
46dc9ce
Add checkout to the job's steps
kryswisnaskas Aug 28, 2024
e44f5d6
Add debugging
kryswisnaskas Aug 28, 2024
7616a1a
split logic
kryswisnaskas Aug 28, 2024
67e54c8
Handle PR context
kryswisnaskas Aug 28, 2024
9e83014
Add context
kryswisnaskas Aug 28, 2024
e99a814
Update known dependencies
kryswisnaskas Aug 28, 2024
55b26d9
Merge pull request #2332 from HHS/kw-test-extraction
kryswisnaskas Aug 28, 2024
c3f9d97
Cleanup
kryswisnaskas Aug 28, 2024
2f14e6b
Merge pull request #2334 from HHS/kw-test-extraction
kryswisnaskas Aug 28, 2024
3a4d932
Forgot to save
kryswisnaskas Aug 28, 2024
6278373
Remove PR_TITLE
kryswisnaskas Aug 28, 2024
7b6b2b7
Merge pull request #2336 from HHS/kw-test-extraction
kryswisnaskas Aug 28, 2024
60bf5a1
Extract PR number from the merge commit
kryswisnaskas Aug 28, 2024
59f7e78
Remove test job
kryswisnaskas Aug 28, 2024
9bf6514
Merge branch 'main' into kw-fix-missing-pr
kryswisnaskas Aug 28, 2024
e163caa
Test deploy
kryswisnaskas Aug 29, 2024
a6cf802
Merge branch 'main' into kw-fix-missing-pr
kryswisnaskas Aug 29, 2024
c36672b
Merge branch 'main' into kw-test-deploy
kryswisnaskas Aug 29, 2024
070fd41
Merge branch 'kw-fix-missing-pr' into kw-test-deploy
kryswisnaskas Aug 29, 2024
e4429b4
Add missing tag
kryswisnaskas Aug 29, 2024
7ab7e89
Remove debugging messages
kryswisnaskas Aug 29, 2024
5044b2e
Merge pull request #2339 from HHS/kw-test-deploy
kryswisnaskas Aug 29, 2024
6278c2f
Merge pull request #2331 from HHS/kw-fix-missing-pr
kryswisnaskas Aug 29, 2024
9f2fa99
Set event submitted: true when event is being submitted
thewatermethod Aug 30, 2024
469001b
Merge pull request #2342 from HHS/TTAHUB/properly-set-event-submitted
thewatermethod Aug 30, 2024
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
127 changes: 83 additions & 44 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ commands:
description: "Name of environment"
type: string
steps:
- checkout
- run:
name: Generate Message
command: |
Expand All @@ -203,43 +204,41 @@ commands:
esac

env_name="<< parameters.environment_name >>"
set -x
if [ ! -z "${CIRCLE_PULL_REQUEST}" ]; then
PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}

# Debugging output
echo "CIRCLE_PULL_REQUEST: ${CIRCLE_PULL_REQUEST}"
echo "Extracted PR_NUMBER: ${PR_NUMBER}"
if [ -n "${CIRCLE_PULL_REQUEST}" ]; then
PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}

PR_TITLE=$(curl -s "${CIRCLE_PULL_REQUEST}" | sed -e :a -e "N; s/\n/ /g; ta" | grep -oP "<bdi class=\"js-issue-title markdown-title\">[^<]+</bdi>" | sed -re "s~<[^>]+>~~g")
# Debugging output
echo "Extracted PR_TITLE: ${PR_TITLE}"

if [ ! -z "${PR_TITLE}" ]; then
JIRA_URLS=$(curl -s "${CIRCLE_PULL_REQUEST}" | sed -e :a -e "N; s/\n/ /g; ta" | grep -oP "Issue[(]s[)]</h2>.*Checklists</h2>" | grep -oP "\"https[^\"]+\"" | sed -e "s~\"~~g" | grep -o "https://jira.acf.gov/browse/[A-Z0-9-]*")

# Debugging output
echo "Extracted JIRA_URLS: ${JIRA_URLS}"

MESSAGE_TEXT=":rocket: Deployment of PR <${CIRCLE_PULL_REQUEST}|${PR_NUMBER}> (${PR_TITLE}) to <${ENV_URL}|${env_name}> was successful!"
if [ ! -z "${JIRA_URLS}" ]; then
if [ -n "${JIRA_URLS}" ]; then
MESSAGE_TEXT="${MESSAGE_TEXT}\nJIRA URLs in the PR:\n${JIRA_URLS}"
fi
else
MESSAGE_TEXT=":rocket: Deployment of PR <${CIRCLE_PULL_REQUEST}|${PR_NUMBER}> to <${ENV_URL}|${env_name}> was successful!"
fi
else
MESSAGE_TEXT=":rocket: Deployment to <${ENV_URL}|${env_name}> was successful!"
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if echo "$COMMIT_MESSAGE" | grep -q "Merge pull request #"; then
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '(?<=Merge pull request #)\d+')
MESSAGE_TEXT=":rocket: Deployment of PR #${PR_NUMBER} to <${ENV_URL}|${env_name}> was successful!"
if [ ! -z "${JIRA_URLS}" ]; then
MESSAGE_TEXT="${MESSAGE_TEXT}\nJIRA URLs in the PR:\n${JIRA_URLS}"
fi
else
MESSAGE_TEXT=":rocket: Deployment to <${ENV_URL}|${env_name}> was successful!"
fi
fi

echo -e "${MESSAGE_TEXT}" > /tmp/message_file

- notify_slack:
slack_bot_token: << parameters.slack_bot_token >>
slack_channel: << parameters.slack_channel >>
message_text_file: "/tmp/message_file"


cf_deploy:
description: "Login to cloud foundry space with service account credentials
and push application using deployment configuration file."
Expand Down Expand Up @@ -562,8 +561,8 @@ parameters:
description: "Name of github branch that will deploy to dev"
default: "al-ttahub-3196-new-tr-views"
type: string
sandbox_git_branch: # change to feature branch to test deployment
default: "mb/TTAHUB-3198/training-report-alerts"
sandbox_git_branch: # change to feature branch to test deployment
default: "kw-test-deploy"
type: string
prod_new_relic_app_id:
default: "877570491"
Expand Down Expand Up @@ -621,9 +620,9 @@ jobs:
command: |
chmod +x ./bin/check_node_version_compatibility.sh
./bin/check_node_version_compatibility.sh
- store_artifacts: # store backend lint reports
- store_artifacts: # store backend lint reports
path: reports
- store_artifacts: # store frontend lint reports
- store_artifacts: # store frontend lint reports
path: frontend/reports
- run:
name: Remove similarity api data
Expand Down Expand Up @@ -662,9 +661,9 @@ jobs:
paths:
- similarity_api/src/venv
key: v1-pip-deps-{{ checksum "combined-requirements.txt" }}
- store_artifacts: # store backend lint reports
- store_artifacts: # store backend lint reports
path: reports
- store_artifacts: # store frontend lint reports
- store_artifacts: # store frontend lint reports
path: similarity_api/reports
- persist_to_workspace:
root: .
Expand All @@ -674,7 +673,7 @@ jobs:
test_backend:
executor: docker-postgres-executor
environment:
SFTP_EXPOSED_PORT: 2222
SFTP_EXPOSED_PORT: 2222
steps:
- attach_workspace:
at: .
Expand All @@ -693,7 +692,7 @@ jobs:
background: true
- run:
name: Test backend
command: |
command: |
chmod 744 ./bin/test-backend-ci
./bin/test-backend-ci
- run:
Expand All @@ -719,7 +718,7 @@ jobs:
SYFT_VERSION: v1.5.0
IMAGE_NAME: ghcr.io/kcirtapfromspace/cloudfoundry_circleci:latest
OUTPUT_FORMAT: json
OUTPUT_FILE: reports/syft_sbom.json
OUTPUT_FILE: reports/syft_sbom.json
command: |
mkdir -p reports/
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b . "$SYFT_VERSION"
Expand Down Expand Up @@ -946,22 +945,38 @@ jobs:
- when:
condition:
and:
- equal: [<< pipeline.project.git_url >>, << pipeline.parameters.prod_git_url >>]
- equal: [<< pipeline.git.branch >>, << pipeline.parameters.prod_git_branch >>]
- equal:
[
<< pipeline.project.git_url >>,
<< pipeline.parameters.prod_git_url >>,
]
- equal:
[
<< pipeline.git.branch >>,
<< pipeline.parameters.prod_git_branch >>,
]
steps:
- run:
name: Create production robot
command: ./bin/robot-factory
- run:
name: Create production robot
command: ./bin/robot-factory
- run:
name: Install Cloud Foundry
command: |
curl -v -L -o cf-cli_amd64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=v7&source=github'
sudo dpkg -i cf-cli_amd64.deb
- when: # sandbox: for short-term feature development, see README.md
- when: # sandbox: for short-term feature development, see README.md
condition:
and:
- equal: [<< pipeline.project.git_url >>, << pipeline.parameters.sandbox_git_url >>]
- equal: [<< pipeline.git.branch >>, << pipeline.parameters.sandbox_git_branch >>]
- equal:
[
<< pipeline.project.git_url >>,
<< pipeline.parameters.sandbox_git_url >>,
]
- equal:
[
<< pipeline.git.branch >>,
<< pipeline.parameters.sandbox_git_branch >>,
]
steps:
- run:
name: Build frontend assets
Expand Down Expand Up @@ -1016,11 +1031,19 @@ jobs:
slack_channel: "acf-head-start-github"
environment_name: "sandbox"

- when: # dev
- when: # dev
condition:
and:
- equal: [<< pipeline.project.git_url >>, << pipeline.parameters.dev_git_url >>]
- equal: [<< pipeline.git.branch >>, << pipeline.parameters.dev_git_branch >>]
- equal:
[
<< pipeline.project.git_url >>,
<< pipeline.parameters.dev_git_url >>,
]
- equal:
[
<< pipeline.git.branch >>,
<< pipeline.parameters.dev_git_branch >>,
]
steps:
- run:
name: Build frontend assets
Expand Down Expand Up @@ -1075,11 +1098,19 @@ jobs:
slack_channel: "acf-head-start-github"
environment_name: "dev"

- when: # staging
- when: # staging
condition:
and:
- equal: [<< pipeline.project.git_url >>, << pipeline.parameters.staging_git_url >>]
- equal: [<< pipeline.git.branch >>, << pipeline.parameters.staging_git_branch >>]
- equal:
[
<< pipeline.project.git_url >>,
<< pipeline.parameters.staging_git_url >>,
]
- equal:
[
<< pipeline.git.branch >>,
<< pipeline.parameters.staging_git_branch >>,
]
steps:
- run:
name: Build frontend assets
Expand Down Expand Up @@ -1132,11 +1163,19 @@ jobs:
slack_channel: "acf-head-start-github"
environment_name: "staging"

- when: # prod
- when: # prod
condition:
and:
- equal: [<< pipeline.project.git_url >>, << pipeline.parameters.prod_git_url >>]
- equal: [<< pipeline.git.branch >>, << pipeline.parameters.prod_git_branch >>]
- equal:
[
<< pipeline.project.git_url >>,
<< pipeline.parameters.prod_git_url >>,
]
- equal:
[
<< pipeline.git.branch >>,
<< pipeline.parameters.prod_git_branch >>,
]
steps:
- run:
name: Build frontend assets
Expand Down Expand Up @@ -1194,10 +1233,10 @@ jobs:
docker:
- image: cimg/base:2024.05
steps:
- sparse_checkout:
directories: 'automation'
- sparse_checkout:
directories: "automation"
branch: << pipeline.git.branch >>
- cf_backup:
- cf_backup:
auth_client_secret: PROD_AUTH_CLIENT_SECRET
cloudgov_username: CLOUDGOV_PROD_USERNAME
cloudgov_password: CLOUDGOV_PROD_PASSWORD
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/pages/TrainingReportForm/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,39 @@ describe('TrainingReportForm', () => {
await waitFor(() => expect(screen.getByText(/: e-1 event/i)).toBeInTheDocument());
await waitFor(() => expect(screen.getByText(/r01-pd-1234/i)).toBeInTheDocument());
});
it('passes correct values to backend', async () => {
fetchMock.get('/api/events/id/1', completedForm);

fetchMock.put('/api/events/id/1', {});
fetchMock.get(sessionsUrl, [
{ id: 2, eventId: 1, data: { sessionName: 'Toothbrushing vol 2', status: 'Complete' } },
{ id: 3, eventId: 1, data: { sessionName: 'Toothbrushing vol 3', status: 'Complete' } },
]);

act(() => {
renderTrainingReportForm('1');
});

await waitFor(() => expect(fetchMock.called('/api/events/id/1', { method: 'GET' })).toBe(true));
const submitButton = await screen.findByRole('button', { name: /Review and submit/i });
act(() => {
userEvent.click(submitButton);
});

// Wait for the modal to display.
await waitFor(() => expect(screen.getByText(/You will not be able to make changes once you save the event./i)).toBeInTheDocument());

// get the button with the text "Yes, continue".
const yesContinueButton = screen.getByRole('button', { name: /Yes, continue/i });
act(() => {
userEvent.click(yesContinueButton);
});

await waitFor(() => expect(fetchMock.called('/api/events/id/1', { method: 'PUT' })).toBe(true));

// expect the data to contain "eventSubmitted: true"
expect(fetchMock.lastOptions('/api/events/id/1').body).toContain('"eventSubmitted":true');

await waitFor(() => expect(screen.getByText(/There was an error saving the training report/i)).toBeInTheDocument());
});
});
5 changes: 4 additions & 1 deletion frontend/src/pages/TrainingReportForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ export default function TrainingReportForm({ match }) {

// PUT it to the backend
const updatedEvent = await updateEvent(trainingReportId, {
data,
data: {
...data,
eventSubmitted: true,
},
ownerId: ownerId || null,
pocIds: pocIds || null,
collaboratorIds,
Expand Down