greasyfork-org / greasyfork

An online repository of user scripts.
https://greasyfork.org
GNU General Public License v3.0
1.45k stars 435 forks source link

Deploy to GreasyFork from github pipeline #1288

Open alex1yaremchuk opened 2 months ago

alex1yaremchuk commented 2 months ago

Hi, I played with webhooks and made it work with github triggering it automatically by itself on push (on tag creation it failed with 406).

But I expected to be able to trigger the webhook by myself from my pipeline after tests succeeded and after I checked the conditions for publishing (like certain tag name).

Haven't found any information on triggering GF webhooks from CI/CD pipeline.

JasonBarnabe commented 2 months ago

This is not currently supported.

There are two pieces that would be needed for this to work:

  1. Ability to understand a notification from the GitHub pipeline. (If you could provide a sample request that would be useful)
  2. Pulling the script from the correct place. Currently on webhook notifications, Greasy Fork is pulling from git, but already this breaks certain workflows where the script is not in git but is instead output by some build process.
alex1yaremchuk commented 2 months ago

Thank you for the reply!

This is not currently supported.

There are two pieces that would be needed for this to work:

  1. Ability to understand a notification from the GitHub pipeline. (If you could provide a sample request that would be useful)

As for this - I thought we could trigger webhook with curl request. I'll post below examples (chatGPT's help).

  1. Pulling the script from the correct place. Currently on webhook notifications, Greasy Fork is pulling from git, but already this breaks certain workflows where the script is not in git but is instead output by some build process.

Actually I could post the script content as part of the request, so there will be no need to look for it on github or somewhere else.

         payload='{
            "ref": "refs/tags/v2024-07-13",
            "before": "a4e6c9625545b2af76743283d1efb9b10504a03e",
            "after": "0000000000000000000000000000000000000000",
            "repository": {
              "id": 826871908,
              "name": "chatscroll",
              "full_name": "alex1yaremchuk/chatscroll",
              "private": false,
              "owner": {
                "name": "alex1yaremchuk",
                "email": "40666786+alex1yaremchuk@users.noreply.github.com"
              },
              "html_url": "https://github.com/alex1yaremchuk/chatscroll",
              "default_branch": "main"
            },
            "pusher": {
              "name": "alex1yaremchuk",
              "email": "40666786+alex1yaremchuk@users.noreply.github.com"
            },
            "created": false,
            "deleted": true,
            "forced": false
          }'
          response=$(curl -v -X POST -H "Content-Type: application/json" \
          -H "Authorization: Bearer githubsecret_here" \
          -d "$payload" \
          https://greasyfork.org/en/users/1280205-alex1yaremchuk/webhook)
          echo "Response code: $response"
          if [ "$response" -ne 200 ]; then
            echo "Deployment failed with response code $response"
            exit 1
          fi

previous version with passing file contents:

          script_content=$(cat src/main.js)
          response=$(curl -v -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" \
          -H "Authorization: Bearer github_secret_here" \
          -d '{"event_type": "push", "script_content": "'"${script_content}"'"}' \
          https://greasyfork.org/en/users/1280205-alexander-yaremchuk/webhook)
          echo "Response code: $response"
          if [ "$response" -ne 200 ]; then
            echo "Deployment failed with response code $response"
            exit 1
          fi
JasonBarnabe commented 2 months ago

Do GitHub actions use the same secret token as webhooks do?

alex1yaremchuk commented 2 months ago

Do GitHub actions use the same secret token as webhooks do?

If I understand your question right - we don't need to trigger actions, github does it by pipeline settings.

Github secret stores whatever we put into it, I put there GF token from webhook. it's just a safe wrapper for a token to use in pipeline code. Github substitutes it with a stored value on execution.

Sorry if I got into too much too obvious detail, I just wanted to clarify for mysef as well.

Thank you!