Automate submitting a Reddit post about your release using the Reddit API.
You don't need to be a moderator of a subreddit to use this. In fact, this action is only tested using a regular account.
Before using this action, you will need to have access to the Reddit API.
-
Make sure you're logged in to your Reddit account, and go to https://www.reddit.com/prefs/apps.
-
Create an app for this action.
- Once created, find the app ID and secret.
Warning DO NOT share the app secret in public. The image below is an invalid secret to show as an example.
- You can follow the steps below to configure the action. If you're interested, you can follow Reddit's cURL quick start to test this app. (If you get rate limit issues, make sure to set a different user agent)
Note Make sure you have configured your API/app before continuing below. If haven't, see the instructions above.
- Set the secrets for usage in GitHub Actions. Go to your repo > Settings > Secrets > Add a new secret.
Add secrets for:
- REDDIT_USERNAME: Your Reddit username
- REDDIT_PASSWORD: Your Reddit password
- REDDIT_APP_ID: The app ID
- REDDIT_APP_SECRET: The app secret
- Configure the workflow. Here, we use the secrets we set earlier and add parameters for the action. See the full list of parameters.
name: Release
on:
release:
types: [published]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: bluwy/release-for-reddit-action@v1
with:
username: ${{ secrets.REDDIT_USERNAME }}
password: ${{ secrets.REDDIT_PASSWORD }}
app-id: ${{ secrets.REDDIT_APP_ID }}
app-secret: ${{ secrets.REDDIT_APP_SECRET }}
subreddit: test # Submit to /r/test
- Create a release!
While this action is meant for releases, you can also configure it to be triggered on each push or pull request. If so, make sure to set the
title
andurl
parameters since they, by default, use values from a release.
Required Your Reddit username.
Required Your Reddit password.
Required The app ID.
Required The app secret.
Required The subreddit to post.
Optional The post title.
Default: ${{ github.repository }} ${{ github.event.release.tag_name }} Released
The default would output e.g. "bluwy/awesome-lib v1.0.0 Released"
More info on the different contexts that can be used: Context and expression syntax for GitHub Actions
All available properties of
github.event.release
: Example response object
Optional The post URL.
Default: ${{ github.event.release.html_url }}
The default would output e.g. "https://github.com/bluwy/awesome-lib/releases/tag/v1.0.0". If the URL links to a Reddit post, it'll do a crosspost instead.
Optional The post flair's ID. More info
Optional The post flair's text (applicable if text_editable is true). More info.
Optional A comment to add for your post. You can use this as a changelog excerpt for the lazy. Will not comment if this is not set or empty.
For example, if your changelog happens to be your release description, you can set this to ${{ github.event.release.body }}
.
Optional Whether to have replies on post and comments to be sent to inbox. Set true
to enable.
Default: false
Optional How many times to retry if it hits the rate limit. This will wait for the limit to end before retrying. To disable retries, set this to 0
. More info.
Default: 1
Output can be accessed in ${{ steps.<id>.outputs.<key> }}
, where <id>
is the id of a step, <key>
is the values below.
The link to the post if successfully submitted.
Tip: You can pass this url back to another reddit action's
url
parameter to do a crosspost! Example.
The link to the comment if a comment text is defined and succesfully submitted.
That's how the Reddit OAuth API works. To get the access token, you have to supply your username, password, app ID and app secret.
Check out Reddit's quick start example which also requires the four information for authentication. (If you get rate limit issues, make sure to set a different user agent)
Setting a flair requires its flair ID. To find the supported flairs for a subreddit, go to https://www.reddit.com/r/subreddit/api/link_flair.json. Replace "subreddit" with your target subreddit and make sure you're logged in for this to work.
The endpoint will return a list of flairs in JSON format, which you can choose one using the flair id.
If the flair's text_editable
property is true, you can set the flair-text
parameter to set a custom text for the flair.
There are two kinds of rate limit in Reddit. One is the request limit to the oauth.reddit.com
endpoint, which is a generous 600 request per 10 minutes. This action will never hit this limit unless you're also using the API for other clients.
The other rate limit is for post and comments submissions. If you start with a new account, it's very likely to get up to 10 minutes of rate limiting. You will likely hit this issue more often than the oauth
rate limit.
Though Reddit doesn't explicitly tell how the submission rate limit is calculated, various sources from the admins mentioned that having an older account and higher karma (especially in the specific subreddit) helps reduce this limit.
In the development of this action, the rate limit was significantly reduced after the 24 hour mark of account creation.
If you encounter this error, make sure your credentials are entered correctly, which are your username, password, app ID and app secret.
If this does not work, follow Reddit's cURL quick start and try to retrive an access token. (If you get rate limit issues, make sure to set a different user agent). If it works, please file an issue!
If the above didn't work, create a new account and use that instead. (This also happened to me).
Keep in mind that new accounts are heavily rate limited.
MIT