Skip to content

Publish summary in PR with GitHub Actions #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,8 @@ name: 'Database Lab: realistic DB testing in CI'
branding:
icon: 'database'
color: 'orange'
description: 'Check database migrations with the Database Lab Engine'
description: 'Test DB migrations using DB branches provided by Database Lab Engine (DLE)'
inputs:
owner:
description: 'The owner of the repository to check'
required: true
default: ${{ github.repository_owner }}
repo:
description: 'The repo to check'
required: true
default: ${{ github.event.repository.name }}
ref:
description: 'The input represents a ref parameter, which can be a SHA, branch, or tag'
required: true
default: ${{ github.ref }}
pull_request:
description: 'Link to the pull request'
required: false
default: ${{ github.event.pull_request.html_url }}
compare:
description: 'The compare link'
required: false
default: ${{ github.event.compare }}
commit_sha:
description: 'Commit SHA'
required: false
default: ${{ github.event.after }}
author_name:
description: 'Author name'
required: false
default: ${{ github.event.head_commit.author.name }}
commands:
description: 'List of commands to run DB migrations'
required: true
Expand Down Expand Up @@ -62,7 +34,37 @@ inputs:

outputs:
response:
value: Done
description: 'The result of migration checks'

runs:
using: 'docker'
image: 'Dockerfile'
using: 'composite'
steps:
- name: DB migration with DLE
uses: postgres-ai/dle-github-actions/core@master
with:
commands: ${{ inputs.commands }}
dbname: ${{ inputs.dbname }}
migration_envs: ${{ inputs.migration_envs }}
download_artifacts: ${{ inputs.download_artifacts }}
observation_interval: ${{ inputs.observation_interval }}
max_lock_duration: ${{ inputs.max_lock_duration }}
max_duration: ${{ inputs.max_duration }}

- id: comment-body
run: |
body="$(cat report.md)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=body::$body"
shell: bash
working-directory: artifacts
if: ${{ always() }}

- name: Post comment to PR
if: ${{ always() && github.event_name == 'pull_request' }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.comment-body.outputs.body }}
File renamed without changes.
70 changes: 70 additions & 0 deletions core/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: 'Database Lab: realistic DB testing in CI'
branding:
icon: 'database'
color: 'orange'
description: 'Test DB migrations using DB branches provided by Database Lab Engine (DLE)'
inputs:
owner:
description: 'Repository owner'
required: true
default: ${{ github.repository_owner }}
repo:
description: 'Repository'
required: true
default: ${{ github.event.repository.name }}
ref:
description: 'Ref (SHA, branch, or tag) that needs to be tested'
required: true
default: ${{ github.ref }}
pull_request:
description: 'GitHub PR (URL)'
required: false
default: ${{ github.event.pull_request.html_url }}
compare:
description: 'GitHub PR comparison URL'
required: false
default: ${{ github.event.compare }}
commit_sha:
description: 'Commit SHA'
required: false
default: ${{ github.event.after }}
author_name:
description: 'Author name'
required: false
default: ${{ github.event.head_commit.author.name }}

commands:
description: 'List of commands to run DB migrations'
required: true
dbname:
description: 'Database name'
required: false
default: ""
migration_envs:
description: 'List of environment variables that will be set before testing'
required: false
download_artifacts:
description: 'Store artifacts and allow downloading them'
required: false
default: "false"

observation_interval:
description: 'Observation interval, seconds (default: 10)'
required: false
default: "10"
max_lock_duration:
description: 'Exclusive lock duration threshold, seconds (default: 10)'
required: false
default: "10"
max_duration:
description: 'DB migration duration threshold, seconds (default: 3600)'
required: false
default: "3600"


outputs:
response:
description: 'DB migration testing results'
runs:
using: 'docker'
image: 'Dockerfile'
19 changes: 11 additions & 8 deletions entrypoint.sh → core/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ if [[ $response_code -ne 200 ]]; then
exit 1
fi

status=$(jq -r '.session.result.status' response.json)

if [[ $status != "passed" ]]; then
echo "Migration status: ${status}"
exit 1
fi

echo "::set-output name=response::$(cat response.json)"

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

# Download report
download_artifacts 'report.md' $session_id $clone_id

# Stop the running clone
response_code=$(curl --show-error --silent "${DLMC_CI_ENDPOINT}/artifact/stop?clone_id=${clone_id}" --write-out "%{http_code}" \
--header "Verification-Token: ${DLMC_VERIFICATION_TOKEN}" \
--header 'Content-Type: application/json')

if [[ $response_code -ne 200 ]]; then
echo "Invalid status code given on destroy clone: ${artifact_code}"
echo "Invalid status code given on destroy clone: ${response_code}"
fi

status=$(jq -r '.session.result.status' response.json)

if [[ $status != "passed" ]]; then
echo "Migration status: ${status}"
exit 1
fi