Skip to content

Commit

Permalink
fix: finish internal test implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dgschwindturo committed Nov 22, 2022
1 parent 302894b commit 2dbbc1b
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 55 deletions.
109 changes: 84 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,96 @@ jobs:
steps:
- uses: open-turo/actions-gha/test@v1

unit-test:
name: Unit test
integration-test:
name: Integration test
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Introduce problem that needs resolution
run: echo "fixme" > ./badshell.sh
- name: Create temporary pull request
id: cpr
uses: peter-evans/create-pull-request@v4
- name: Search for comment within PR
id: before-add-fc
uses: peter-evans/find-comment@v2
with:
title: Temp PR for unit testing purposes
base: main
branch: pr-for-unit-testing
branch-suffix: timestamp
issue-number: ${{ github.event.pull_request.number }}
comment-author: open-turo-bot
body-includes:
${{ format('auto-gen for PR {0}',
github.event.pull_request.number)}}
token: ${{ secrets.OPEN_TURO_GITHUB_TOKEN }}
draft: true
- name: Verify new PR created
- name: Verify comment is not already present on the PR
if: steps.before-add-fc.outputs.comment-id != ''
run: |
echo "PR ${{ steps.cpr.outputs.pull-request-number }} created"
echo "PR operation '${{ steps.cpr.outputs.pull-request-operation}}'"
- name: Cleanup temporary pull request
if:
always() && ${{ steps.cpr.outputs.pull-request-operation}} ==
'created' && ${{ steps.cpr.outputs.pull-request-number }} != ''
uses: peter-evans/close-pull@v2
echo "::error title=Unexpected PR state::Comment already exists on PR"
exit 1
- name: Add comment when not already present on the PR
if: steps.before-add-fc.outputs.comment-id == ''
uses: ./
with:
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
comment:
Auto-closing temporary PR ${{ steps.cpr.outputs.pull-request-number
}}
delete-branch: true
comment: Lorem ipsum dolor sit amet.
text-detector:
${{ format('auto-gen for PR {0}',
github.event.pull_request.number)}}
workflow: ADD
github-token: ${{ secrets.OPEN_TURO_GITHUB_TOKEN }}
- name: Search for comment that should now be present on the PR
id: after-add-fc
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: open-turo-bot
body-includes: ipsum dolor
token: ${{ secrets.OPEN_TURO_GITHUB_TOKEN }}
- name: Verify comment is now present on the PR
if: steps.after-add-fc.outputs.comment-id == ''
run: |
echo "::error title=Unexpected PR state::Comment should exist on PR but is not found"
exit 1
- name: Update comment that is already present on the PR
if: success() && steps.after-add-fc.outputs.comment-id != ''
uses: ./
with:
comment: Lorem ipsum donor sit amet.
text-detector:
${{ format('auto-gen for PR {0}',
github.event.pull_request.number)}}
workflow: ADD
github-token: ${{ secrets.OPEN_TURO_GITHUB_TOKEN }}
- name: Search for updated comment that should be present on the PR
id: after-update-fc
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: open-turo-bot
body-includes: ipsum donor
token: ${{ secrets.OPEN_TURO_GITHUB_TOKEN }}
- name: Verify updated comment is present on the PR
if: steps.after-update-fc.outputs.comment-id == ''
run: |
echo "::error title=Unexpected PR state::Updated comment should exist on PR but is not found"
exit 1
- name: Now delete the comment if present
if: success() && steps.after-update-fc.outputs.comment-id != ''
uses: ./
with:
text-detector:
${{ format('auto-gen for PR {0}',
github.event.pull_request.number)}}
workflow: REMOVE
github-token: ${{ secrets.OPEN_TURO_GITHUB_TOKEN }}
- name: Search for comment that should now have been deleted
id: after-delete-fc
if: success()
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: open-turo-bot
body-includes: ipsum dolor
token: ${{ secrets.OPEN_TURO_GITHUB_TOKEN }}
- name: Verify comment is no longer present on the PR
if: steps.after-delete-fc.outputs.comment-id != ''
run: |
echo "::error title=Unexpected PR state::Comment should no longer exist on PR but is still present"
exit 1
- name: Test status
if: success() && steps.after-delete-fc.outputs.comment-id == ''
run: echo "Test success"
80 changes: 50 additions & 30 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,72 @@ description:
found to be resolved, allows the previously added comment, if one exists at
that time, to be removed from the PR.
inputs:
instruction-text:
workflow:
required: true
description:
This is the full text of the message to be placed within a comment of the
given PR to instruct the author of the PR how to resolve a given problem.
instruction-text-detector:
required: true
description:
This is some unique verbatim subset of the instruction-text that is to be
used to determine if a comment has already been created against the PR
that instructs the author how to resolve the given problem.
delete-comment-on-resolution:
ADD indicates the comment is to be added/updated to/within the PR, REMOVE
indicates the comment is to be removed from the PR.
text-detector:
required: true
description:
Whether or not to delete the comment that has been added to the PR upon
problem resolution.
default: "true"
This is some unique verbatim subset of the comment that is to be used to
determine if a comment has already been created against the PR that
instructs the author how to resolve the given problem.
default: created by action-conditional-pr-comment
github-token:
required: true
description:
GitHub token that can create/delete comments. e.g. 'secrets.GITHUB_TOKEN'
GitHub token that can add/update/delete comments. e.g.
'secrets.GITHUB_TOKEN'
comment:
required: false
description:
This is the full text of the message to be placed within a comment of the
given PR to instruct the author of the PR how to resolve a given problem.
This value should be provided for all ADD workflows.
default: fixme
comment-author:
required: false
description: The author of the comment upon addition.
default: open-turo-bot
runs:
using: composite
steps:
- name:
Check to see if problem resolution instructions comment already present
on the PR
uses: peter-evans/find-comment@v2
if: github.event_name == 'pull_request'
- name: Verify we are in the context of a PR
if: github.event_name != 'pull_request'
shell: bash
## This action can only be run in the context of a PR
run: |
echo "::warning title=Unsupported run state::This action can only be run within the context of a PR"
exit 1
- name: Check to see if comment already present on the PR
id: fc
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: ${{ inputs.instruction-text-detector }}
- name: Conditionally create instructions comment for PR author
if:
github.event_name == 'pull_request' && failure() &&
steps.fc.outputs.comment-id == ''
comment-author: ${{ inputs.comment-author }}
body-includes: ${{ inputs.text-detector }}
token: ${{ inputs.github-token }}
- name: Conditionally add comment to PR
if: inputs.workflow == 'ADD' && steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ inputs.instruction-text}}
- name: Delete instructions comment from PR if problem has been resolved
if:
inputs.delete-comment-on-resolution == 'true' && github.event_name ==
'pull_request' && success() && steps.fc.outputs.comment-id != ''
## Place the comment detection text within an HTML comment.
body:
${{ format('{0} <!-- {1} -->', inputs.comment, inputs.text-detector)}}
token: ${{ inputs.github-token }}
- name: Conditionally update existing comment within PR
if: inputs.workflow == 'ADD' && steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
## Place the comment detection text within an HTML comment.
body:
${{ format('{0} <!-- {1} -->', inputs.comment, inputs.text-detector)}}
token: ${{ inputs.github-token }}
- name: Conditionally delete comment from PR if found
if: inputs.workflow == 'REMOVE' && steps.fc.outputs.comment-id != ''
uses: jungwinter/comment@v1
with:
type: delete
Expand Down

0 comments on commit 2dbbc1b

Please sign in to comment.