Skip to content

Commit cac5abd

Browse files
slack pipeline success notify#2
1 parent f5d7217 commit cac5abd

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

.github/workflows/pc.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ on:
77
paths-ignore:
88
- README.md
99
jobs:
10+
start-time-capture:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
workflow_start_time: ${{ steps.start.outputs.start_time_unix }}
14+
steps:
15+
- name: Capture Workflow Start Time
16+
id: start
17+
run: echo "start_time_unix=$(date +%s)" >> $GITHUB_OUTPUT
1018
secret-scanning:
1119
name: Secret scanning
1220
runs-on: ubuntu-latest
@@ -444,16 +452,19 @@ jobs:
444452
slack-pipeline-success-notify:
445453
name: Slack Pipeline Success Notify
446454
if: always()
447-
needs: test
455+
needs: [start-time-capture,test]
448456
runs-on: ubuntu-latest
449457
steps:
450458
- name: Calculate Workflow Duration
451459
id: workflow_duration
452460
run: |
453-
START_TIME=$(date -d "${{ github.event.workflow_run.created_at }}" +%s)
461+
START_TIME=${{ needs.start-time-capture.outputs.workflow_start_time }}
454462
END_TIME=$(date +%s)
455463
DURATION=$((END_TIME - START_TIME))
456-
echo "DURATION=$DURATION" >> $GITHUB_OUTPUT
464+
MINUTES=$((DURATION / 60))
465+
SECONDS=$((DURATION % 60))
466+
echo "MINUTES=$MINUTES" >> $GITHUB_OUTPUT
467+
echo "SECONDS=$SECONDS" >> $GITHUB_OUTPUT
457468
- name: Notify
458469
uses: slackapi/slack-github-action@v2.0.0
459470
if: always()
@@ -481,7 +492,7 @@ jobs:
481492
"type": "section",
482493
"text": {
483494
"type": "mrkdwn",
484-
"text":":watch: *Duration:* ${{ steps.workflow_duration.outputs.DURATION }} seconds."
495+
"text":":watch: *Duration:* ${{ steps.workflow_duration.outputs.MINUTES }} minutes and ${{ steps.workflow_duration.outputs.SECONDS }} seconds."
485496
}
486497
},
487498
]

0 commit comments

Comments
 (0)