diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 4119193a..d8ea5f77 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -33,22 +33,7 @@ jobs: env: GH_TOKEN: ${{ secrets.SPONSORS_TOKEN }} GH_LOGIN: your-org - run: | - QUERY='query($login:String!){ - organization(login:$login){ - monthlyEstimatedSponsorsIncomeInCents - sponsorshipsAsMaintainer(first:1){ totalCount } - } - }' - RESP=$(curl -s https://api.github.com/graphql \ - -H "Authorization: Bearer $GH_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"query\":\"$QUERY\",\"variables\":{\"login\":\"$GH_LOGIN\"}}") - CENTS=$(echo "$RESP" | jq '.data.organization.monthlyEstimatedSponsorsIncomeInCents // 0') - COUNT=$(echo "$RESP" | jq '.data.organization.sponsorshipsAsMaintainer.totalCount // 0') - jq -n --argjson sum "$CENTS" --argjson count "$COUNT" \ - '{ sponsor_sum: ($sum/100|floor), sponsor_count: $count }' \ - > website/_data/gh_sponsors.json + uses: ./FetchGHSponsors - name: Setup .NET Core SDK uses: actions/setup-dotnet@v4 diff --git a/.github/workflows/pullrequest.yaml b/.github/workflows/pullrequest.yaml index 0c1dd1e1..6b0005b8 100644 --- a/.github/workflows/pullrequest.yaml +++ b/.github/workflows/pullrequest.yaml @@ -30,22 +30,7 @@ jobs: env: GH_TOKEN: ${{ secrets.SPONSORS_TOKEN }} GH_LOGIN: your-org - run: | - QUERY='query($login:String!){ - organization(login:$login){ - monthlyEstimatedSponsorsIncomeInCents - sponsorshipsAsMaintainer(first:1){ totalCount } - } - }' - RESP=$(curl -s https://api.github.com/graphql \ - -H "Authorization: Bearer $GH_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"query\":\"$QUERY\",\"variables\":{\"login\":\"$GH_LOGIN\"}}") - CENTS=$(echo "$RESP" | jq '.data.organization.monthlyEstimatedSponsorsIncomeInCents // 0') - COUNT=$(echo "$RESP" | jq '.data.organization.sponsorshipsAsMaintainer.totalCount // 0') - jq -n --argjson sum "$CENTS" --argjson count "$COUNT" \ - '{ sponsor_sum: ($sum/100|floor), sponsor_count: $count }' \ - > website/_data/gh_sponsors.json + uses: ./FetchGHSponsors - name: Setup .NET Core SDK uses: actions/setup-dotnet@v4 diff --git a/FetchGHSponsors/action.yml b/FetchGHSponsors/action.yml new file mode 100644 index 00000000..04ae7fec --- /dev/null +++ b/FetchGHSponsors/action.yml @@ -0,0 +1,25 @@ +name: Fetch GH Sponsors +description: 'Updates the GitHub spondors list for the Monogame website' +author: 'MonoGame Foundation' +runs: + using: "composite" + steps: + - name: Fetch + if: runner.os == 'Linux' + run: | + QUERY='query($login:String!){ + organization(login:$login){ + monthlyEstimatedSponsorsIncomeInCents + sponsorshipsAsMaintainer(first:1){ totalCount } + } + }' + RESP=$(curl -s https://api.github.com/graphql \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"query\":\"$QUERY\",\"variables\":{\"login\":\"$GH_LOGIN\"}}") + CENTS=$(echo "$RESP" | jq '.data.organization.monthlyEstimatedSponsorsIncomeInCents // 0') + COUNT=$(echo "$RESP" | jq '.data.organization.sponsorshipsAsMaintainer.totalCount // 0') + jq -n --argjson sum "$CENTS" --argjson count "$COUNT" \ + '{ sponsor_sum: ($sum/100|floor), sponsor_count: $count }' \ + > website/_data/gh_sponsors.json + shell: bash \ No newline at end of file