diff --git a/action.yml b/action.yml index 5e7162b..0b744ef 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 }} diff --git a/Dockerfile b/core/Dockerfile similarity index 100% rename from Dockerfile rename to core/Dockerfile diff --git a/core/action.yml b/core/action.yml new file mode 100644 index 0000000..08dbdfa --- /dev/null +++ b/core/action.yml @@ -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' diff --git a/entrypoint.sh b/core/entrypoint.sh similarity index 96% rename from entrypoint.sh rename to core/entrypoint.sh index e3efcf4..8b3ec9f 100755 --- a/entrypoint.sh +++ b/core/entrypoint.sh @@ -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) @@ -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