Modify workflows for better reporting (#124) #138
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 | |
with: | |
fetch-depth: 0 | |
- 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 data for Pull Request | |
if: ${{ github.event_name == 'pull_request' }} | |
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 "overall_time=$formatted_time" >> $GITHUB_ENV | |
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_ENV | |
echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV | |
echo "pr_url=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV | |
echo "diff=${{ github.event.pull_request.html_url }}/commits/${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | |
echo "commit_message=$(git log --format=%s -n 1 ${{ github.event.pull_request.head.sha }})" >> $GITHUB_ENV | |
echo "commit=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | |
echo "author=$(git log --format='%an <%ae>' -n 1 ${{ github.sha }})" >> $GITHUB_ENV | |
echo "date=$(git show -s --format=%ci ${{ github.sha }} | xargs -I{} date -d {} +'%a %b %d %T %Y %z')" >> $GITHUB_ENV | |
echo "current_job_status=${{ job.status }}" >> $GITHUB_ENV | |
- name: Record job data for push event | |
if: ${{ github.event_name == 'push' }} | |
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 "overall_time=$formatted_time" >> $GITHUB_ENV | |
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV | |
echo "diff=${{ github.event.compare }}" >> $GITHUB_ENV | |
echo "commit_message=$(git log --format=%s -n 1 ${{ github.sha }})" >> $GITHUB_ENV | |
echo "commit=${{ github.sha }}" >> $GITHUB_ENV | |
echo "author=${{ github.event.pusher.name }}" >> $GITHUB_ENV | |
echo "date=$(git show -s --format=%ci ${{ github.sha }} | xargs -I{} date -d {} +'%a %b %d %T %Y %z')" >> $GITHUB_ENV | |
echo "current_job_status=${{ job.status }}" >> $GITHUB_ENV | |
- name: Post to Slack about the result of the Pull Request | |
if: ( always() && ${{ github.event_name == 'pull_request' }} ) | |
uses: slackapi/[email protected] | |
with: | |
channel-id: 'C05P40DCGAK' | |
payload-file-path: ".github/workflows/payloads/pr_payload.json" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_WORKABLE_APP_OAUTH_TOKEN }} | |
- name: Post to Slack about the result of the push | |
if: ( always() && ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) ) | |
id: slack | |
uses: slackapi/[email protected] | |
with: | |
channel-id: 'C05P40DCGAK' | |
payload-file-path: ".github/workflows/payloads/push_payload.json" | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_WORKABLE_APP_OAUTH_TOKEN }} |