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 19 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
57 changes: 27 additions & 30 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@ branding:
color: 'orange'
description: 'Check database migrations with the Database Lab Engine'
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,32 @@ 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: agneum/migration-action/core@composite-action
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 }}

- run: |
echo 'SUMMARY<<EOF' >> $GITHUB_ENV
cat summary.md >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
shell: bash

- name: Post comment to PR
if: ${{ github.event_name == 'pull_request' }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ env.SUMMARY }}
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: 'Check database migrations with the Database Lab Engine'
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
dbname:
description: 'The database that the workflow is running with'
required: false
default: ""
migration_envs:
description: 'List of environment variables that will be set during migrations running'
required: false
download_artifacts:
description: 'Option to download artifacts'
required: false
default: "false"

observation_interval:
description: 'Observation interval'
required: false
default: "10"
max_lock_duration:
description: 'Max lock duration'
required: false
default: "10"
max_duration:
description: 'Max duration'
required: false
default: "3600"


outputs:
response:
description: 'The result of CI checks'
runs:
using: 'docker'
image: 'Dockerfile'
15 changes: 13 additions & 2 deletions entrypoint.sh → core/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ JSON_DATA=$(jq -n -c \

echo $JSON_DATA

response_code=$(curl --show-error --silent --location --request POST "${DLMC_CI_ENDPOINT}/migration/run" --write-out "%{http_code}" \
response_code=$(curl -k --show-error --silent --location --request POST "${DLMC_CI_ENDPOINT}/migration/run" --write-out "%{http_code}" \
--header "Verification-Token: ${DLMC_VERIFICATION_TOKEN}" \
--header 'Content-Type: application/json' \
--output response.json \
--data "${JSON_DATA}")

jq . response.json

# TODO: remove after providing summary.md
export JSON_RESPONSE=$(cat response.json | jq)
echo "$(cat<<-EOL
### Summary
\`\`\`json
${JSON_RESPONSE}
\`\`\`
EOL
)" > summary.md


if [[ $response_code -ne 200 ]]; then
echo "Migration status code: ${response_code}"
exit 1
Expand All @@ -63,7 +74,7 @@ fi
mkdir artifacts

download_artifacts() {
artifact_code=$(curl --show-error --silent "${DLMC_CI_ENDPOINT}/artifact/download?artifact_type=$1&session_id=$2&clone_id=$3" --write-out "%{http_code}" \
artifact_code=$(curl -k --show-error --silent "${DLMC_CI_ENDPOINT}/artifact/download?artifact_type=$1&session_id=$2&clone_id=$3" --write-out "%{http_code}" \
--header "Verification-Token: ${DLMC_VERIFICATION_TOKEN}" \
--header 'Content-Type: application/json' \
--output artifacts/$1)
Expand Down