CSS deployment for reddit
- Create an images folder for where images are to be located, and know the relative path in relation to the root of the repository. This must exist even if you have no images. If you do have images, the names of the images in the folder will be equivalent to the names of the images when uploaded to reddit, so, for example, if you have, "buttons.png" in your images folder, that image will be named "buttons" when deployed to reddit.
- Locate where your stylesheet (compiled or manually edited) will be located, and know the relative path in relation to the root of the repository.
- You must use the files
validatecss.py
anddeploy.py
in this repository. These may be renamed if you wish, but be sure to rename them in your.travis.yml
file if necesssary. deploy.py
is dependant on praw > 3.5.0 yet less than 4.0.0b4, so the proper url is provided in this project's.travis.yml
. This will need to be edited as necessary if using arequirements.txt
file, or, if your project relies on praw4.0.0b4 or greater, the deployment script with need to be edited to uninstall praw, install it from the necessary tarball, and then continue with the main deployment process- Lines 2-4, 7-14 are necessary as they retrieve dependencies from reddit and elsewhere in order to validate CSS.
- In whatever script you use for the
.travis.yml
script block, it must call uponvalidatecss.py
in order to validate your CSS to be in line with reddit. For optional directives to achieve url format or size requirements, see Optional Directives. - The deployment provider must be script, and the script itself must call upon
deploy.py
- In your travis environment's shell settings, enable "Build only if .travis.yml is present", and "Limit concurrent jobs", and set the limit to 1. This is done so that under the chance that a earlier build would take longer than a later one, that it does not cause a race condition in deployment. If "Build pushes" is enabled, it is recommended to set deployment to be conditional on
.travis.yml
to a branch of your choosing so that only one branch will be deployed. An example is given in this repo's.travis.yml
. It is also recommended to enable "Build pull requests", so that pull requests to your repository can be validated before merging. Pull requests would never trigger deployment. - In your travis environment's environment variables, you must set the username, password, client_id, and client_secret (with those names) of the account / OAuth2 client pair you will be using to connect to reddit. subreddit (with that name) must also be set so the deployment script will deploy to the given subreddit. By default, the stylesheet is registered to be in the root directory as "stylesheet.css", but this can be changed if you set the "cssfile" environment variable to the path you found in step 2. The same goes with the "imgdir" variable, the images directory, and step 1. Whatever you do, do not be stupid. Ensure that the username, password, client_id, and client_secret variables are set to not display in the build log. Same goes with the subreddit variable if the subreddit is private. In the first situation, anyone would be able to access that reddit account. In the second, they'd find a private subreddit.
- If you ever find yourself needing to force a deployment to a subreddit, add the environment variable "force_deploy" with a value of "True", and restart the latest build. This will wipe images on the subreddit set, and make them equivalent to what is in the images directory. This will also forcibly deploy the stylesheet even if no changes had been made to it. The deployment still depends on the validation script passing. Remember to trash this variable once complete.
- Have a cookie!
- If the environment variable "replace_image_uris" is set to "True", static relative / absolute normalized file-paths will be replaced with reddit's "%%name%%" format before validation and saved to the disk for deployment. to reddit's %%name%% format in case wanted by the user.
- If the environment variable "minify" is set to "True" or "1", the validator will minify the css with little readability (spaces in tokens), while a numerical value of "2" or greater will minify the css to the highest standard allowed by reddit (which reddit uses to push to their cdn and serve from); no readability, but a large amount of
space saved. Minifying is done after validation, and is done after validation and saved to the disk for deployment.
Note: Travis runs
git stash --all
be default immediately before deployment, which would undo either / both of these optional directives.skip_cleanup: true
must be set in.travis.yml
if either / both of these optional directives are set. If you require cleanup for extra deployment in your project, you can do this by runninggit stash --all
after deployment to reddit is complete. The simplest method of doing so is shown in this project's.travis.yml
.