Skip to content

Commit abb3ae5

Browse files
authored
Use updated actions for comments (#125)
* Use updated actions for comments * Update actions version * Set dependency for pipelines_status job * Pass CLI version to tg-comment update * Bump pipelines version * Update pipelines.yml * Checkout repo in finalize job * Get customer token * Use pipelines-cli v0.40.0-rc5 * Use renamed actions * Use updated binary * Use rc7 binary * Update to pipelines v0.40.0-rc8 * Update to use latest actions * Use Pipelines binary rc9 * Update to pipelines binary rc10 * Remove deprecated step * Set artifact token correctly on finalize request * Set working directory for Pipelines status step
1 parent 2996be3 commit abb3ae5

File tree

4 files changed

+293
-93
lines changed

4 files changed

+293
-93
lines changed

.github/workflows/pipelines-drift-detection.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ on:
3131
type: string
3232
default: "https://api.prod.app.gruntwork.io/api/v1"
3333
secrets:
34-
PIPELINES_READ_TOKEN:
35-
required: false
36-
PR_CREATE_TOKEN:
37-
required: false
34+
PIPELINES_READ_TOKEN:
35+
required: false
36+
PR_CREATE_TOKEN:
37+
required: false
3838
env:
39-
PIPELINES_CLI_VERSION: v0.39.0
40-
PIPELINES_ACTIONS_VERSION: v3.6.4
39+
PIPELINES_CLI_VERSION: v0.40.0-rc10
40+
PIPELINES_ACTIONS_VERSION: ore/dev-927-rework-pipelines-status-update-action
4141
BOILERPLATE_VERSION: v0.5.16
4242
GRUNTWORK_INSTALLER_VERSION: v0.0.40
4343

@@ -56,7 +56,6 @@ jobs:
5656
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
5757
api_base_url: ${{ inputs.api_base_url }}
5858

59-
6059
- name: Fetch Org Read Token
6160
id: pipelines-customer-org-read-token
6261
uses: gruntwork-io/pipelines-credentials@v1

.github/workflows/pipelines-root.yml

Lines changed: 149 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ on:
3838
required: false
3939

4040
env:
41-
PIPELINES_CLI_VERSION: v0.39.0
42-
PIPELINES_ACTIONS_VERSION: v3.6.4
41+
PIPELINES_CLI_VERSION: v0.40.0-rc10
42+
PIPELINES_ACTIONS_VERSION: ore/dev-927-rework-pipelines-status-update-action
4343
BOILERPLATE_VERSION: v0.5.16
4444
GRUNTWORK_INSTALLER_VERSION: v0.0.40
4545

@@ -107,7 +107,7 @@ jobs:
107107
ref: ${{ env.PIPELINES_ACTIONS_VERSION }}
108108
token: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
109109

110-
- name: Validate PIPELINES_READ_TOKEN
110+
- name: Report error if token with access to gruntwork repos is invalid
111111
if: always() && steps.checkout_actions.conclusion != 'success'
112112
env:
113113
GH_TOKEN: ${{ github.token }}
@@ -117,7 +117,7 @@ jobs:
117117
run: |
118118
logs_url="https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
119119
msg=$(printf "<h2>❌ Plan for $PR_HEAD_SHA</h2>❌ Gruntwork Pipelines was unable to checkout the <code>pipelines-actions</code> repository. Please ensure the <code>PIPELINES_READ_TOKEN</code> is valid and unexpired. <a href=\"https://docs.gruntwork.io/pipelines/security/machine-users#ci-read-only-user\">Learn More</a><br><br><br><a href=\"$logs_url\">View full logs</a>")
120-
echo "::error:: $msg"
120+
echo "::error:: $msg" # Results in step failure but rest of logic in this step will still run
121121
echo "$msg" >> "$GITHUB_STEP_SUMMARY"
122122
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
123123
gh pr comment $pull_number -b "$msg" -R $GITHUB_ORG || true # || true incase this fails on a non-PR run
@@ -129,13 +129,19 @@ jobs:
129129
fetch-depth: 0
130130
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
131131

132+
- name: Install Pipelines CLI
133+
uses: ./pipelines-actions/.github/actions/pipelines-install
134+
with:
135+
version: ${{ env.PIPELINES_CLI_VERSION }}
136+
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
137+
132138
- name: Preflight Checks
133139
uses: ./pipelines-actions/.github/actions/pipelines-preflight-action
134140
with:
135141
IS_ROOT: "true"
136142
PIPELINES_READ_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
137143
INFRA_ROOT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
138-
ORG_REPO_ADMIN_TOKEN: ${{ steps.pipelines-org-repo-admin-token.outputs.PIPELINES_TOKEN }}
144+
ORG_REPO_ADMIN_TOKEN: ${{ steps.pipelines-org-repo-admin-token.outputs.PIPELINES_TOKEN }}
139145
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
140146
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
141147
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
@@ -196,6 +202,14 @@ jobs:
196202
FALLBACK_TOKEN: ${{ secrets.INFRA_ROOT_WRITE_TOKEN }}
197203
api_base_url: ${{ inputs.api_base_url }}
198204

205+
- name: Fetch Propose Infra Change Token
206+
id: pipelines-propose-infra-change-token
207+
uses: gruntwork-io/pipelines-credentials@v1
208+
with:
209+
PIPELINES_TOKEN_PATH: propose-infra-change/${{ github.repository_owner }}
210+
FALLBACK_TOKEN: ${{ secrets.INFRA_ROOT_WRITE_TOKEN }}
211+
api_base_url: ${{ inputs.api_base_url }}
212+
199213
- name: Checkout Pipelines Actions
200214
uses: actions/checkout@v4
201215
with:
@@ -211,11 +225,16 @@ jobs:
211225
fetch-depth: 0
212226
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
213227

228+
- name: Install Pipelines CLI
229+
uses: ./pipelines-actions/.github/actions/pipelines-install
230+
with:
231+
version: ${{ env.PIPELINES_CLI_VERSION }}
232+
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
233+
214234
- name: Bootstrap Workflow
215235
id: gruntwork_context
216236
uses: ./pipelines-actions/.github/actions/pipelines-bootstrap
217237
with:
218-
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
219238
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
220239
change_type: ${{ matrix.jobs.ChangeType }}
221240
branch: ${{ matrix.jobs.Ref }}
@@ -299,7 +318,7 @@ jobs:
299318
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
300319
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
301320

302-
- name: "[TerragruntExecute]: Authenticate with AWS and then Invoke Terragrunt"
321+
- name: "[TerragruntExecute]: Run terragrunt ${{ steps.gruntwork_context.outputs.terragrunt_command }} in ${{ steps.gruntwork_context.outputs.working_directory }}"
303322
id: terragrunt
304323
if: ${{ steps.gruntwork_context.outputs.action == 'TERRAGRUNT_EXECUTE' }}
305324
uses: ./pipelines-actions/.github/actions/pipelines-execute
@@ -318,27 +337,18 @@ jobs:
318337
deploy_branch_name: ${{ steps.gruntwork_context.outputs.deploy_branch_name }}
319338
stack_paths: ${{ toJson(matrix.jobs.StackPaths) }}
320339

321-
- name: Get Logs URL
322-
id: get_logs_url
323-
uses: ./pipelines-actions/.github/actions/pipelines-get-job-logs-url
324-
if: always()
325-
with:
326-
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
327-
job_name: ${{ env.JOB_NAME }}
328-
step_name_prefix: "${{ steps.gruntwork_context.outputs.action == 'TERRAGRUNT_EXECUTE' && '[TerragruntExecute]:\ Authenticate with AWS and then Invoke Terragrunt' || (steps.gruntwork_context.outputs.action == 'BASELINE_ACCOUNT' && 'Run core accounts baselines' || '[ProvisionAccount]:\ Provision New Account') }}"
329-
330340
- name: Update comment
331-
uses: ./pipelines-actions/.github/actions/pipelines-status-update
332341
if: always()
342+
uses: ./pipelines-actions/.github/actions/pipelines-comment-job-update
333343
with:
344+
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
334345
step_name: ${{ matrix.jobs.ChangeType }}
335346
step_working_directory: ${{ matrix.jobs.WorkingDirectory }}
347+
step_terragrunt_command: ${{ matrix.jobs.Action.Command }}
336348
step_status: ${{ (steps.provision_new_account.conclusion == 'success' || steps.terragrunt.conclusion == 'success' || steps.core_accounts_baselines.conclusion == 'success') && 'success' || 'failed' }}
337-
step_details: ${{ steps.terragrunt.outputs.formatted_plan_output }}
338-
step_details_extended_log: ${{ steps.terragrunt.outputs.execute_stdout_log }}
339-
pull_request_number: ${{ steps.gruntwork_context.outputs.pr_number }}
340-
step_logs_url: ${{ steps.get_logs_url.outputs.step_logs_url }}
341-
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
349+
plan_apply_log_file_path: ${{ steps.terragrunt.outputs.plan_folder }}
350+
extended_log_file_path: ${{ steps.terragrunt.outputs.execute_stdout_log }}
351+
job_name: ${{ env.JOB_NAME }}
342352

343353
outputs:
344354
account_id: ${{ matrix.jobs.AccountId }}
@@ -403,19 +413,28 @@ jobs:
403413
fetch-depth: 0
404414
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
405415

406-
- name: Update comment
407-
uses: ./pipelines-actions/.github/actions/pipelines-status-update
416+
- name: Install Pipelines CLI
417+
uses: ./pipelines-actions/.github/actions/pipelines-install
408418
with:
409-
step_name: Baseline Child Account ${{ matrix.jobs.Name }}
410-
step_status: "in_progress"
411-
pull_request_number: ${{ needs.pipelines_execute.outputs.pr_number }}
412-
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
419+
version: ${{ env.PIPELINES_CLI_VERSION }}
420+
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
421+
422+
- name: Update comment
423+
shell: bash
424+
working-directory: ./infra-live-repo
425+
env:
426+
GH_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
427+
ACTION: "Baseline Child Account ${{ matrix.jobs.Name }}"
428+
run: |
429+
pipelines scm create-change-request-comment \
430+
--working-directory "." \
431+
--auto-header \
432+
--comment "🔄 $ACTION..."
413433
414434
- name: Bootstrap Workflow
415435
id: gruntwork_context
416436
uses: ./pipelines-actions/.github/actions/pipelines-bootstrap
417437
with:
418-
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
419438
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
420439
change_type: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].ChangeType }}
421440
branch: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Ref }}
@@ -459,26 +478,17 @@ jobs:
459478
job: ${{ toJson(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0]) }}
460479
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
461480

462-
- name: Get Logs URL
463-
id: get_logs_url
464-
uses: ./pipelines-actions/.github/actions/pipelines-get-job-logs-url
465-
if: always()
466-
with:
467-
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
468-
job_name: ${{ env.JOB_NAME }}
469-
step_name_prefix: "[Baseline]: Baseline the Child Account"
470-
471481
- name: Update comment
472-
uses: ./pipelines-actions/.github/actions/pipelines-status-update
473-
if: always()
474-
with:
475-
step_name: Baseline Child Account ${{ matrix.jobs.Name }}
476-
step_status: ${{ steps.baseline_child_account.conclusion == 'success' && 'success' || 'failed' }}
477-
step_details: ${{ steps.baseline_child_account.outputs.formatted_plan_output || 'Check the logs for more details.' }}
478-
step_details_extended_log: ${{ steps.baseline_child_account.outputs.execute_stdout_log }}
479-
pull_request_number: ${{ needs.pipelines_execute.outputs.pr_number }}
480-
step_logs_url: ${{ steps.get_logs_url.outputs.step_logs_url }}
481-
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
482+
shell: bash
483+
working-directory: ./infra-live-repo
484+
env:
485+
GH_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
486+
ACTION: "Baseline Child Account ${{ matrix.jobs.Name }}"
487+
run: |
488+
pipelines scm create-change-request-comment \
489+
--working-directory "." \
490+
--auto-header \
491+
--comment "✅ $ACTION\nCheck the logs for more details."
482492
483493
pipelines_setup_delegated_repo:
484494
name: "Setup Delegated Repo"
@@ -526,11 +536,16 @@ jobs:
526536
fetch-depth: 0
527537
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
528538

539+
- name: Install Pipelines CLI
540+
uses: ./pipelines-actions/.github/actions/pipelines-install
541+
with:
542+
version: ${{ env.PIPELINES_CLI_VERSION }}
543+
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
544+
529545
- name: Bootstrap Workflow
530546
id: gruntwork_context
531547
uses: ./pipelines-actions/.github/actions/pipelines-bootstrap
532548
with:
533-
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
534549
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
535550
change_type: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].ChangeType }}
536551
branch: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Ref }}
@@ -585,3 +600,88 @@ jobs:
585600
pr_body: ${{ steps.provision_delegated_repo.outputs.pr_body }}
586601
requesting_pr_number: ${{ steps.provision_delegated_repo.outputs.requesting_pr_number }}
587602
step_summary_content: ${{ steps.provision_delegated_repo.outputs.step_summary_content }}
603+
604+
pipelines_status_check:
605+
name: "Pipelines Status Check"
606+
runs-on: ${{ fromJSON(inputs.runner) }}
607+
needs: [pipelines_orchestrate, pipelines_execute]
608+
if: always() && fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0] != null
609+
steps:
610+
- name: Record workflow env vars
611+
env:
612+
PIPELINES_BINARY_URL: ${{ inputs.pipelines_binary_url }}
613+
run: |
614+
time_now=$(date -u +"%s")
615+
echo "PIPELINES_JOB_START_TIME=$time_now" >> $GITHUB_ENV
616+
echo "PIPELINES_BINARY_URL=$PIPELINES_BINARY_URL" >> $GITHUB_ENV
617+
618+
- name: Fetch Gruntwork Read Token
619+
id: pipelines-gruntwork-read-token
620+
uses: gruntwork-io/pipelines-credentials@v1
621+
with:
622+
PIPELINES_TOKEN_PATH: "pipelines-read/gruntwork-io"
623+
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
624+
api_base_url: ${{ inputs.api_base_url }}
625+
626+
- name: Fetch Org Read Token
627+
id: pipelines-customer-org-read-token
628+
uses: gruntwork-io/pipelines-credentials@v1
629+
with:
630+
PIPELINES_TOKEN_PATH: pipelines-read/${{ github.repository_owner }}
631+
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
632+
api_base_url: ${{ inputs.api_base_url }}
633+
634+
- name: Fetch Create PR Token
635+
id: pipelines-propose-infra-change-token
636+
uses: gruntwork-io/pipelines-credentials@v1
637+
with:
638+
PIPELINES_TOKEN_PATH: propose-infra-change/${{ github.repository_owner }}
639+
FALLBACK_TOKEN: ${{ secrets.INFRA_ROOT_WRITE_TOKEN }}
640+
api_base_url: ${{ inputs.api_base_url }}
641+
642+
- name: Checkout Pipelines Actions
643+
uses: actions/checkout@v4
644+
with:
645+
path: pipelines-actions
646+
repository: gruntwork-io/pipelines-actions
647+
ref: ${{ env.PIPELINES_ACTIONS_VERSION }}
648+
token: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
649+
650+
- name: Check out repo code
651+
uses: actions/checkout@v4
652+
with:
653+
path: infra-live-repo
654+
fetch-depth: 0
655+
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
656+
657+
- name: Install Pipelines CLI
658+
uses: ./pipelines-actions/.github/actions/pipelines-install
659+
with:
660+
version: ${{ env.PIPELINES_CLI_VERSION }}
661+
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
662+
663+
- name: Check Status
664+
shell: bash
665+
working-directory: ./infra-live-repo
666+
env:
667+
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
668+
run: |
669+
GH_TOKEN="$PR_COMMENT_WRITE_TOKEN" \
670+
GH_ARTIFACT_TOKEN="$PR_COMMENT_WRITE_TOKEN" \
671+
pipelines status-update finalize \
672+
--working-directory . \
673+
--ci github-actions >/tmp/finalize-output.json
674+
675+
pipeline_status=$(jq -r '.status' </tmp/finalize-output.json)
676+
677+
cat /tmp/finalize-output.json
678+
679+
printf '%.s─' $(seq 1 "$(tput -T dumb cols)")
680+
echo " "
681+
if [[ "$pipeline_status" == "success" ]]; then
682+
echo -e "✅ \033[1;32mPipeline Passed\033[0m"
683+
exit 0
684+
else
685+
echo -e "❌ \033[1;31mPipeline Failed\033[0m"
686+
exit 1
687+
fi

0 commit comments

Comments
 (0)