diff --git a/.github/workflows/ask_sponsor.yaml b/.github/workflows/ask_sponsor.yaml new file mode 100644 index 00000000..221357c2 --- /dev/null +++ b/.github/workflows/ask_sponsor.yaml @@ -0,0 +1,18 @@ +--- +name: Ask Sponsor +on: + pull_request_target: + types: + - opened +jobs: + ask_sponsor: + uses: ./.github/workflows/wc_ask_sponsor.yaml + permissions: {} + with: + author: ${{github.event.pull_request.user.login}} + pr_number: ${{github.event.pull_request.number}} + if: | + github.event.pull_request.user.type == 'User' + # if: | + # github.event.pull_request.user.type == 'User' && + # github.event.pull_request.user.login != 'suzuki-shunsuke' diff --git a/.github/workflows/wc_ask_sponsor.yaml b/.github/workflows/wc_ask_sponsor.yaml new file mode 100644 index 00000000..10ca1714 --- /dev/null +++ b/.github/workflows/wc_ask_sponsor.yaml @@ -0,0 +1,69 @@ +--- +on: + workflow_dispatch: + inputs: + author: + required: true + pr_number: + required: true + workflow_call: + inputs: + author: + type: string + required: true + pr_number: + type: string + required: true +jobs: + ask_sponsor: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + permissions: {} + steps: + - env: + GH_TOKEN: ${{github.token}} + AUTHOR: ${{inputs.author}} + PR_NUMBER: ${{inputs.pr_number}} + BODY: | + We spend a lot of time maintaining aqua and aqua-registry every day. + Today, aqua-registry is used not only by aqua, but also by tools like mise and docker agent. + If these projects help you, please consider supporting us via GitHub Sponsors. + https://github.com/sponsors/aquaproj + run: | + set -eu + + is_sponsor=$(gh api graphql \ + -F "sponsorable=aquaproj" \ + -F "author=$AUTHOR" \ + -q '.data.user.isSponsoredBy' \ + -f query=' + query($sponsorable: String!, $author: String!) { + user(login: $sponsorable) { + isSponsoredBy(accountLogin: $author) + } + }') + if [ "$is_sponsor" = "true" ]; then + echo "::notice:: @$AUTHOR is a sponsor of aquaproj" + exit 0 + fi + + is_sponsor=$(gh api graphql \ + -F "sponsorable=suzuki-shunsuke" \ + -F "author=$AUTHOR" \ + -q '.data.user.isSponsoredBy' \ + -f query=' + query($sponsorable: String!, $author: String!) { + user(login: $sponsorable) { + isSponsoredBy(accountLogin: $author) + } + }') + if [ "$is_sponsor" = "true" ]; then + echo "::notice:: @$AUTHOR is a sponsor of suzuki-shunsuke" + exit 0 + fi + + echo "::notice:: @$AUTHOR is NOT a (public) sponsor of aquaproj or suzuki-shunsuke" + gh pr comment \ + -R "$GITHUB_REPOSITORY" \ + --body "$BODY" \ + "$PR_NUMBER"