Skip to content

Commit 6caab62

Browse files
authored
Publish summary in PR with GitHub Actions (#9)
* automatically publish CI Checker summary to a pull request (if exists) * use composite action to combine steps and have one step to set up the CI Checker action * share the summary artifact between steps to post comment * no configuration changes required Example: * https://github.com/postgres-ai/green-zone/runs/7539251035?check_suite_focus=true * test comment posting green-zone#8 (comment)
1 parent 10212ec commit 6caab62

File tree

4 files changed

+114
-39
lines changed

4 files changed

+114
-39
lines changed

action.yml

+33-31
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,8 @@ name: 'Database Lab: realistic DB testing in CI'
22
branding:
33
icon: 'database'
44
color: 'orange'
5-
description: 'Check database migrations with the Database Lab Engine'
5+
description: 'Test DB migrations using DB branches provided by Database Lab Engine (DLE)'
66
inputs:
7-
owner:
8-
description: 'The owner of the repository to check'
9-
required: true
10-
default: ${{ github.repository_owner }}
11-
repo:
12-
description: 'The repo to check'
13-
required: true
14-
default: ${{ github.event.repository.name }}
15-
ref:
16-
description: 'The input represents a ref parameter, which can be a SHA, branch, or tag'
17-
required: true
18-
default: ${{ github.ref }}
19-
pull_request:
20-
description: 'Link to the pull request'
21-
required: false
22-
default: ${{ github.event.pull_request.html_url }}
23-
compare:
24-
description: 'The compare link'
25-
required: false
26-
default: ${{ github.event.compare }}
27-
commit_sha:
28-
description: 'Commit SHA'
29-
required: false
30-
default: ${{ github.event.after }}
31-
author_name:
32-
description: 'Author name'
33-
required: false
34-
default: ${{ github.event.head_commit.author.name }}
357
commands:
368
description: 'List of commands to run DB migrations'
379
required: true
@@ -62,7 +34,37 @@ inputs:
6234

6335
outputs:
6436
response:
37+
value: Done
6538
description: 'The result of migration checks'
39+
6640
runs:
67-
using: 'docker'
68-
image: 'Dockerfile'
41+
using: 'composite'
42+
steps:
43+
- name: DB migration with DLE
44+
uses: postgres-ai/dle-github-actions/core@master
45+
with:
46+
commands: ${{ inputs.commands }}
47+
dbname: ${{ inputs.dbname }}
48+
migration_envs: ${{ inputs.migration_envs }}
49+
download_artifacts: ${{ inputs.download_artifacts }}
50+
observation_interval: ${{ inputs.observation_interval }}
51+
max_lock_duration: ${{ inputs.max_lock_duration }}
52+
max_duration: ${{ inputs.max_duration }}
53+
54+
- id: comment-body
55+
run: |
56+
body="$(cat report.md)"
57+
body="${body//'%'/'%25'}"
58+
body="${body//$'\n'/'%0A'}"
59+
body="${body//$'\r'/'%0D'}"
60+
echo "::set-output name=body::$body"
61+
shell: bash
62+
working-directory: artifacts
63+
if: ${{ always() }}
64+
65+
- name: Post comment to PR
66+
if: ${{ always() && github.event_name == 'pull_request' }}
67+
uses: peter-evans/create-or-update-comment@v2
68+
with:
69+
issue-number: ${{ github.event.pull_request.number }}
70+
body: ${{ steps.comment-body.outputs.body }}
File renamed without changes.

core/action.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: 'Database Lab: realistic DB testing in CI'
2+
branding:
3+
icon: 'database'
4+
color: 'orange'
5+
description: 'Test DB migrations using DB branches provided by Database Lab Engine (DLE)'
6+
inputs:
7+
owner:
8+
description: 'Repository owner'
9+
required: true
10+
default: ${{ github.repository_owner }}
11+
repo:
12+
description: 'Repository'
13+
required: true
14+
default: ${{ github.event.repository.name }}
15+
ref:
16+
description: 'Ref (SHA, branch, or tag) that needs to be tested'
17+
required: true
18+
default: ${{ github.ref }}
19+
pull_request:
20+
description: 'GitHub PR (URL)'
21+
required: false
22+
default: ${{ github.event.pull_request.html_url }}
23+
compare:
24+
description: 'GitHub PR comparison URL'
25+
required: false
26+
default: ${{ github.event.compare }}
27+
commit_sha:
28+
description: 'Commit SHA'
29+
required: false
30+
default: ${{ github.event.after }}
31+
author_name:
32+
description: 'Author name'
33+
required: false
34+
default: ${{ github.event.head_commit.author.name }}
35+
36+
commands:
37+
description: 'List of commands to run DB migrations'
38+
required: true
39+
dbname:
40+
description: 'Database name'
41+
required: false
42+
default: ""
43+
migration_envs:
44+
description: 'List of environment variables that will be set before testing'
45+
required: false
46+
download_artifacts:
47+
description: 'Store artifacts and allow downloading them'
48+
required: false
49+
default: "false"
50+
51+
observation_interval:
52+
description: 'Observation interval, seconds (default: 10)'
53+
required: false
54+
default: "10"
55+
max_lock_duration:
56+
description: 'Exclusive lock duration threshold, seconds (default: 10)'
57+
required: false
58+
default: "10"
59+
max_duration:
60+
description: 'DB migration duration threshold, seconds (default: 3600)'
61+
required: false
62+
default: "3600"
63+
64+
65+
outputs:
66+
response:
67+
description: 'DB migration testing results'
68+
runs:
69+
using: 'docker'
70+
image: 'Dockerfile'

entrypoint.sh renamed to core/entrypoint.sh

+11-8
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ if [[ $response_code -ne 200 ]]; then
4343
exit 1
4444
fi
4545

46-
status=$(jq -r '.session.result.status' response.json)
47-
48-
if [[ $status != "passed" ]]; then
49-
echo "Migration status: ${status}"
50-
exit 1
51-
fi
52-
5346
echo "::set-output name=response::$(cat response.json)"
5447

5548
clone_id=$(jq -r '.clone_id' response.json)
@@ -80,11 +73,21 @@ cat response.json | jq -c -r '.session.artifacts[]' | while read artifact; do
8073
download_artifacts $artifact $session_id $clone_id
8174
done
8275

76+
# Download report
77+
download_artifacts 'report.md' $session_id $clone_id
78+
8379
# Stop the running clone
8480
response_code=$(curl --show-error --silent "${DLMC_CI_ENDPOINT}/artifact/stop?clone_id=${clone_id}" --write-out "%{http_code}" \
8581
--header "Verification-Token: ${DLMC_VERIFICATION_TOKEN}" \
8682
--header 'Content-Type: application/json')
8783

8884
if [[ $response_code -ne 200 ]]; then
89-
echo "Invalid status code given on destroy clone: ${artifact_code}"
85+
echo "Invalid status code given on destroy clone: ${response_code}"
86+
fi
87+
88+
status=$(jq -r '.session.result.status' response.json)
89+
90+
if [[ $status != "passed" ]]; then
91+
echo "Migration status: ${status}"
92+
exit 1
9093
fi

0 commit comments

Comments
 (0)