Add slack notification for Pull Request #121
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
environment: Deploy | |
steps: | |
- name: Get starting time for reporting | |
id: start | |
run: echo "start_time=$(date +%s)" >> $GITHUB_OUTPUT | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Install python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
- name: Install poetry and run tests | |
run: | | |
git tag 0.0.0.dev | |
pip install poetry | |
poetry config virtualenvs.in-project true | |
make install | |
. .venv/bin/activate | |
make test | |
- name: Record job end time, calculate elapsed time, and get the latest commit message | |
id: end | |
run: | | |
end_time=$(date +%s) | |
start_time=${{ steps.start.outputs.start_time }} | |
elapsed_time=$(($end_time-$start_time)) | |
formatted_time=$(date -u -d @$elapsed_time +"%M:%S") | |
echo $formatted_time | |
echo "overall_time=$formatted_time" >> $GITHUB_OUTPUT | |
echo "commit_message=$(git log --format=%B -n 1)" >> $GITHUB_OUTPUT | |
- name: Post to a Slack channel | |
if: always() | |
id: slack | |
uses: slackapi/[email protected] | |
with: | |
channel-id: 'C05P40DCGAK' | |
payload: | | |
{ | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "G3 CI/PR-${{ github.event.pull_request.number }}: ${{ job.status }}\n```Time : ${{ steps.end.outputs.overall_time }}\nBranch : ${{ github.head_ref }}\nPR : ${{ github.event.pull_request.html_url }}\nDiff : ${{ github.event.pull_request.html_url }}/commits/${{ github.event.pull_request.head.sha }}\n\n ${{ steps.end.outputs.commit_message }}```" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_WORKABLE_APP_OAUTH_TOKEN }} |