Skip to content

Test Negative

Test Negative #106

Workflow file for this run

name: Test Negative
on:
workflow_dispatch: {}
permissions:
contents: write
pull-requests: write
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup
run: echo "Do setup"
create-release:
runs-on: ubuntu-latest
continue-on-error: true
needs: [setup]
steps:
- name: Checkout
uses: actions/checkout@v3
- id: create-release
run: |
release_name="${PREFIX}$(git rev-parse --short HEAD)"
gh release create ${release_name} --prerelease --target ${{ github.sha }} --notes "Created by ${{ github.workflow }} (will be automatically deleted)."
echo "name=${release_name}" > $GITHUB_OUTPUT
echo "tag=$(gh release view ${release_name} --json tagName -q '.tagName')" >> $GITHUB_OUTPUT
env:
# Below is the main difference between this workflow's positive counterpart.
# The action will not pick up a comment because the provided 'include_regex' will not be able to match it.
PREFIX: "v0.0.0-test.exclude."
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
name: ${{ steps.create-release.outputs.name }}
tag: ${{ steps.create-release.outputs.tag }}
assert:
runs-on: ubuntu-latest
needs: [create-release]
outputs:
comment-id: ${{ steps.fc.outputs.comment-id }}
steps:
- uses: actions/checkout@v4
- uses: ./
id: action
with:
tag: ${{ needs.create-release.outputs.tag }}
include_regex: 'v0\.0\.0-test\.include\..*' # Should NOT find a comment
- name: debug
run: |
echo "${{ fromJSON(steps.action.outputs.result) }}"
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ fromJSON(steps.action.outputs.result).comments[0].pull_request }}
body-includes: ${{ needs.create-release.outputs.tag }}
- name: Succeed if comment was not found
if: ${{ always() && steps.fc.outputs.comment-id == 0 }}
run: |
exit 0
- name: Fail if comment was found
if: ${{ always() && steps.fc.outputs.comment-id != 0 }}
run: |
exit 1
teardown:
runs-on: ubuntu-latest
needs: [create-release, assert]
if: ${{ always() }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Delete Test Release + Tag
if: needs.create-release.result == 'success'
run: gh release delete ${{ needs.create-release.outputs.name }} --cleanup-tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: octokit/[email protected]
name: Delete Test Release Comment
if: ${{ always() && needs.assert.outputs.comment-id != 0 }}
with:
route: DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}
owner: "${{ github.event.repository.owner.login }}"
repo: "${{ github.event.repository.name }}"
comment_id: ${{ needs.assert.outputs.comment-id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}