Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/verify-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: verify-api

# The verify-api action, run from this checkout with the released tool, on this repository's own api/: it proves the
# action end to end on every pull request, and keeps a comment when api/ is out of date.
on:
pull_request:

permissions:
contents: read

jobs:
verify-api:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # the comment
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b # v5.2.7
with:
cache: false
env:
MISE_JOBS: "1"
- run: dotnet build src/Nullean.PublicApi.Diff -c Release
- uses: ./verify-api
with:
directory: api
projects: |
src/Nullean.PublicApi/Nullean.PublicApi.csproj
src/Nullean.PublicApi.Diff/Nullean.PublicApi.Diff.csproj
comment: 'true'
9 changes: 6 additions & 3 deletions verify-api/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ runs:
SUGGESTED: ${{ steps.verify.outputs.suggested-change }}
run: |
marker='<!-- assembly-differ:verify-api -->'
existing=$(gh api "repos/$REPOSITORY/issues/$PULL_REQUEST/comments" --paginate --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1)
existing=$(gh api "repos/$REPOSITORY/issues/$PULL_REQUEST/comments" --paginate --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1 || true)
body="$RUNNER_TEMP/assembly-differ-verify.md"
if [ "$CODE" = "0" ]; then
# only an earlier comment is updated: a pull request whose files always matched gets none
Expand All @@ -133,10 +133,13 @@ runs:
else
exit 0
fi
# a pull request from a fork gets a token that cannot write: say so, and leave failing to the check below
if [ -n "$existing" ]; then
gh api -X PATCH "repos/$REPOSITORY/issues/comments/$existing" -F "body=@$body" > /dev/null
gh api -X PATCH "repos/$REPOSITORY/issues/comments/$existing" -F "body=@$body" > /dev/null ||
echo "::warning title=assembly-differ::could not update the comment; the token needs pull-requests: write"
else
gh api -X POST "repos/$REPOSITORY/issues/$PULL_REQUEST/comments" -F "body=@$body" > /dev/null
gh api -X POST "repos/$REPOSITORY/issues/$PULL_REQUEST/comments" -F "body=@$body" > /dev/null ||
echo "::warning title=assembly-differ::could not comment; the token needs pull-requests: write"
fi

- name: Fail when the files do not match
Expand Down
Loading