Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor build script #76

Merged
merged 12 commits into from
Oct 22, 2016
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ before_script:
- git remote add origin https://${GH_TOKEN}@github.com/CatBlock/catblock.git
- pip install selenium
script:
- python tools/make_release.py -b firefox -ext y
- python tools/make_release.py -b edge
- python tools/make_release.py -b chrome
- python tools/make_release.py -b opera
- python tools/make_release.py -b firefox -ext browser
- python tools/make_release.py -b edge -ext zip
- python tools/make_release.py -b chrome -ext zip
- python tools/make_release.py -b opera -ext zip
after_success:
- cd tools/
- chmod +x ./publish_release.sh
Expand Down
80 changes: 31 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,54 @@ CatBlock
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cc8d000f77bb427caa8b0293d9b5d225)](https://www.codacy.com/app/tomastaro/catblock?utm_source=github.com&utm_medium=referral&utm_content=CatBlock/catblock&utm_campaign=Badge_Grade)
[![GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/CatBlock/catblock/blob/master/LICENSE.txt)

## Overview
CatBlock (previously known as "AdBlock with CatBlock") is like an ad blocking extension, but instead of blocking ads it shows you pictures of cats by default (configurable).

You can also disable replacing ads by cats, so CatBlock can work as a standard ad blocking extension (useful for when you're doing presentations anywhere!)

This project aims at maintaining and improving the original [CatBlock](http://blog.getadblock.com/2012/04/catblock-lives-on.html) project by Michael Gundlach, the creator of [AdBlock](https://getadblock.com) and CatBlock.
If you want to find out the history of this extension, you can check it out [here](https://github.com/CatBlock/catblock/wiki/History).

If you want to keep an eye on (or even contribute to) the behind-the-scenes stuff, check out our [Trello Board](https://trello.com/catblock).
## Goals
This project aims at maintaining and improving the original [CatBlock](http://catblock.getadblock.com) project by Michael Gundlach (the creator of [AdBlock](https://getadblock.com) and CatBlock), which is built on top of the AdBlock code.

## Installation:
Available in [Chrome Web Store](https://chrome.google.com/webstore/detail/catblock/mdcgnhlfpnbeieiiccmebgkfdebafodo),
[Opera Extensions Store](https://addons.opera.com/sk/extensions/details/adblock-with-catblock/?display=en) and [Firefox Addons Store](https://addons.mozilla.org/en/firefox/addon/adblock-with-catblock/).
Right now, CatBlock is not available in the [Safari Extensions Store](https://safari-extensions.apple.com), or in the Windows Store (for Edge insiders). Instead, you must sideload the extension: [Edge instructions](https://github.com/CatBlock/catblock/wiki/Building-the-extension#in-microsoft-edge).
AdBlock has recently switched to the Adblock Plus codebase in version 3.0, but instead of importing those changes to CatBlock, we think it would be better to improve the original codebase.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already in catblock.wiki/History?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpeckett Yep, it is but I think it would be great to highlight, that we do want to improve the original code as much as we can and update it instead of switching to the ABP's code.


## Tools used for testing:
We use many different services to help keep CatBlock working! We use [Travis](http://travis-ci.org) to build new versions automatically for us. We're looking into a way of making a "nightly" version of CatBlock, with bleeding-edge (probably broken) code for testing.
## Installation
CatBlock is available in [Chrome Web Store](https://chrome.google.com/webstore/detail/catblock/mdcgnhlfpnbeieiiccmebgkfdebafodo),
[Opera Extensions Store](https://addons.opera.com/sk/extensions/details/adblock-with-catblock/?display=en) and [Firefox Addons Store](https://addons.mozilla.org/en/firefox/addon/adblock-with-catblock/).

We also have Travis connected to [BrowserStack](http://browserstack.com), to run a few automated tests for us. If "builds:passing" shows at the top of this README, then it's probably working fine, otherwise the current version of the code might not work so well.
Right now, CatBlock is not available in the [Safari Extensions Store](https://safari-extensions.apple.com), or in the [Windows Store](https://www.microsoft.com/en-us/windows/windows-10-apps), but we are looking into releasing CatBlock there as well!

## Compatibility:
Chrome: 49+
Opera: 35+
Safari: 6+
Firefox: 48+
Edge: 38.14342+
If you can't wait for an official release of CatBlock on Windows Store, [find out](https://github.com/CatBlock/catblock/wiki/Building-the-extension#in-microsoft-edge) how to sideload CatBlock on Edge right now.

## Live chat:
[![Slack](http://catblock-slackin.herokuapp.com/badge.svg)](http://catblock-slackin.herokuapp.com)
## Supported browsers
CatBlock is compatible with following browsers:
- Chrome: 49+
- Opera: 35+
- Safari: 6+
- Firefox: 48+
- Edge: Windows 10 Anniversary - version 1607

We use Slack a lot - make an account at <http://catblock-slackin.herokuapp.com> and log in at <https://catblock.slack.com>. You can ask questions there (the main contributors are all in Europe, so anyone in Australia should expect a bit of a wait).
## Tools we use
We use many different services to help keep CatBlock working! We use [Travis](http://travis-ci.org) to build new versions automatically for us.

If you want to contribute any improvements, please go ahead and send us a pull request from a fork of this repo!
We also have Travis connected to [BrowserStack](http://browserstack.com), to run a few automated unit tests for us. If "builds:passing" shows at the top of this README, then it's probably working fine, otherwise the current version of the code might not work so well.

## Developers

0. Fork this repository.
1. Switch to your working directory.
2. Clone the development repository.

### In Chrome
### How to build the extension or create a development environment?
The [development guide](https://github.com/CatBlock/catblock/wiki/Building-the-extension) will make your life easier if you need to build CatBlock or create an unpacked development environment and change the source code.

3. Go to the Chrome menu > **Tools** > **Extensions**.
4. Check **Developer mode** then press **Load unpacked extension...** .
5. Find your working directory & select it.
6. To test after you make a change, be sure to click on **Reload** button on **chrome://extensions** page.
7. Push your changes.
8. Send us pull request!
### Do you want to contribute?
If you want to contribute any improvements to the code, please go ahead and send us a pull request from a fork of this repo!

### In Safari

3. First, you need to obtain a Safari Developer Certificate from [Apple](https://developer.apple.com/programs/safari/)
4. Go to **Develop** > **Show Extension Builder**.
5. Click **+** then select **Add Extension...** .
6. Find your working directory & select it.
7. Click **Install**.
8. To test after you make a change, be sure to click on **Reload** button in Extension Builder.
9. Push your changes.
10. Send us pull request!
If we see that you are a dedicated contributor, we may provide you with contributor permissions.
The people to contact for this project are [@kpeckett](https://github.com/kpeckett) and [@tomasko126](https://github.com/tomasko126).

### In Opera
### Do you want to know more about our project?
If you want to keep an eye on CatBlock or even know more about it, check out our [Wiki page](https://github.com/CatBlock/catblock/wiki), where you can find all important information.

3. Go to **about://extensions**.
4. Press **Developer Mode** then press **Load Unpacked Extension...** .
5. Find your working directory & select it.
6. To test after you make a change, be sure to click on **Reload** button on **about://extensions** page.
7. Push your changes.
8. Send us pull request!
## Get in touch with us
[![Slack](http://catblock-slackin.herokuapp.com/badge.svg)](http://catblock-slackin.herokuapp.com)

If we see that you are a dedicated contributor, we may provide you with contributor permissions.
The people to contact for this project are @kpeckett and @tomasko126
We use Slack a lot - make an account at <http://catblock-slackin.herokuapp.com> and log in at <https://catblock.slack.com>. You can ask questions there (the main contributors are all in Europe, so anyone in Australia should expect a bit of a wait).
132 changes: 77 additions & 55 deletions tools/make_release.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/python

"""
Prepare a release versions of CatBlock for Chrome, Opera, Firefox and Edge
This script is compatible with Python v3.x
This script generates a release versions of CatBlock for different platforms
and also an unpacked development environment

Compatible with Python v3.x

Author: Tomas Taro
License: GNU GPLv3
Expand All @@ -16,15 +16,21 @@ def main():
import argparse # Provides functions for parsing arguments

# Parse passed arguments
parser = argparse.ArgumentParser(description="This script generates Firefox and Edge versions of CatBlock")
parser.add_argument("-b", "--browser", help="Name of the browser, which should we generate an extension for", required=True)
parser = argparse.ArgumentParser(description="This script generates CatBlock for a specified browser")
parser.add_argument("-b", "--browser", help="What browser do you want to build an extension for?", required=True)
parser.add_argument("-ext", "--extension", help="Generate an extension package for a particular browser?", required=False)
parser.add_argument("-devenv", help="Generate an unpacked development environment?", required=False)
args = parser.parse_args()

# When nothing has been defined except the target, print an exception and return
if args.extension == None and args.devenv == None:
print("You must specify, whether to create an unpacked development environment or to generate an extension package")
sys.exit(1)

# Remove .DS_Store files
os.system("find . -name '*.DS_Store' -type f -delete")

# If /builds doesn't exist, create it
# If /builds directory doesn't exist, create it
if not os.path.exists("builds"):
os.makedirs("builds")

Expand Down Expand Up @@ -62,6 +68,7 @@ def prepareManifestFile():
}
}

# Apply platform-specific changes
with open(browserData[args.browser]["path"], "r+") as browser_manifest:
keys = json.load(browser_manifest) # Creates a dict of all messages in the AdBlock file

Expand Down Expand Up @@ -89,37 +96,39 @@ def prepareManifestFile():
# Prepare a Firefox release
if args.browser == "firefox":

print("Preparing CatBlock for Firefox release...")
print("Generating CatBlock for Firefox...")

# If /catblock_firefox folder exists, delete it
if os.path.exists("catblock_firefox"):
shutil.rmtree("catblock_firefox")

# Copy the content of the original folder into /catblock_firefox and ignore hidden files, builds and tools folders
# Copy the content of the original folder into /catblock_firefox and
# ignore hidden files, builds and tools folders
shutil.copytree(os.getcwd(), "catblock_firefox", ignore=shutil.ignore_patterns(".*", "builds", "tools"))

# Prepare manifest.json file
prepareManifestFile()

# Create a .zip file
shutil.make_archive("catblock-firefox", "zip", "catblock_firefox")

# Rename to the Firefox compatible .xpi file
if args.extension == "y":
os.rename("catblock-firefox.zip", "catblock-firefox.xpi")
# Generate a packed extension
if args.extension != None:
shutil.make_archive("catblock-firefox", "zip", "catblock_firefox")

if os.path.isfile("catblock-firefox.zip"):
shutil.move("catblock-firefox.zip", "builds/catblock-firefox.zip")
else:
shutil.move("catblock-firefox.xpi", "builds/catblock-firefox.xpi")
# Rename to the Firefox compatible .xpi file
if args.extension == "browser":
os.rename("catblock-firefox.zip", "catblock-firefox.xpi")
shutil.move("catblock-firefox.xpi", "builds/catblock-firefox.xpi")
else:
shutil.move("catblock-firefox.zip", "builds/catblock-firefox.zip")

shutil.rmtree("catblock_firefox")
# When an unpacked development environment should not be created, remove the folder
if args.devenv == None:
shutil.rmtree("catblock_firefox")

print("CatBlock for Firefox has been built!")
print("Done!")

elif args.browser == "edge":

print("Preparing CatBlock for Edge release...")
print("Generating CatBlock for Edge...")

# If /catblock_edge folder does exist, remove it
if os.path.exists("catblock_edge"):
Expand All @@ -135,17 +144,22 @@ def prepareManifestFile():
# Prepare manifest.json file
prepareManifestFile()

shutil.make_archive("catblock-edge", "zip", "catblock_edge")

shutil.move("catblock-edge.zip", "builds/catblock-edge.zip")
# Edge doesn't support a special suffix of an extension,
# hence we ignore -ext argument
# Generate a packed extension
if args.extension != None:
shutil.make_archive("catblock-edge", "zip", "catblock_edge")
shutil.move("catblock-edge.zip", "builds/catblock-edge.zip")

shutil.rmtree("catblock_edge")
# When an unpacked development environment should not be created, remove the folder
if args.devenv == None:
shutil.rmtree("catblock_edge")

print("CatBlock for Edge has been built!")
print("Done!")

elif args.browser == "chrome":

print("Preparing CatBlock for Chrome release...")
print("Generating CatBlock for Chrome...")

# If /catblock_chrome folder does exist, remove it
if os.path.exists("catblock_chrome"):
Expand All @@ -157,15 +171,15 @@ def prepareManifestFile():
# Prepare manifest.json file
prepareManifestFile()

shutil.make_archive("catblock-chrome", "zip", "catblock_chrome")

# Selenium testing
# Selenium testing - enabled only on Travis-CI
if os.environ.get("TRAVIS") != None:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

shutil.make_archive("catblock-chrome", "zip", "catblock_chrome")

chop = webdriver.ChromeOptions()
chop.add_extension("catblock-chrome.zip")
chop = chop.to_capabilities()
Expand Down Expand Up @@ -194,25 +208,30 @@ def prepareManifestFile():
sys.exit(1)
# End of Selenium testing

# Generate a packed extension
if args.extension != None:
# In Travis, catblock-chrome.zip has already been created
if os.environ.get("TRAVIS") == None:
shutil.make_archive("catblock-chrome", "zip", "catblock_chrome")

# Rename to the Chrome's compatible .crx file
if args.extension == "browser":
os.rename("catblock-chrome.zip", "catblock-chrome.crx")
shutil.move("catblock-chrome.crx", "builds/catblock-chrome.crx")
else:
shutil.move("catblock-chrome.zip", "builds/catblock-chrome.zip")

# When an unpacked development environment should not be created, remove the folder
if args.devenv == None:
shutil.rmtree("catblock_chrome")

# Rename to the Chrome compatible .crx file
if args.extension == "y":
os.rename("catblock-chrome.zip", "catblock-chrome.crx")

if os.path.isfile("catblock-chrome.zip"):
shutil.move("catblock-chrome.zip", "builds/catblock-chrome.zip")
else:
shutil.move("catblock-chrome.crx", "builds/catblock-chrome.crx")

shutil.rmtree("catblock_chrome")

print("CatBlock for Chrome has been built!")
print("Done!")

elif args.browser == "opera":

print("Preparing CatBlock for Opera release...")
print("Generating CatBlock for Opera...")

# If /catblock_chrome folder does exist, remove it
# If /catblock_opera folder does exist, remove it
if os.path.exists("catblock_opera"):
shutil.rmtree("catblock_opera")

Expand All @@ -222,20 +241,23 @@ def prepareManifestFile():
# Prepare manifest.json file
prepareManifestFile()

shutil.make_archive("catblock-opera", "zip", "catblock_opera")
# Generate a packed extension
if args.extension != None:
shutil.make_archive("catblock-opera", "zip", "catblock_opera")

# Rename to the Opera compatible .nex file
if args.extension == "y":
os.rename("catblock-opera.zip", "catblock-opera.nex")
# Rename to the Opera's compatible .nex file
if args.extension == "browser":
os.rename("catblock-opera.zip", "catblock-opera.nex")
shutil.move("catblock-opera.nex", "builds/catblock-opera.nex")
else:
shutil.move("catblock-opera.zip", "builds/catblock-opera.zip")

if os.path.isfile("catblock-opera.zip"):
shutil.move("catblock-opera.zip", "builds/catblock-opera.zip")
else:
shutil.move("catblock-opera.nex", "builds/catblock-opera.nex")
# When an unpacked development environment should not be created, remove the folder
if args.devenv == None:
shutil.rmtree("catblock_opera")

shutil.rmtree("catblock_opera")
print("Done!")

print("CatBlock for Opera has been built!")
else:
print("You have selected an unsupported browser. Please, try again.")

Expand Down