diff --git a/.github/workflows/verify-api.yml b/.github/workflows/verify-api.yml new file mode 100644 index 0000000..43c1e20 --- /dev/null +++ b/.github/workflows/verify-api.yml @@ -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' diff --git a/verify-api/action.yml b/verify-api/action.yml index 300c048..bcf436e 100644 --- a/verify-api/action.yml +++ b/verify-api/action.yml @@ -117,7 +117,7 @@ runs: SUGGESTED: ${{ steps.verify.outputs.suggested-change }} run: | marker='' - 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 @@ -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